-
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
FlutterFragment predictive back #52302
Conversation
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
You probably also need to update the implementation of popSystemNavigator()
to restore the previous state of the callback-enablement, instead of unconditionally re-enabling it on line 1673.
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.
@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 comment
The 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.
Could @math1man or @reidbaker point me in the right direction for how to test this? Sorry I'm pretty inexperienced here, I'm struggling to even get into a real workflow. It seems like I need to recompile every time I touch the engine code (but not the test code). I'm doing:
But for one, I don't know how to view the output of Log statements I put in the test or in the engine code. They never show up in the test output. I added some code in FlutterFragmentTest to verify popSystemNavigator is enabling/disabling the callback, but it doesn't seem to fail if I revert the PR's changes, and I'm struggling to understand why not without the benefit of logs. |
Honestly @matanlurey is who I go to for engine help but tomorrow I can take a look. |
@camsim99 helped me out on Discord, the answer is |
Sometimes |
Ah thanks, I was using |
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.
LGTM
@reidbaker This is ready for a final check when you have a chance. |
Thank you I will get this on my list |
Thanks! No rush from me. |
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.
Approved but there are some comments on trying to understand this code.
// 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. |
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.
@@ -318,8 +320,15 @@ public void itDelegatesOnBackPressedAutomaticallyWhenEnabled() { | |||
TestDelegateFactory delegateFactory = new TestDelegateFactory(mockDelegate); | |||
fragment.setDelegateFactory(delegateFactory); | |||
|
|||
// Calling onBackPressed now will still be handled by Android (the default), |
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.
reading this test shouldn't the back pressed be handled by the framework because of the code on 306?
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.
My comment above should help explain this a bit. shouldAutomaticallyHandleOnBackPressed enables predictive back, while setFrameworkHandlesBack determines whether Android or the framework handle the back gesture.
This reverts commit c364b29.
…sions) (#149220) Manual roll requested by [email protected] flutter/engine@d032390...b26e1b0 2024-05-28 [email protected] Manual revert of #53001 (flutter/engine#53075) 2024-05-28 [email protected] Remove --ios-cpu flag. Only the arm64 variant is supported. (flutter/engine#53044) 2024-05-28 [email protected] Roll Skia from 229d94a8807e to ac454b80130c (1 revision) (flutter/engine#53074) 2024-05-28 [email protected] [Impeller] make strokes slightly lighter. (flutter/engine#53067) 2024-05-28 [email protected] Roll Skia from 23ddbb590e44 to 229d94a8807e (2 revisions) (flutter/engine#53071) 2024-05-28 [email protected] FlutterFragment predictive back (flutter/engine#52302) 2024-05-28 [email protected] Roll Skia from 02c359cf8233 to 23ddbb590e44 (2 revisions) (flutter/engine#53070) 2024-05-28 [email protected] Roll Skia from 4f91b3865441 to 02c359cf8233 (1 revision) (flutter/engine#53069) 2024-05-28 [email protected] [Impeller] shrunk the buffer for the rrect_blur (flutter/engine#53068) 2024-05-28 [email protected] Roll Skia from 91cd2b48377a to 4f91b3865441 (4 revisions) (flutter/engine#53066) 2024-05-28 [email protected] Upgrade all[most] androidx dependencies to latest (flutter/engine#53001) 2024-05-28 [email protected] Roll Skia from 0c2c490021b7 to 91cd2b48377a (3 revisions) (flutter/engine#53065) 2024-05-28 [email protected] Roll Skia from 545203f95d4e to 0c2c490021b7 (2 revisions) (flutter/engine#53063) 2024-05-28 [email protected] Roll Skia from 74b4d97be6ab to 545203f95d4e (1 revision) (flutter/engine#53062) 2024-05-28 [email protected] Roll Skia from 848d9498fd68 to 74b4d97be6ab (1 revision) (flutter/engine#53061) 2024-05-28 [email protected] Remove use of --nnbd-agnostic (flutter/engine#53055) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…sions) (flutter#149220) Manual roll requested by [email protected] flutter/engine@d032390...b26e1b0 2024-05-28 [email protected] Manual revert of flutter#53001 (flutter/engine#53075) 2024-05-28 [email protected] Remove --ios-cpu flag. Only the arm64 variant is supported. (flutter/engine#53044) 2024-05-28 [email protected] Roll Skia from 229d94a8807e to ac454b80130c (1 revision) (flutter/engine#53074) 2024-05-28 [email protected] [Impeller] make strokes slightly lighter. (flutter/engine#53067) 2024-05-28 [email protected] Roll Skia from 23ddbb590e44 to 229d94a8807e (2 revisions) (flutter/engine#53071) 2024-05-28 [email protected] FlutterFragment predictive back (flutter/engine#52302) 2024-05-28 [email protected] Roll Skia from 02c359cf8233 to 23ddbb590e44 (2 revisions) (flutter/engine#53070) 2024-05-28 [email protected] Roll Skia from 4f91b3865441 to 02c359cf8233 (1 revision) (flutter/engine#53069) 2024-05-28 [email protected] [Impeller] shrunk the buffer for the rrect_blur (flutter/engine#53068) 2024-05-28 [email protected] Roll Skia from 91cd2b48377a to 4f91b3865441 (4 revisions) (flutter/engine#53066) 2024-05-28 [email protected] Upgrade all[most] androidx dependencies to latest (flutter/engine#53001) 2024-05-28 [email protected] Roll Skia from 0c2c490021b7 to 91cd2b48377a (3 revisions) (flutter/engine#53065) 2024-05-28 [email protected] Roll Skia from 545203f95d4e to 0c2c490021b7 (2 revisions) (flutter/engine#53063) 2024-05-28 [email protected] Roll Skia from 74b4d97be6ab to 545203f95d4e (1 revision) (flutter/engine#53062) 2024-05-28 [email protected] Roll Skia from 848d9498fd68 to 74b4d97be6ab (1 revision) (flutter/engine#53061) 2024-05-28 [email protected] Remove use of --nnbd-agnostic (flutter/engine#53055) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Following up on #39208 and #42789, which added predictive back support for FlutterActivity.
My test app for this is: https://github.com/justinmc/flutter-add-to-app
I tried this both with the Flutter app as the main activity, and with it as a secondary activity after an initial Android route. Predictive back worked in both cases. However, this PR does not include support for in-app route transitions in Flutter.
Related: flutter/flutter#109558, and my comment flutter/flutter#109558 (comment).
b/242216228