Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[wip] Restore old back handling for FlutterFragmentActivity #56565

Closed
wants to merge 2 commits into from

Conversation

gmackall
Copy link
Member

Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.

List which issues are fixed by this PR. You must list at least one issue.

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@gmackall gmackall marked this pull request as draft November 13, 2024 19:29
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

@gmackall gmackall changed the title Fix FlutterFragmentActivity back breakage [wip] Restore old back handling for FlutterFragmentActivity Nov 21, 2024
@jmagman
Copy link
Member

jmagman commented Jan 7, 2025

@gmackall post-monorepo can you recreate this in the framework when you get a chance?

@gmackall
Copy link
Member Author

flutter/flutter#161545

@gmackall gmackall closed this Jan 13, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Feb 21, 2025
Remake of flutter/engine#56565. Quoting from an
old comment, slightly edited:

------------ 

flutter/engine#52302 seems to have
unintentionally had the effect of not allowing people to "opt out" of
predictive back. This is actually aligned with what the android docs say
should happen:

https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture
> Note: OnBackPressedCallback is always called regardless of the value
of android:enableOnBackInvokedCallback. In other words, disabling the
system animation doesn't affect your app's back handling logic if it
uses OnBackPressedCallback.

But this wasn't actually true for flutter apps before
flutter/engine#52302, because we were not
calling `super`, and `FlutterFragmentActivity` extends a
`FragmentActivity` which in turn extends a `ComponentActivity`, which
uses the old `onBackPressed` to [invoke the new back
handling](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/ComponentActivity.kt;l=587?q=ComponentActivity):
```kotlin
   override fun onBackPressed() {
        onBackPressedDispatcher.onBackPressed()
    }
```

So while the docs imply that removing the `onBackPressed` in
`FlutterFragmentActivity` shouldn't have had an effect, that wasn't true
because in our case we were consuming the back event and ignoring the
warning
```java
  @OverRide
  @SuppressWarnings("MissingSuperCall")
  public void onBackPressed() {
    flutterFragment.onBackPressed();
  }
```

What all this means is that apps that _aren't_ opting in to predictive
back had their back handling migrated to the new code path
automatically. FlutterFragmentActivity was uniquely is forced into the
new back handling codepath by
flutter/engine#52302, which this PR fixes.

------------ 

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Gray Mackall <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants