-
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
Platform channel for predictive back #39208
Changes from 20 commits
9b25e71
b10efe3
75d8e38
e8a5130
9c0e7cc
205d1e5
66d1f84
9e8e230
0ed2bec
2afbbad
8aeba57
5e89211
015f2a5
b7b2f17
6bc7d5e
01a22a2
6f22009
440a6ee
e075275
af98e2c
1db22e5
4701d66
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 |
---|---|---|
|
@@ -217,6 +217,8 @@ public class FlutterActivity extends Activity | |
implements FlutterActivityAndFragmentDelegate.Host, LifecycleOwner { | ||
private static final String TAG = "FlutterActivity"; | ||
|
||
private boolean hasRegisteredCallback = false; | ||
|
||
/** | ||
* The ID of the {@code FlutterView} created by this activity. | ||
* | ||
|
@@ -643,8 +645,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { | |
|
||
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); | ||
|
||
registerOnBackInvokedCallback(); | ||
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. Now that this is removed, it means that by default, Flutter will not handle back gestures. So if you start up a Flutter app that does nothing, has no Navigator or WidgetsApp etc., root predictive back will work. The framework will have to first call setFrameworkHandlesBacks in order to prevent predictive back and to handle back gestures itself. This will be handled automatically in Flutter apps that use WidgetsApp. |
||
|
||
configureWindowForTransparency(); | ||
|
||
setContentView(createFlutterView()); | ||
|
@@ -668,6 +668,7 @@ public void registerOnBackInvokedCallback() { | |
getOnBackInvokedDispatcher() | ||
.registerOnBackInvokedCallback( | ||
OnBackInvokedDispatcher.PRIORITY_DEFAULT, onBackInvokedCallback); | ||
hasRegisteredCallback = true; | ||
} | ||
} | ||
|
||
|
@@ -681,6 +682,7 @@ public void registerOnBackInvokedCallback() { | |
public void unregisterOnBackInvokedCallback() { | ||
if (Build.VERSION.SDK_INT >= 33) { | ||
getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(onBackInvokedCallback); | ||
hasRegisteredCallback = false; | ||
} | ||
} | ||
|
||
|
@@ -698,6 +700,15 @@ public void onBackInvoked() { | |
} | ||
: null; | ||
|
||
@Override | ||
public void setFrameworkHandlesBacks(boolean frameworkHandlesBacks) { | ||
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. How do people feel about this name? 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. suggestion: setFrameworkHandlesBack (without the plural s)? 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. Maybe something to indicate it registers/unregisters a callback based on 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. I'm going to go with I kind of wanted to be generic about what is actually happening under the hood in case that changes, or in case we ever needed to do this on another platform that handles it differently. I think Let me know if anyone has other thoughts though. |
||
if (frameworkHandlesBacks && !hasRegisteredCallback) { | ||
registerOnBackInvokedCallback(); | ||
} else if (!frameworkHandlesBacks && hasRegisteredCallback) { | ||
unregisterOnBackInvokedCallback(); | ||
} | ||
} | ||
|
||
/** | ||
* Switches themes for this {@code Activity} from the theme used to launch this {@code Activity} | ||
* to a "normal theme" that is intended for regular {@code Activity} operation. | ||
|
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.
nit: should this get a more specific name as to what callback has been registered for context?
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.
Changed to: hasRegisteredBackCallback