-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Predictive back transition breaking change announcement #12268
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
Merged
+217
−0
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd77b06
Template
justinmc 09878df
Old title and description changes
justinmc 544c62d
Merge branch 'main' into predictive-back-transition
justinmc 05ba917
Everything but description and timeline
justinmc 0923801
Merge branch 'main' into predictive-back-transition
justinmc 68b8633
Finish writing
justinmc 48e2cb6
Update src/content/release/breaking-changes/default-android-page-tran…
sfshaza2 7603606
Fix frontmatter and cleanup formatting
parlough File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
221 changes: 221 additions & 0 deletions
221
src/content/release/breaking-changes/default-android-page-transition.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| --- | ||
| title: The default page transition on Android is now PredictiveBackPageTransitionsBuilder | ||
| description: Android's default page transition has been updated to match the | ||
| platform and to support predictive back. | ||
| --- | ||
|
|
||
| ## Summary | ||
|
|
||
| The default page transition on Android has been updated from | ||
| [`ZoomPageTransitionsBuilder`][] to [`PredictiveBackPageTransitionsBuilder`][]. | ||
| When not using predictive back, this falls back to | ||
| [`FadeForwardsPageTransitionsBuilder`][]. | ||
|
|
||
| ## Context | ||
|
|
||
| Android has been rolling out a feature called predictive back, where performing | ||
| a back gesture allows the user to peek at the previous route or app and possibly | ||
| cancel the navigation. Flutter added support for this with the [`PopScope`][] | ||
| widget followed by [`PredictiveBackPageTransitionsBuilder`][]. | ||
|
|
||
| In the meantime, Android also updated its default page transition. Flutter added | ||
| support for this with [`FadeForwardsPageTransitionsBuilder`][]. | ||
|
|
||
| ## Description of change | ||
|
|
||
| With this change, [`PredictiveBackPageTransitionsBuilder`][] has replaced | ||
| [`ZoomPageTransitionsBuilder`][] as the default page transition on Android. | ||
| During a normal page transition without a predictive back gesture, users | ||
| see the new [`FadeForwardsPageTransitionsBuilder`][] as the default page | ||
| transition. When using a predictive back gesture, the page animates along | ||
| with the gesture and allow canceling or committing to the back navigation. | ||
|
|
||
| In this example, no page transition is explicitly given, so the | ||
| [default]({{site.github}}/flutter/flutter/blob/e983e4bd81f29b17215057fa5c9f46f96cbaf183/packages/flutter/lib/src/material/page_transitions_theme.dart#L806-L813) | ||
| is set to [`PredictiveBackPageTransitionsBuilder`][] in the theme on Android. | ||
|
|
||
| <!-- skip --> | ||
| ```dart | ||
| MaterialApp( | ||
| theme: ThemeData( | ||
| brightness: Brightness.light, | ||
| ), | ||
| home: const PageOne(), | ||
| ); | ||
| ``` | ||
|
|
||
| ## Migration guide | ||
|
|
||
| If you want to keep your app's page transition on the old | ||
| [`ZoomPageTransitionsBuilder`][], you can simply set your page transition | ||
| explicitly in your app's theme. Keep in mind that you will not be able to | ||
| support predictive back route transitions. | ||
|
|
||
| Code before migration: | ||
|
|
||
| <!-- skip --> | ||
| ```dart | ||
| return MaterialApp( | ||
| theme: ThemeData( | ||
| brightness: Brightness.light, | ||
| // pageTransitionsTheme is the default. | ||
| ), | ||
| home: const MyFirstScreen(), | ||
| ); | ||
| ``` | ||
|
|
||
| Code after migration: | ||
|
|
||
| <!-- skip --> | ||
| ```dart | ||
| MaterialApp( | ||
| theme: ThemeData( | ||
| // pageTransitionsTheme is explicitly set to the old transition on Android. | ||
| pageTransitionsTheme: const PageTransitionsTheme( | ||
| builders: { | ||
| TargetPlatform.android: ZoomPageTransitionsBuilder(), | ||
| }, | ||
| ), | ||
| ), | ||
| home: const MyFirstScreen(), | ||
| ); | ||
| ``` | ||
|
|
||
| One side effect of changing the default transition is that the duration that it | ||
| takes to transition between pages has increased from 300ms to 450ms. This may | ||
| cause breakages in tests that depend on the previous transition duration. | ||
| Fortunately, it's possible to use [`TransitionDurationObserver`][] to keep tests | ||
| independent of whatever page transition is used. | ||
|
|
||
| Code before migration: | ||
|
|
||
| <!-- skip --> | ||
| ```dart | ||
| testWidgets('example', (WidgetTester tester) async { | ||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| onGenerateRoute: (RouteSettings settings) { ... }, | ||
| ), | ||
| ); | ||
|
|
||
| expect(find.text('Page 1'), findsOneWidget); | ||
| expect(find.text('Page 2'), findsNothing); | ||
|
|
||
| // Pump through the whole transition, hardcoded to 300ms. | ||
| await tester.tap(find.text('Next')); | ||
| await tester.pump(const Duration(milliseconds: 300)); | ||
|
|
||
| expect(find.text('Page 1'), findsNothing); | ||
| expect(find.text('Page 2'), findsOneWidget); | ||
| }); | ||
| ``` | ||
|
|
||
| Code after migration: | ||
|
|
||
| <!-- skip --> | ||
| ```dart | ||
| testWidgets('example', (WidgetTester tester) async { | ||
| final TransitionDurationObserver observer = TransitionDurationObserver(); | ||
|
|
||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| navigatorObservers: <NavigatorObserver>[observer], | ||
| onGenerateRoute: (RouteSettings settings) { ... }, | ||
| ), | ||
| ); | ||
|
|
||
| expect(find.text('Page 1'), findsOneWidget); | ||
| expect(find.text('Page 2'), findsNothing); | ||
|
|
||
| // Pump through the whole transition independent of the duration. | ||
| await tester.tap(find.text('Next')); | ||
| await observer.pumpPastTransition(tester); | ||
|
|
||
| expect(find.text('Page 1'), findsNothing); | ||
| expect(find.text('Page 2'), findsOneWidget); | ||
| }); | ||
| ``` | ||
|
|
||
| It's even possible to write tests that need to pump part of the way through a | ||
| page transition without depending on the exact duration. | ||
|
|
||
| Code before migration: | ||
|
|
||
| <!-- skip --> | ||
| ```dart | ||
| testWidgets('example', (WidgetTester tester) async { | ||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| onGenerateRoute: (RouteSettings settings) { ... }, | ||
| ), | ||
| ); | ||
|
|
||
| expect(find.text('Page 1'), findsOneWidget); | ||
| expect(find.text('Page 2'), findsNothing); | ||
|
|
||
| // Pump through half of the transition with a hardcoded value. | ||
| await tester.tap(find.text('Back')); | ||
| await tester.pump(const Duration(milliseconds: 150)); | ||
|
|
||
| expect(find.text('Page 1'), findsOneWidget); | ||
| expect(find.text('Page 2'), findsOneWidget); | ||
| }); | ||
| ``` | ||
|
|
||
| Code after migration: | ||
|
|
||
| <!-- skip --> | ||
| ```dart | ||
| testWidgets('example', (WidgetTester tester) async { | ||
| final TransitionDurationObserver observer = TransitionDurationObserver(); | ||
|
|
||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| navigatorObservers: <NavigatorObserver>[observer], | ||
| onGenerateRoute: (RouteSettings settings) { ... }, | ||
| ), | ||
| ); | ||
|
|
||
| expect(find.text('Page 1'), findsOneWidget); | ||
| expect(find.text('Page 2'), findsNothing); | ||
|
|
||
| // Pump through half of the transition independent of the duration. | ||
| await tester.tap(find.text('Back')); | ||
| await tester.pump(observer.transitionDuration ~/ 2); | ||
|
|
||
| expect(find.text('Page 1'), findsOneWidget); | ||
| expect(find.text('Page 2'), findsOneWidget); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Timeline | ||
|
|
||
| Landed in version: 3.37.0-0.0.pre<br> | ||
| In stable release: 3.38.0 | ||
|
|
||
| ## References | ||
|
|
||
| API documentation: | ||
|
|
||
| * [`ZoomPageTransitionsBuilder`][] | ||
| * [`PredictiveBackPageTransitionsBuilder`][] | ||
| * [`FadeForwardsPageTransitionsBuilder`][] | ||
| * [`PopScope`][] | ||
| * [`TransitionDurationObserver`][] | ||
|
|
||
| Relevant issues: | ||
|
|
||
| * [Android predictive back route transitions][] | ||
|
|
||
| Relevant PRs: | ||
|
|
||
| * [Predictive back route transitions by default][] | ||
|
|
||
| [`FadeForwardsPageTransitionsBuilder`]: {{site.api}}/flutter/material/FadeForwardsPageTransitionsBuilder-class.html | ||
| [`PopScope`]: {{site.api}}/flutter/widgets/PopScope-class.html | ||
| [`PredictiveBackPageTransitionsBuilder`]: {{site.api}}/flutter/material/PredictiveBackPageTransitionsBuilder-class.html | ||
| [`TransitionDurationObserver`]: {{site.api}}/flutter/flutter_test/TransitionDurationObserver-class.html | ||
| [`ZoomPageTransitionsBuilder`]: {{site.api}}/flutter/material/ZoomPageTransitionsBuilder-class.html | ||
|
|
||
| [Android predictive back route transitions]: {{site.github.com}}/flutter/flutter/issues/131961 | ||
| [Predictive back route transitions by default]: {{site.github}}/flutter/flutter/pull/165832 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.