-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FlutterFragment predictive back #52302
Changes from 4 commits
89629fb
bf4e1ec
c396216
1ae637d
7cd3383
3733332
0d95e27
6d69cfc
c06300a
48765ee
c785e98
1ff7c32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1056,6 +1056,11 @@ public void onAttach(@NonNull Context context) { | |
delegate.onAttach(context); | ||
if (getArguments().getBoolean(ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED, false)) { | ||
requireActivity().getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback); | ||
// By default, Android handles backs, and predictive back is enabled. This | ||
// can be changed by calling setFrameworkHandlesBack. For example, the | ||
// framework will call this automatically in a typical app when it has | ||
// routes to pop. | ||
onBackPressedCallback.setEnabled(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably also need to update the implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @math1man Thanks for jumping back in here, I've been trying to catch back up on your comments from the last PR. Pushing a fix for that now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries. Honestly, I think besides this comment everything looks good. Happy to look into anything specific you might be concerned about though. |
||
} | ||
context.registerComponentCallbacks(this); | ||
} | ||
|
@@ -1673,6 +1678,14 @@ public boolean popSystemNavigator() { | |
return false; | ||
} | ||
|
||
@Override | ||
public void setFrameworkHandlesBack(boolean frameworkHandlesBack) { | ||
if (getArguments().getBoolean(ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED, false)) { | ||
return; | ||
} | ||
onBackPressedCallback.setEnabled(frameworkHandlesBack); | ||
} | ||
|
||
@VisibleForTesting | ||
@NonNull | ||
boolean shouldDelayFirstAndroidViewDraw() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still confused by this code. It looks like we are on a true branch of ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED.
Is this just saying that onBackPressedCallback.setEnabled should be the opposite of the argument passed to ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to push a commit to reword this comment to try to make it more clear.
ARG_SHOULD_AUTOMATICALLY_HANDLE_ON_BACK_PRESSED means that predictive back is enabled. onBackPressedCallback enabled means that Flutter is handling back gestures (typically because Flutter has Flutter routes to on its navigation stack). Disabled means that Android is handling back gestures, so it will either pop the Activity or go back to the phone's home screen.
So when the app starts, by default we let Android handle backs. If/when the Flutter app wants to change this, it calls setFrameworkHandlesBack and enables this callback.