Skip to content
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

Merged
merged 12 commits into from
May 28, 2024

Conversation

justinmc
Copy link
Contributor

@justinmc justinmc commented Apr 22, 2024

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

// 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@justinmc justinmc requested a review from reidbaker April 24, 2024 20:41
@justinmc
Copy link
Contributor Author

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:

$ autoninja -C out/android_debug_unopt                                                                     
$ ./flutter/testing/run_tests.py --type java --java-filter io.flutter.embedding.android.FlutterFragmentTest

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.

@reidbaker
Copy link
Contributor

Honestly @matanlurey is who I go to for engine help but tomorrow I can take a look.

@justinmc
Copy link
Contributor Author

@camsim99 helped me out on Discord, the answer is System.out.println. That should help me make some more progress on the tests tomorrow. Thanks!

@math1man
Copy link
Contributor

Sometimes android.util.Log is better, but in most cases either should work.

@justinmc
Copy link
Contributor Author

Ah thanks, I was using io.flutter.Log, which didn't seem to show up.

@justinmc justinmc marked this pull request as ready for review May 20, 2024 18:15
@justinmc justinmc requested a review from math1man May 20, 2024 18:15
@justinmc
Copy link
Contributor Author

@math1man This works in an add-to-app setup when I try it and the tests pass, but it does not include the changes for predictive back route transitions within Flutter apps (#49093). I guess it will be best to do that in a separate PR?

Copy link
Contributor

@math1man math1man left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@justinmc
Copy link
Contributor Author

@reidbaker This is ready for a final check when you have a chance.

@reidbaker
Copy link
Contributor

Thank you I will get this on my list

@justinmc
Copy link
Contributor Author

Thanks! No rush from me.

Copy link
Contributor

@reidbaker reidbaker left a 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.
Copy link
Contributor

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?

Copy link
Contributor Author

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),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@justinmc justinmc merged commit c364b29 into flutter:main May 28, 2024
26 checks passed
@justinmc justinmc deleted the flutter-fragment-predictive-back branch May 28, 2024 19:52
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 28, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 28, 2024
eyebrowsoffire added a commit to eyebrowsoffire/engine that referenced this pull request May 28, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 28, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 29, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 29, 2024
…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
victorsanni pushed a commit to victorsanni/flutter that referenced this pull request May 31, 2024
…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
justinmc added a commit that referenced this pull request Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants