forked from firka/flutter
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
This commit is contained in:
@@ -36,15 +36,19 @@ class CupertinoPageTransition extends AnimatedWidget {
|
||||
// one.
|
||||
@required Animation<double> 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<FractionalOffset> incomingPositionAnimation;
|
||||
final Animation<FractionalOffset> _incomingPositionAnimation;
|
||||
// When this page is becoming covered by another page.
|
||||
final Animation<FractionalOffset> outgoingPositionAnimation;
|
||||
final Animation<FractionalOffset> _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,
|
||||
|
||||
@@ -176,6 +176,9 @@ class MaterialPageRoute<T> extends PageRoute<T> {
|
||||
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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user