Commit 0cf2f88f authored by xster's avatar xster Committed by GitHub

Make Cupertino page transition linear during drag (#9167)

* Just realized the creation order is the other way around

* Works

* Revert previous partial solution

* Change pumpAndSettle to pump for gestures
parent 1182eb18
...@@ -36,15 +36,19 @@ class CupertinoPageTransition extends AnimatedWidget { ...@@ -36,15 +36,19 @@ class CupertinoPageTransition extends AnimatedWidget {
// one. // one.
@required Animation<double> outgoingRouteAnimation, @required Animation<double> outgoingRouteAnimation,
@required this.child, @required this.child,
// Perform incoming transition linearly. Use to precisely track back gesture drags.
bool linearTransition,
}) : }) :
incomingPositionAnimation = _kRightMiddleTween.animate( _incomingPositionAnimation = linearTransition
new CurvedAnimation( ? _kRightMiddleTween.animate(incomingRouteAnimation)
parent: incomingRouteAnimation, : _kRightMiddleTween.animate(
curve: Curves.easeOut, new CurvedAnimation(
reverseCurve: Curves.easeIn, parent: incomingRouteAnimation,
) curve: Curves.easeOut,
), reverseCurve: Curves.easeIn,
outgoingPositionAnimation = _kMiddleLeftTween.animate( )
),
_outgoingPositionAnimation = _kMiddleLeftTween.animate(
new CurvedAnimation( new CurvedAnimation(
parent: outgoingRouteAnimation, parent: outgoingRouteAnimation,
curve: Curves.easeOut, curve: Curves.easeOut,
...@@ -60,19 +64,20 @@ class CupertinoPageTransition extends AnimatedWidget { ...@@ -60,19 +64,20 @@ class CupertinoPageTransition extends AnimatedWidget {
); );
// When this page is coming in to cover another page. // When this page is coming in to cover another page.
final Animation<FractionalOffset> incomingPositionAnimation; final Animation<FractionalOffset> _incomingPositionAnimation;
// When this page is becoming covered by another page. // When this page is becoming covered by another page.
final Animation<FractionalOffset> outgoingPositionAnimation; final Animation<FractionalOffset> _outgoingPositionAnimation;
final Widget child; final Widget child;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// TODO(ianh): tell the transform to be un-transformed for hit testing // TODO(ianh): tell the transform to be un-transformed for hit testing
// but not while being controlled by a gesture. // but not while being controlled by a gesture.
return new SlideTransition( return new SlideTransition(
position: outgoingPositionAnimation, position: _outgoingPositionAnimation,
child: new SlideTransition( child: new SlideTransition(
position: incomingPositionAnimation, position: _incomingPositionAnimation,
child: new PhysicalModel( child: new PhysicalModel(
shape: BoxShape.rectangle, shape: BoxShape.rectangle,
color: _kBackgroundColor, color: _kBackgroundColor,
......
...@@ -176,6 +176,9 @@ class MaterialPageRoute<T> extends PageRoute<T> { ...@@ -176,6 +176,9 @@ class MaterialPageRoute<T> extends PageRoute<T> {
incomingRouteAnimation: animation, incomingRouteAnimation: animation,
outgoingRouteAnimation: forwardAnimation, outgoingRouteAnimation: forwardAnimation,
child: child, child: child,
// In the middle of a back gesture drag, let the transition be linear to match finger
// motions.
linearTransition: _backGestureController != null,
); );
} else { } else {
return new _MountainViewPageTransition( return new _MountainViewPageTransition(
......
...@@ -209,7 +209,7 @@ void main() { ...@@ -209,7 +209,7 @@ void main() {
// Drag from left edge to invoke the gesture. // Drag from left edge to invoke the gesture.
final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0)); final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0));
await gesture.moveBy(const Offset(400.0, 0.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 1'), findsNothing);
expect(find.text('Page 2'), isOnstage); expect(find.text('Page 2'), isOnstage);
...@@ -240,11 +240,24 @@ void main() { ...@@ -240,11 +240,24 @@ void main() {
// Drag from left edge to invoke the gesture. // Drag from left edge to invoke the gesture.
final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0)); final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0));
await gesture.moveBy(const Offset(400.0, 0.0)); await gesture.moveBy(const Offset(400.0, 0.0));
await tester.pumpAndSettle(); await tester.pump();
// Page 1 is now visible. // Page 1 is now visible.
expect(find.text('Page 1'), isOnstage); expect(find.text('Page 1'), isOnstage);
expect(find.text('Page 2'), 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 { testWidgets('test no back gesture on iOS fullscreen dialogs', (WidgetTester tester) async {
...@@ -269,7 +282,7 @@ void main() { ...@@ -269,7 +282,7 @@ void main() {
// Drag from left edge to invoke the gesture. // Drag from left edge to invoke the gesture.
final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0)); final TestGesture gesture = await tester.startGesture(const Point(5.0, 100.0));
await gesture.moveBy(const Offset(400.0, 0.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 1'), findsNothing);
expect(find.text('Page 2'), isOnstage); expect(find.text('Page 2'), isOnstage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment