From 1a87d4b82c89766720903a88016a25faad428e86 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Tue, 30 Aug 2016 16:17:31 -0400 Subject: [PATCH] Disable back gesture behind a flag until it's ready. (#5646) Also added a regression test for the back gesture on iOS and android. --- .../flutter/lib/src/material/scaffold.dart | 7 ++- .../test/widget/page_transitions_test.dart | 61 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 603c87d739..35d962ed32 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -22,6 +22,9 @@ const double _kFloatingActionButtonMargin = 16.0; // TODO(hmuller): should be de const Duration _kFloatingActionButtonSegue = const Duration(milliseconds: 200); final Tween _kFloatingActionButtonTurnTween = new Tween(begin: -0.125, end: 0.0); +// iOS back gesture is in development. This flag will go away when it's ready +// to ship. +const bool _kBackGestureEnabled = false; const double _kBackGestureWidth = 20.0; /// The Scaffold's appbar is the toolbar, bottom, and the "flexible space" @@ -697,7 +700,9 @@ class ScaffoldState extends State { NavigationGestureController _backGestureController; bool _shouldHandleBackGesture() { - return Theme.of(context).platform == TargetPlatform.iOS && Navigator.canPop(context); + return _kBackGestureEnabled && + Theme.of(context).platform == TargetPlatform.iOS && + Navigator.canPop(context); } void _handleDragStart(DragStartDetails details) { diff --git a/packages/flutter/test/widget/page_transitions_test.dart b/packages/flutter/test/widget/page_transitions_test.dart index 7da2b51698..474aec5793 100644 --- a/packages/flutter/test/widget/page_transitions_test.dart +++ b/packages/flutter/test/widget/page_transitions_test.dart @@ -93,6 +93,67 @@ void main() { expect(find.text('Overlay'), findsNothing); expect(Navigator.canPop(containerKey1.currentContext), isFalse); + }); + testWidgets('Check back gesture works on iOS', (WidgetTester tester) async { + GlobalKey containerKey1 = new GlobalKey(); + GlobalKey containerKey2 = new GlobalKey(); + final Map routes = { + '/': (_) => 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(seconds: 1)); + + expect(find.text('Home'), findsNothing); + expect(find.text('Settings'), isOnstage); + + // Drag from left edge to invoke the gesture. + TestGesture gesture = await tester.startGesture(new Point(5.0, 100.0)); + await gesture.moveBy(new Offset(50.0, 0.0)); + await tester.pump(); + + // TODO(mpcomplete): back gesture disabled. Home should be onstage when + // it is reenabled. + expect(find.text('Home'), findsNothing); + expect(find.text('Settings'), isOnstage); + }); + + testWidgets('Check back gesture does nothing on android', (WidgetTester tester) async { + GlobalKey containerKey1 = new GlobalKey(); + GlobalKey containerKey2 = new GlobalKey(); + final Map routes = { + '/': (_) => 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.android), + )); + + Navigator.pushNamed(containerKey1.currentContext, '/settings'); + + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + + expect(find.text('Home'), findsNothing); + expect(find.text('Settings'), isOnstage); + + // Drag from left edge to invoke the gesture. + TestGesture gesture = await tester.startGesture(new Point(5.0, 100.0)); + await gesture.moveBy(new Offset(50.0, 0.0)); + await tester.pump(); + + expect(find.text('Home'), findsNothing); + expect(find.text('Settings'), isOnstage); }); }