diff --git a/packages/flutter/lib/src/cupertino/page.dart b/packages/flutter/lib/src/cupertino/page.dart index 9c33be96d6..b1ae0fa58d 100644 --- a/packages/flutter/lib/src/cupertino/page.dart +++ b/packages/flutter/lib/src/cupertino/page.dart @@ -36,15 +36,19 @@ class CupertinoPageTransition extends AnimatedWidget { // one. @required Animation outgoingRouteAnimation, @required this.child, + // Perform incoming transition linearly. Use to precisely track back gesture drags. + bool linearTransition, }) : - incomingPositionAnimation = _kRightMiddleTween.animate( - new CurvedAnimation( - parent: incomingRouteAnimation, - curve: Curves.easeOut, - reverseCurve: Curves.easeIn, - ) - ), - outgoingPositionAnimation = _kMiddleLeftTween.animate( + _incomingPositionAnimation = linearTransition + ? _kRightMiddleTween.animate(incomingRouteAnimation) + : _kRightMiddleTween.animate( + new CurvedAnimation( + parent: incomingRouteAnimation, + curve: Curves.easeOut, + reverseCurve: Curves.easeIn, + ) + ), + _outgoingPositionAnimation = _kMiddleLeftTween.animate( new CurvedAnimation( parent: outgoingRouteAnimation, curve: Curves.easeOut, @@ -60,19 +64,20 @@ class CupertinoPageTransition extends AnimatedWidget { ); // When this page is coming in to cover another page. - final Animation incomingPositionAnimation; + final Animation _incomingPositionAnimation; // When this page is becoming covered by another page. - final Animation outgoingPositionAnimation; + final Animation _outgoingPositionAnimation; final Widget child; + @override Widget build(BuildContext context) { // TODO(ianh): tell the transform to be un-transformed for hit testing // but not while being controlled by a gesture. return new SlideTransition( - position: outgoingPositionAnimation, + position: _outgoingPositionAnimation, child: new SlideTransition( - position: incomingPositionAnimation, + position: _incomingPositionAnimation, child: new PhysicalModel( shape: BoxShape.rectangle, color: _kBackgroundColor, diff --git a/packages/flutter/lib/src/material/page.dart b/packages/flutter/lib/src/material/page.dart index 7893b87b2d..05cd610106 100644 --- a/packages/flutter/lib/src/material/page.dart +++ b/packages/flutter/lib/src/material/page.dart @@ -176,6 +176,9 @@ class MaterialPageRoute extends PageRoute { incomingRouteAnimation: animation, outgoingRouteAnimation: forwardAnimation, child: child, + // In the middle of a back gesture drag, let the transition be linear to match finger + // motions. + linearTransition: _backGestureController != null, ); } else { return new _MountainViewPageTransition( diff --git a/packages/flutter/test/material/page_test.dart b/packages/flutter/test/material/page_test.dart index 4e9b4ba4a8..b0e9454132 100644 --- a/packages/flutter/test/material/page_test.dart +++ b/packages/flutter/test/material/page_test.dart @@ -209,7 +209,7 @@ void main() { // Drag from left edge to invoke the gesture. final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0)); await gesture.moveBy(const Offset(400.0, 0.0)); - await tester.pumpAndSettle(); + await tester.pump(); expect(find.text('Page 1'), findsNothing); expect(find.text('Page 2'), isOnstage); @@ -240,11 +240,24 @@ void main() { // Drag from left edge to invoke the gesture. final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0)); await gesture.moveBy(const Offset(400.0, 0.0)); - await tester.pumpAndSettle(); + await tester.pump(); // Page 1 is now visible. expect(find.text('Page 1'), isOnstage); expect(find.text('Page 2'), isOnstage); + + // The route widget position needs to track the finger position very exactly. + expect(tester.getTopLeft(find.text('Page 2')), const Point(400.0, 0.0)); + + await gesture.moveBy(const Offset(-200.0, 0.0)); + await tester.pump(); + + expect(tester.getTopLeft(find.text('Page 2')), const Point(200.0, 0.0)); + + await gesture.moveBy(const Offset(-100.0, 200.0)); + await tester.pump(); + + expect(tester.getTopLeft(find.text('Page 2')), const Point(100.0, 0.0)); }); testWidgets('test no back gesture on iOS fullscreen dialogs', (WidgetTester tester) async { @@ -269,7 +282,7 @@ void main() { // Drag from left edge to invoke the gesture. final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0)); await gesture.moveBy(const Offset(400.0, 0.0)); - await tester.pumpAndSettle(); + await tester.pump(); expect(find.text('Page 1'), findsNothing); expect(find.text('Page 2'), isOnstage);