Skip to content

Commit

Permalink
refactor: replace some getNavigationScene() & requireNavigationScene(…
Browse files Browse the repository at this point in the history
…) usage with NavigationSceneGetter
  • Loading branch information
qii committed Apr 22, 2021
1 parent a7e0df6 commit a463127
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.bytedance.scene.navigation.NavigationScene;
import com.bytedance.scene.utlity.Utility;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
createRootSceneIfNeeded();
}

NavigationScene parentSceneNavigation = getNavigationScene();
NavigationScene parentSceneNavigation = NavigationSceneGetter.getNavigationScene(this);
if (parentSceneNavigation != null) {
parentSceneNavigation.addOnBackPressedListener(this, new OnBackPressedListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scene.navigation.NavigationScene;
import com.bytedance.scene.navigation.OnBackPressedListener;
import com.bytedance.scene.utlity.Experimental;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
ViewGroup.LayoutParams.MATCH_PARENT);
}

requireNavigationScene().addOnBackPressedListener(this, new OnBackPressedListener() {
NavigationSceneGetter.requireNavigationScene(this).addOnBackPressedListener(this, new OnBackPressedListener() {
@Override
public boolean onBackPressed() {
if (mBehavior.getState() != BottomSheetBehavior.STATE_COLLAPSED) {
Expand Down Expand Up @@ -223,7 +224,7 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
};

private void cancel() {
NavigationScene navigationScene = getNavigationScene();
NavigationScene navigationScene = NavigationSceneGetter.getNavigationScene(this);
if (navigationScene != null) {
navigationScene.remove(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.view.*;
import androidx.annotation.*;
import androidx.lifecycle.Lifecycle;
import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scene.Scene;
import com.bytedance.scene.animation.animatorexecutor.NoAnimationExecutor;
import com.bytedance.scene.interfaces.PushOptions;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void show(@NonNull Scene hostScene) {
return;
}

NavigationScene navigationScene = hostScene.getNavigationScene();
NavigationScene navigationScene = NavigationSceneGetter.getNavigationScene(hostScene);
if (navigationScene == null) {
return;
}
Expand All @@ -160,7 +161,7 @@ private void dismissInternal(boolean allowStateLoss) {
mDialog.dismiss();
}
mViewDestroyed = true;
NavigationScene navigationScene = getNavigationScene();
NavigationScene navigationScene = NavigationSceneGetter.getNavigationScene(this);
if (navigationScene != null) {
navigationScene.remove(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.app.Activity;
import android.os.Build;
import com.bytedance.scene.navigation.NavigationSceneGetter;
import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import com.bytedance.scene.Scene;
Expand Down Expand Up @@ -48,7 +49,7 @@ public void show(@NonNull Scene hostScene) {
return;
}

NavigationScene navigationScene = hostScene.getNavigationScene();
NavigationScene navigationScene = NavigationSceneGetter.getNavigationScene(hostScene);
if (navigationScene == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import androidx.annotation.*;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Lifecycle;
import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scene.Scene;
import com.bytedance.scene.dialog.DialogScene;
import com.bytedance.scene.dialog.R;
Expand Down Expand Up @@ -192,7 +193,7 @@ private void initRootView() {
@Override
public void onClick(View v) {
if (mCanceledOnTouchOutside) {
requireNavigationScene().pop();
NavigationSceneGetter.requireNavigationScene(AlertDialogScene.this).pop();
}
}
});
Expand All @@ -213,7 +214,7 @@ public void setBackGroundDim(float dim) {
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
requireNavigationScene().addOnBackPressedListener(this, new OnBackPressedListener() {
NavigationSceneGetter.requireNavigationScene(this).addOnBackPressedListener(this, new OnBackPressedListener() {
@Override
public boolean onBackPressed() {
return !mCancelable;
Expand Down Expand Up @@ -351,7 +352,7 @@ void dismissDialog() {
if (getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) {
return;
}
NavigationScene navigationScene = getNavigationScene();
NavigationScene navigationScene = NavigationSceneGetter.getNavigationScene(this);
if (navigationScene != null) {
navigationScene.remove(this);
sendDismissMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.bytedance.scene.navigation.NavigationScene;
import com.bytedance.scene.navigation.NavigationSceneOptions;
import com.bytedance.scene.utlity.AnimatorUtility;
import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scene.utlity.CancellationSignal;
import com.bytedance.scene.utlity.NonNullPair;

Expand Down Expand Up @@ -136,7 +137,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Intent intent = requireActivity().getIntent();
NonNullPair<? extends Class<? extends Scene>, Bundle> pair = getSceneDataFromIntent(intent);
getNavigationScene().push(pair.first,
NavigationSceneGetter.requireNavigationScene(this).push(pair.first,
pair.second, new PushOptions.Builder().setAnimation(new KeepAnimationExecutor())
.setPushResultCallback(new PushResultCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;

import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scene.Scene;
import com.bytedance.scene.group.GroupScene;
import com.bytedance.scene.navigation.OnBackPressedListener;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void onClick(View v) {
mDrawerLayout.openDrawer(Gravity.LEFT);
}
});
requireNavigationScene().addOnBackPressedListener(this, new OnBackPressedListener() {
NavigationSceneGetter.requireNavigationScene(this).addOnBackPressedListener(this, new OnBackPressedListener() {
@Override
public boolean onBackPressed() {
if (mDrawerLayout.isDrawerOpen(mNavigationView)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;

import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scene.ui.view.NavigationBarView;
import com.bytedance.scene.ui.view.StatusBarView;
import com.bytedance.scene.ui.R;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
this.mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getNavigationScene().pop();
NavigationSceneGetter.requireNavigationScene(SwipeBackAppCompatScene.this).pop();
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scene.Scene;
import com.bytedance.scene.animation.animatorexecutor.NoAnimationExecutor;
import com.bytedance.scene.animation.interaction.InteractionNavigationPopAnimationFactory;
Expand Down Expand Up @@ -106,31 +107,31 @@ protected void onInteractionEnd() {
@Override
public boolean onBackPressed() {
interactionNavigationPopAnimationFactory.forceCancel();
requireNavigationScene().removeOnBackPressedListener(this);
NavigationSceneGetter.requireNavigationScene(SwipeBackGroupScene.this).removeOnBackPressedListener(this);
return true;
}
};

mSlidePercentFrameLayout.setCallback(new SlidePercentFrameLayout.Callback() {
@Override
public boolean isSupport() {
return requireNavigationScene().isInteractionNavigationPopSupport(interactionNavigationPopAnimationFactory);
return NavigationSceneGetter.requireNavigationScene(SwipeBackGroupScene.this).isInteractionNavigationPopSupport(interactionNavigationPopAnimationFactory);
}

@Override
public void onStart() {
if (requireNavigationScene().pop(interactionNavigationPopAnimationFactory)) {
if (NavigationSceneGetter.requireNavigationScene(SwipeBackGroupScene.this).pop(interactionNavigationPopAnimationFactory)) {
Resources r = getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, r.getDisplayMetrics());
ViewCompat.setElevation(swipeContainerView, px);
backgroundView.setVisibility(View.VISIBLE);
requireNavigationScene().addOnBackPressedListener(SwipeBackGroupScene.this, onBackPressedListener);
NavigationSceneGetter.requireNavigationScene(SwipeBackGroupScene.this).addOnBackPressedListener(SwipeBackGroupScene.this, onBackPressedListener);
}
}

@Override
public void onFinish() {
NavigationScene navigationScene = getNavigationScene();
NavigationScene navigationScene = NavigationSceneGetter.getNavigationScene(SwipeBackGroupScene.this);
if (navigationScene != null) {
navigationScene.removeOnBackPressedListener(onBackPressedListener);
interactionNavigationPopAnimationFactory.finish();
Expand Down Expand Up @@ -168,7 +169,7 @@ public void setSwipeEnabled(boolean enabled) {
}

protected void onSwipeBackEnd() {
getNavigationScene().pop(new PopOptions.Builder().setAnimation(new NoAnimationExecutor()).build());
NavigationSceneGetter.getNavigationScene(this).pop(new PopOptions.Builder().setAnimation(new NoAnimationExecutor()).build());
}

protected void onSwipeBackCancel() {
Expand Down

0 comments on commit a463127

Please sign in to comment.