-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Refactor: Migrate page transition builder class to widgets #174321
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
Refactor: Migrate page transition builder class to widgets #174321
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. 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. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). 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. |
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.
Code Review
This pull request refactors the PageTransitionsBuilder class by moving it from packages/flutter/lib/src/material/page_transitions_theme.dart to a new file packages/flutter/lib/src/widgets/page_transitions_builder.dart. This is a good architectural improvement, placing the general-purpose builder in a lower-level library. The changes are clean and the existing tests should cover this refactoring. I've added a couple of suggestions to improve the documentation in the new file to better reflect its new, more generic location.
| /// Used by [PageTransitionsTheme] to define a [MaterialPageRoute] page | ||
| /// transition animation. | ||
| /// | ||
| /// Apps can configure the map of builders for [ThemeData.pageTransitionsTheme] | ||
| /// to customize the default [MaterialPageRoute] page transition animation | ||
| /// for different platforms. | ||
| /// | ||
| /// See also: | ||
| /// | ||
| /// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition | ||
| /// that's similar to the one provided by Android O. | ||
| /// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition | ||
| /// that's similar to the one provided by Android P. | ||
| /// * [ZoomPageTransitionsBuilder], which defines the default page transition | ||
| /// that's similar to the one provided in Android Q. | ||
| /// * [CupertinoPageTransitionsBuilder], which defines a horizontal page | ||
| /// transition that matches native iOS page transitions. | ||
| /// * [FadeForwardsPageTransitionsBuilder], which defines a page transition | ||
| /// that's similar to the one provided by Android U. |
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.
Since PageTransitionsBuilder is now in the widgets library, its documentation should be more generic and not solely focused on its usage within the material library.1
I suggest updating the class documentation to first provide a general description and then specify its use in material. Also, adding PageTransitionsTheme and MaterialPageRoute to the "See also" section would provide better context for developers.
/// Defines a page transition animation for a [PageRoute].
///
/// This class is used by [PageTransitionsTheme] to define a [MaterialPageRoute]
/// page transition animation. Apps can configure the map of builders for
/// [ThemeData.pageTransitionsTheme] to customize the default
/// [MaterialPageRoute] page transition animation for different platforms.
///
/// See also:
///
/// * [PageTransitionsTheme], which uses this class to configure page transitions.
/// * [MaterialPageRoute], which uses this class to build its transition.
/// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android O.
/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android P.
/// * [ZoomPageTransitionsBuilder], which defines the default page transition
/// that's similar to the one provided in Android Q.
/// * [CupertinoPageTransitionsBuilder], which defines a horizontal page
/// transition that matches native iOS page transitions.
/// * [FadeForwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android U.Style Guide References
Footnotes
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.
+1
| /// Wraps the child with one or more transition widgets which define how [route] | ||
| /// arrives on and leaves the screen. | ||
| /// | ||
| /// The [MaterialPageRoute.buildTransitions] method looks up the | ||
| /// current [PageTransitionsTheme] with `Theme.of(context).pageTransitionsTheme` | ||
| /// and delegates to this method with a [PageTransitionsBuilder] based | ||
| /// on the theme's [ThemeData.platform]. |
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.
The documentation for buildTransitions is very specific to its usage in MaterialPageRoute. To improve clarity and adhere to better layering, I suggest making the documentation more general first, explaining the method's purpose, and then providing the MaterialPageRoute usage as an example.1
/// Wraps the child with one or more transition widgets which define how [route]
/// arrives on and leaves the screen.
///
/// Subclasses override this method to create a transition animation.
///
/// The [MaterialPageRoute.buildTransitions] method is an example of a method
/// that uses this to build a transition. It looks up the current
/// [PageTransitionsTheme] with `Theme.of(context).pageTransitionsTheme`
/// and delegates to this method with a [PageTransitionsBuilder] based
/// on the theme's [ThemeData.platform].Style Guide References
Footnotes
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.
+1 here
victorsanni
left a comment
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 would avoid design-language-specific documentation and references (Material, Theme and ThemeData etc). Try to make this as standalone and as design-language-agnostic as possible. Instead, move the Material-specific documentation to the relevant Material widgets.
I asked offline and found this is not entirely true. Referencing |
victorsanni
left a comment
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.
The documentation suggestions from gemini look like a good place to start.
Also are there tests for this class that can be moved here? I don't think we want to add a new file + class in widgets/ without some sort of test.
0fc4d18 to
b74aecf
Compare
|
I don't think there are tests for |
A test could make a mock transitions builder that extends |
b74aecf to
21cee4d
Compare
|
Approach with test so far is looking good. Can you adopt the gemini doc recommendations and fix the failing tests in CI? |
8a2a6e8 to
37a9080
Compare
37a9080 to
907ca6f
Compare
victorsanni
left a comment
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.
Looking good so far, one final comment asking for more documentation.
907ca6f to
313d4b2
Compare
|
@victorsanni I have updated the paragraph, please have a look. |
| scale: Tween<double>( | ||
| begin: 0.5, | ||
| end: 1.0, | ||
| ).animate(CurvedAnimation(parent: animation, curve: Curves.easeInOut)), |
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.
this might be causing a memory leak, consider using CurveTween or something similar instead.
| /// in any design system. Custom [PageRoute] subclasses can accept a | ||
| /// PageTransitionsBuilder and delegate to its [buildTransitions] method when | ||
| /// overriding [ModalRoute.buildTransitions]. This enables reusable transition | ||
| /// animations that work with [Navigator] and other navigation primitives without |
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.
Not sure we need to explicitly say "without requiring Material Design components". The idea is the class should be understandable as a standalone concept for developers who don't even know Material exists.
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.
So this should precede the paragraph on PageTransitionsTheme, while that paragraph should be prefixed with an annotation that it is an example of how this class can be used.
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.
Yup, Make sense.
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 have pushed snipped directly in doc, right now. Do you feel, we should create a example file for this?
383ab98 to
d3c5c97
Compare
d3c5c97 to
69bd510
Compare
victorsanni
left a comment
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.
To fix linux analyze, run dart format packages/flutter/test/widgets/page_transitions_builder_test.dart
3872487 to
04b7698
Compare
…74321) Changes * Move PageTransitionsBuilder from `material/page_transitions_theme.dart` to `widget/page_transitions_builder.dart` part of: flutter#172929 ## 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 `///`). - [ ] 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. - [x] All existing and new tests are passing.
…74321) Changes * Move PageTransitionsBuilder from `material/page_transitions_theme.dart` to `widget/page_transitions_builder.dart` part of: flutter#172929 ## 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 `///`). - [ ] 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. - [x] All existing and new tests are passing.
…74321) Changes * Move PageTransitionsBuilder from `material/page_transitions_theme.dart` to `widget/page_transitions_builder.dart` part of: flutter#172929 ## 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 `///`). - [ ] 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. - [x] All existing and new tests are passing.
Changes
material/page_transitions_theme.darttowidget/page_transitions_builder.dartpart of: #172929
Pre-launch Checklist
///).