Commit dc5e1bba authored by Matt Perry's avatar Matt Perry Committed by GitHub

Disallow back gestures during a page transition. (#5982)

Fixes https://github.com/flutter/flutter/issues/5973
parent 20d554c1
......@@ -202,6 +202,8 @@ class MaterialPageRoute<T> extends PageRoute<T> {
@override
NavigationGestureController startPopGesture(NavigatorState navigator) {
if (controller.status != AnimationStatus.completed)
return null;
assert(_backGestureController == null);
_backGestureController = new _CupertinoBackGestureController(
navigator: navigator,
......
......@@ -286,4 +286,50 @@ void main() {
expect(settingsOffset.x, greaterThan(100.0));
expect(settingsOffset.y, 100.0);
});
testWidgets('Check back gesture doesnt start during transitions', (WidgetTester tester) async {
GlobalKey containerKey1 = new GlobalKey();
GlobalKey containerKey2 = new GlobalKey();
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (_) => new Scaffold(key: containerKey1, body: new Text('Home')),
'/settings': (_) => new Scaffold(key: containerKey2, body: new Text('Settings')),
};
await tester.pumpWidget(new MaterialApp(
routes: routes,
theme: new ThemeData(platform: TargetPlatform.iOS),
));
Navigator.pushNamed(containerKey1.currentContext, '/settings');
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
// We are mid-transition, both pages are on stage.
expect(find.text('Home'), isOnstage);
expect(find.text('Settings'), isOnstage);
// Drag from left edge to invoke the gesture. (near bottom so we grab
// the Settings page as it comes up).
TestGesture gesture = await tester.startGesture(new Point(5.0, 550.0));
await gesture.moveBy(new Offset(500.0, 0.0));
await gesture.up();
await tester.pump();
await tester.pump(const Duration(milliseconds: 1000));
// The original forward navigation should have completed, instead of the
// back gesture, since we were mid transition.
expect(find.text('Home'), findsNothing);
expect(find.text('Settings'), isOnstage);
// Try again now that we're settled.
gesture = await tester.startGesture(new Point(5.0, 550.0));
await gesture.moveBy(new Offset(500.0, 0.0));
await gesture.up();
await tester.pump();
await tester.pump(const Duration(milliseconds: 1000));
expect(find.text('Home'), isOnstage);
expect(find.text('Settings'), findsNothing);
});
}
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