Skip to content

Commit

Permalink
refactor: only visible Scene can intercept app back event
Browse files Browse the repository at this point in the history
  • Loading branch information
qii committed Feb 25, 2020
1 parent f7f4d71 commit 3dc15e1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
Expand Up @@ -553,9 +553,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
parentSceneNavigation.addOnBackPressedListener(this, new OnBackPressedListener() {
@Override
public boolean onBackPressed() {
if (getState().value < State.STARTED.value) {
return false;
}
return NavigationScene.this.onBackPressed();
}
});
Expand Down
Expand Up @@ -17,6 +17,7 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleOwner;
import android.content.Context;
import android.os.Build;
Expand Down Expand Up @@ -358,7 +359,8 @@ public boolean interceptOnBackPressed() {
List<NonNullPair<LifecycleOwner, OnBackPressedListener>> copy = new ArrayList<>(mOnBackPressedListenerList);
for (int i = copy.size() - 1; i >= 0; i--) {
NonNullPair<LifecycleOwner, OnBackPressedListener> pair = copy.get(i);
if (pair.second.onBackPressed()) {
if (pair.first.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)
&& pair.second.onBackPressed()) {
return true;
}
}
Expand Down
Expand Up @@ -86,9 +86,6 @@ public void onClick(View v) {
requireNavigationScene().addOnBackPressedListener(this, new OnBackPressedListener() {
@Override
public boolean onBackPressed() {
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
return false;
}
if (mDrawerLayout.isDrawerOpen(mNavigationView)) {
mDrawerLayout.closeDrawer(mNavigationView);
return true;
Expand Down

0 comments on commit 3dc15e1

Please sign in to comment.