-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[material_ui] Handle unknown swipe edges in predictive back transitions #12502
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
Open
muhammadkamel
wants to merge
1
commit into
flutter:main
Choose a base branch
from
muhammadkamel:fix/material-ui-predictive-back-swipe-edge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+162
−2
Open
Changes from all commits
Commits
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
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
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
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -675,6 +675,156 @@ void main() { | |||||
| }); | ||||||
| } | ||||||
|
|
||||||
| testWidgets( | ||||||
| 'PredictiveBackPageTransitionsBuilder supports right-edge swipe (page slides from right)', | ||||||
| (WidgetTester tester) async { | ||||||
| const PageTransitionsBuilder pageTransitionsBuilder = PredictiveBackPageTransitionsBuilder(); | ||||||
| final routes = <String, WidgetBuilder>{ | ||||||
| '/': (BuildContext context) => Material( | ||||||
| child: TextButton( | ||||||
| child: const Text('push'), | ||||||
| onPressed: () => Navigator.of(context).pushNamed('/b'), | ||||||
| ), | ||||||
| ), | ||||||
| '/b': (BuildContext context) => const Text('page b'), | ||||||
| }; | ||||||
|
|
||||||
| await tester.pumpWidget( | ||||||
| MaterialApp( | ||||||
| theme: ThemeData( | ||||||
| pageTransitionsTheme: PageTransitionsTheme( | ||||||
| builders: <TargetPlatform, PageTransitionsBuilder>{ | ||||||
| for (final TargetPlatform platform in TargetPlatform.values) | ||||||
| platform: pageTransitionsBuilder, | ||||||
| }, | ||||||
| ), | ||||||
| ), | ||||||
| routes: routes, | ||||||
| ), | ||||||
| ); | ||||||
|
|
||||||
| await tester.tap(find.text('push')); | ||||||
| await tester.pumpAndSettle(); | ||||||
|
|
||||||
| if (defaultTargetPlatform != TargetPlatform.android) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| // Start back gesture from the right edge (swipeEdge: 1). | ||||||
| final ByteData startMessage = const StandardMethodCodec().encodeMethodCall( | ||||||
| const MethodCall('startBackGesture', <String, dynamic>{ | ||||||
| 'touchOffset': <double>[800.0, 300.0], | ||||||
| 'progress': 0.0, | ||||||
| 'swipeEdge': 1, // right | ||||||
| }), | ||||||
| ); | ||||||
| await binding.defaultBinaryMessenger.handlePlatformMessage( | ||||||
| 'flutter/backgesture', | ||||||
| startMessage, | ||||||
| (ByteData? _) {}, | ||||||
| ); | ||||||
| await tester.pump(); | ||||||
|
|
||||||
| expect(_findPredictiveBackPageTransition(pageTransitionsBuilder), findsOneWidget); | ||||||
|
|
||||||
| // Drag from right edge — page should shift to the left (negative dx). | ||||||
| final ByteData updateMessage = const StandardMethodCodec().encodeMethodCall( | ||||||
| const MethodCall('updateBackGestureProgress', <String, dynamic>{ | ||||||
| 'touchOffset': <double>[700.0, 300.0], | ||||||
| 'progress': 0.35, | ||||||
| 'swipeEdge': 1, // right | ||||||
| }), | ||||||
| ); | ||||||
| await binding.defaultBinaryMessenger.handlePlatformMessage( | ||||||
| 'flutter/backgesture', | ||||||
| updateMessage, | ||||||
| (ByteData? _) {}, | ||||||
| ); | ||||||
| await tester.pumpAndSettle(); | ||||||
|
|
||||||
| // The page animates during a right-edge swipe. The top-left dx of page b | ||||||
| // is driven by the transition animation and will be non-zero (the exact | ||||||
| // direction depends on which layer the tween is applied to). | ||||||
| final Offset pageBOffset = tester.getTopLeft(find.text('page b')); | ||||||
| expect(pageBOffset.dx, isNot(0.0)); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a right-edge swipe, the page is expected to shift to the left (negative
Suggested change
|
||||||
|
|
||||||
| // Commit the gesture. | ||||||
| final ByteData commitMessage = const StandardMethodCodec().encodeMethodCall( | ||||||
| const MethodCall('commitBackGesture'), | ||||||
| ); | ||||||
| await binding.defaultBinaryMessenger.handlePlatformMessage( | ||||||
| 'flutter/backgesture', | ||||||
| commitMessage, | ||||||
| (ByteData? _) {}, | ||||||
| ); | ||||||
| await tester.pumpAndSettle(); | ||||||
|
|
||||||
| expect(find.text('push'), findsOneWidget); | ||||||
| expect(find.text('page b'), findsNothing); | ||||||
| }, | ||||||
| variant: TargetPlatformVariant.all(), | ||||||
| ); | ||||||
|
|
||||||
| testWidgets('button-triggered back does not start a predictive back animation', ( | ||||||
| WidgetTester tester, | ||||||
| ) async { | ||||||
| const PageTransitionsBuilder pageTransitionsBuilder = PredictiveBackPageTransitionsBuilder(); | ||||||
| final routes = <String, WidgetBuilder>{ | ||||||
| '/': (BuildContext context) => Material( | ||||||
| child: TextButton( | ||||||
| child: const Text('push'), | ||||||
| onPressed: () => Navigator.of(context).pushNamed('/b'), | ||||||
| ), | ||||||
| ), | ||||||
| '/b': (BuildContext context) => const Text('page b'), | ||||||
| }; | ||||||
|
|
||||||
| await tester.pumpWidget( | ||||||
| MaterialApp( | ||||||
| theme: ThemeData( | ||||||
| pageTransitionsTheme: PageTransitionsTheme( | ||||||
| builders: <TargetPlatform, PageTransitionsBuilder>{ | ||||||
| for (final TargetPlatform platform in TargetPlatform.values) | ||||||
| platform: pageTransitionsBuilder, | ||||||
| }, | ||||||
| ), | ||||||
| ), | ||||||
| routes: routes, | ||||||
| ), | ||||||
| ); | ||||||
|
|
||||||
| await tester.tap(find.text('push')); | ||||||
| await tester.pumpAndSettle(); | ||||||
|
|
||||||
| if (defaultTargetPlatform != TargetPlatform.android) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| expect(_findPredictiveBackPageTransition(pageTransitionsBuilder), findsNothing); | ||||||
| expect(_findFallbackPageTransition(pageTransitionsBuilder), findsOneWidget); | ||||||
|
|
||||||
| // Android button-triggered back events report a zero touch offset and | ||||||
| // zero progress. handleStartBackGesture treats these as isButtonEvent | ||||||
| // and does not start a predictive animation. | ||||||
| final ByteData startMessage = const StandardMethodCodec().encodeMethodCall( | ||||||
| const MethodCall('startBackGesture', <String, dynamic>{ | ||||||
| 'touchOffset': <double>[0.0, 0.0], | ||||||
| 'progress': 0.0, | ||||||
| 'swipeEdge': 0, | ||||||
| }), | ||||||
| ); | ||||||
| await binding.defaultBinaryMessenger.handlePlatformMessage( | ||||||
| 'flutter/backgesture', | ||||||
| startMessage, | ||||||
| (ByteData? _) {}, | ||||||
| ); | ||||||
| await tester.pump(); | ||||||
|
|
||||||
| // The predictive back transition must NOT have started. | ||||||
| expect(_findPredictiveBackPageTransition(pageTransitionsBuilder), findsNothing); | ||||||
| expect(_findFallbackPageTransition(pageTransitionsBuilder), findsOneWidget); | ||||||
| }, variant: TargetPlatformVariant.all()); | ||||||
|
|
||||||
| testWidgets('PredictiveBackPageTransitionsBuilder uses fallbackColor', ( | ||||||
| WidgetTester tester, | ||||||
| ) async { | ||||||
|
|
||||||
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.
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
SwipeEdge.leftand the wildcard_fallback both return the exact same offsetOffset(xShift, _getYShiftPosition(screenSize.height)), we can simplify the switch expression by removing the redundantSwipeEdge.leftcase and letting the wildcard pattern handle it.