Unverified Commit 4c0b0be2 authored by Will Lockwood's avatar Will Lockwood Committed by GitHub

Add ability for `ModalRoutes` to ignore pointers during transitions and do so...

Add ability for `ModalRoutes` to ignore pointers during transitions and do so on `Cupertino` routes (#95757)
parent 0052566c
......@@ -235,6 +235,9 @@ mixin CupertinoRouteTransitionMixin<T> on PageRoute<T> {
return result;
}
@override
bool get ignorePointerDuringTransitions => true;
// Called by _CupertinoBackGestureDetector when a pop ("back") drag start
// gesture is detected. The returned controller handles all of the subsequent
// drag events.
......@@ -1049,6 +1052,9 @@ class CupertinoModalPopupRoute<T> extends PopupRoute<T> {
@override
Duration get transitionDuration => _kModalPopupTransitionDuration;
@override
bool get ignorePointerDuringTransitions => true;
Animation<double>? _animation;
late Tween<Offset> _offsetTween;
......@@ -1349,4 +1355,7 @@ class CupertinoDialogRoute<T> extends RawDialogRoute<T> {
barrierLabel: barrierLabel ?? CupertinoLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: barrierColor ?? CupertinoDynamicColor.resolve(kCupertinoModalBarrierColor, context),
);
@override
bool get ignorePointerDuringTransitions => true;
}
......@@ -29,13 +29,13 @@ void main() {
);
await tester.tap(find.text('Go'));
await tester.pump();
await tester.pumpAndSettle();
expect(find.text('Action Sheet'), findsOneWidget);
expect(find.byType(CupertinoActionSheet), findsOneWidget);
await tester.tapAt(const Offset(20.0, 20.0));
await tester.pump();
expect(find.text('Action Sheet'), findsNothing);
await tester.tap(find.byType(ModalBarrier).last);
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsNothing);
});
testWidgets('Verify that a tap on title section (not buttons) does not dismiss an action sheet', (WidgetTester tester) async {
......@@ -867,7 +867,7 @@ void main() {
expect(find.byType(CupertinoActionSheet), findsNothing);
});
testWidgets('Modal barrier is pressed during transition', (WidgetTester tester) async {
testWidgets('Modal barrier cannot be dismissed during transition', (WidgetTester tester) async {
await tester.pumpWidget(
createAppWithButtonThatLaunchesActionSheet(
CupertinoActionSheet(
......@@ -906,21 +906,20 @@ void main() {
await tester.pump(const Duration(milliseconds: 60));
expect(tester.getTopLeft(find.byType(CupertinoActionSheet)).dy, moreOrLessEquals(337.1, epsilon: 0.1));
// Exit animation
// Attempt to dismiss
await tester.tapAt(const Offset(20.0, 20.0));
await tester.pump(const Duration(milliseconds: 60));
await tester.pump(const Duration(milliseconds: 60));
expect(tester.getTopLeft(find.byType(CupertinoActionSheet)).dy, moreOrLessEquals(374.3, epsilon: 0.1));
// Enter animation is continuing
expect(tester.getTopLeft(find.byType(CupertinoActionSheet)).dy, moreOrLessEquals(325.4, epsilon: 0.1));
await tester.pump(const Duration(milliseconds: 60));
expect(tester.getTopLeft(find.byType(CupertinoActionSheet)).dy, moreOrLessEquals(470.0, epsilon: 0.1));
await tester.pumpAndSettle();
await tester.pump(const Duration(milliseconds: 60));
expect(tester.getTopLeft(find.byType(CupertinoActionSheet)).dy, 600.0);
// Attempt to dismiss again
await tester.tapAt(const Offset(20.0, 20.0));
await tester.pumpAndSettle();
// Action sheet has disappeared
await tester.pump(const Duration(milliseconds: 60));
expect(find.byType(CupertinoActionSheet), findsNothing);
});
......@@ -952,7 +951,7 @@ void main() {
);
await tester.tap(find.text('Go'));
await tester.pump();
await tester.pumpAndSettle();
expect(
semantics,
......
......@@ -1074,6 +1074,8 @@ void main() {
transition = tester.firstWidget(fadeTransitionFinder);
expect(transition.opacity.value, moreOrLessEquals(1.0, epsilon: 0.001));
await tester.pumpAndSettle();
await tester.tap(find.text('Delete'));
// Exit animation, look at reverse FadeTransition.
......
......@@ -442,6 +442,8 @@ void main() {
await tester.pump(const Duration(milliseconds: 40));
expect(tester.getTopLeft(find.byType(Placeholder)).dy, moreOrLessEquals(0.0, epsilon: 0.1));
await tester.pumpAndSettle();
// Exit animation
await tester.tap(find.text('Close'));
await tester.pump();
......@@ -547,6 +549,8 @@ void main() {
await tester.pump(const Duration(milliseconds: 40));
expect(tester.getTopLeft(find.byType(Placeholder)).dx, moreOrLessEquals(-267.0, epsilon: 1.0));
await tester.pumpAndSettle();
// Exit animation
await tester.tap(find.text('Close'));
await tester.pump();
......@@ -636,6 +640,8 @@ void main() {
await tester.pump(const Duration(milliseconds: 40));
expect(tester.getTopLeft(find.byType(Placeholder)).dx, 0.0);
await tester.pumpAndSettle();
// Exit animation
await tester.tap(find.text('Close'));
await tester.pump();
......@@ -655,6 +661,221 @@ void main() {
await testNoParallax(tester, fromFullscreenDialog: true);
});
group('Route interactivity during transition animations', () {
testWidgets('CupertinoPageRoute ignores pointers when route on top of it pops', (WidgetTester tester) async {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
bool homeTapped = false;
await tester.pumpWidget(
CupertinoApp(
navigatorKey: navigatorKey,
home: TextButton(
onPressed: () => homeTapped = true,
child: const Text('Home'),
),
),
);
navigatorKey.currentState!.push<void>(
CupertinoPageRoute<void>(
builder: (_) => const Text('Page 2'),
)
);
await tester.pumpAndSettle();
expect(find.text('Page 2'), findsOneWidget);
navigatorKey.currentState!.pop();
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Page 2'), findsOneWidget); // Transition still in progress
await tester.tap(find.text('Home'), warnIfMissed: false); // Home route is not tappable
expect(homeTapped, false);
await tester.pumpAndSettle(); // Transition completes
await tester.tap(find.text('Home'));
expect(homeTapped, true);
});
testWidgets('fullscreenDialog CupertinoPageRoute ignores pointers when route on top of it pops', (WidgetTester tester) async {
bool homeTapped = false;
await tester.pumpWidget(
CupertinoApp(
home: TextButton(
onPressed: () => homeTapped = true,
child: const Text('Home'),
),
),
);
tester.state<NavigatorState>(find.byType(Navigator)).push<void>(
CupertinoPageRoute<void>(
fullscreenDialog: true,
builder: (_) => const Text('Page 2'),
)
);
await tester.pumpAndSettle();
expect(find.text('Page 2'), findsOneWidget);
tester.state<NavigatorState>(find.byType(Navigator)).pop();
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Page 2'), findsOneWidget); // Transition still in progress
await tester.tap(find.text('Home'), warnIfMissed: false); // Home route is not tappable
expect(homeTapped, false);
await tester.pumpAndSettle(); // Transition completes
await tester.tap(find.text('Home'));
expect(homeTapped, true);
});
testWidgets('CupertinoPageRoute ignores pointers when user pop gesture is in progress', (WidgetTester tester) async {
bool homeTapped = false;
await tester.pumpWidget(
CupertinoApp(
home: TextButton(
onPressed: () => homeTapped = true,
child: const Text('Page 1'),
),
),
);
tester.state<NavigatorState>(find.byType(Navigator)).push(
CupertinoPageRoute<void>(
builder: (_) => const Text('Page 2'),
),
);
await tester.pumpAndSettle();
expect(find.text('Page 1'), findsNothing);
final TestGesture swipeGesture = await tester.startGesture(const Offset(5, 100));
await swipeGesture.moveBy(const Offset(100, 0));
await tester.pump();
expect(find.text('Page 1'), findsOneWidget);
expect(tester.state<NavigatorState>(find.byType(Navigator)).userGestureInProgress, true);
await tester.tap(find.text('Page 1'), warnIfMissed: false);
expect(homeTapped, false);
});
testWidgets('CupertinoPageRoute ignores pointers when it is pushed on top of other route', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
onGenerateRoute: (_) => CupertinoPageRoute<void>(
builder: (_) => const Text('Home'),
),
),
);
await tester.tap(find.text('Home'));
tester.state<NavigatorState>(find.byType(Navigator)).push(
CupertinoPageRoute<void>(
builder: (_) => const Text('Page 2'),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Home'), findsOneWidget); // Transition still in progress
// Can't test directly for taps because route is interactive but offstage
// One ignore pointer for each of two overlay entries (ModalScope, ModalBarrier) on each of two routes
expect(find.byType(IgnorePointer, skipOffstage: false), findsNWidgets(4));
final List<Element> ignorePointers = find.byType(IgnorePointer, skipOffstage: false).evaluate().toList();
expect((ignorePointers.first.widget as IgnorePointer).ignoring, true); // Home modalBarrier
expect((ignorePointers[1].widget as IgnorePointer).ignoring, true); // Home modalScope
expect((ignorePointers[2].widget as IgnorePointer).ignoring, true); // Page 2 modalBarrier
expect((ignorePointers.last.widget as IgnorePointer).ignoring, true); // Page 2 modalScope
});
testWidgets('showCupertinoDialog ignores pointers until transition completes', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
home: Builder(
builder: (BuildContext context) {
return TextButton(
onPressed: () {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext innerContext) => TextButton(
onPressed: Navigator.of(innerContext).pop,
child: const Text('dialog'),
),
);
},
child: const Text('Show Dialog'),
);
},
),
),
);
// Open the dialog.
await tester.tap(find.byType(TextButton));
await tester.pump(const Duration(milliseconds: 100));
// Trigger pop while the transition is in progress
await tester.tap(find.text('dialog'), warnIfMissed: false);
await tester.pumpAndSettle();
// Transition is over and the dialog has not been dismissed
expect(find.text('dialog'), findsOneWidget);
await tester.tap(find.text('dialog'));
await tester.pumpAndSettle();
// The dialog has not been dismissed
expect(find.text('dialog'), findsNothing);
});
testWidgets('showCupertinoModalPopup ignores pointers until transition completes', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
home: Builder(
builder: (BuildContext context) {
return TextButton(
onPressed: () {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext innerContext) => TextButton(
onPressed: Navigator.of(innerContext).pop,
child: const Text('modal'),
),
);
},
child: const Text('Show modal'),
);
},
),
),
);
// Open the modal popup
await tester.tap(find.byType(TextButton));
await tester.pump(const Duration(milliseconds: 100));
// Trigger pop while the transition is in progress
await tester.tap(find.text('modal'), warnIfMissed: false);
await tester.pumpAndSettle();
// Transition is over and the dialog has not been dismissed
expect(find.text('modal'), findsOneWidget);
await tester.tap(find.text('modal'));
await tester.pumpAndSettle();
// The dialog has not been dismissed
expect(find.text('modal'), findsNothing);
});
});
testWidgets('Animated push/pop is not linear', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
......
......@@ -432,6 +432,7 @@ void main() {
routes: routes,
),
);
expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 2);
await tester.tap(find.text('PUSH'));
expect(await tester.pumpAndSettle(const Duration(minutes: 1)), 2);
expect(find.text('PUSH'), findsNothing);
......@@ -790,8 +791,8 @@ void main() {
// Tapping the "page" route's back button doesn't do anything either.
await tester.tap(find.byTooltip('Back'), warnIfMissed: false);
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.byKey(pageScaffoldKey)), const Offset(400, 0));
await tester.pump();
expect(tester.getTopLeft(find.byKey(pageScaffoldKey, skipOffstage: false)), const Offset(400, 0));
expect(tester.getTopLeft(find.byKey(homeScaffoldKey)).dx, lessThan(0));
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
......
......@@ -940,6 +940,36 @@ void main() {
expect(trainHopper2.currentTrain, isNull); // Has been disposed.
});
testWidgets('secondary animation is AnimationMin when transition route that cannot be transitioned to or from pops', (WidgetTester tester) async {
final PageRoute<void> pageRouteOne = MaterialPageRoute<void>(
builder: (_) => const Text('Page One'),
);
await tester.pumpWidget(
MaterialApp(
onGenerateRoute: (_) => pageRouteOne,
),
);
final PageRoute<void> pageRouteTwo = MaterialPageRoute<void>(
fullscreenDialog: true,
builder: (_) => const Text('Page Two'),
);
tester.state<NavigatorState>(find.byType(Navigator)).push(pageRouteTwo);
await tester.pumpAndSettle();
tester.state<NavigatorState>(find.byType(Navigator)).pop();
await tester.pump();
expect(
((pageRouteOne.secondaryAnimation! as ProxyAnimation).parent! as ProxyAnimation).parent,
isA<AnimationMin<double>>()
..having((AnimationMin<double> a) => a.first, 'first', equals(kAlwaysDismissedAnimation))
..having((AnimationMin<double> a) => a.next, 'first', equals(pageRouteTwo.animation)),
);
});
testWidgets('secondary animation is triggered when pop initial route', (WidgetTester tester) async {
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
late Animation<double> secondaryAnimationOfRouteOne;
......@@ -1011,6 +1041,41 @@ void main() {
expect(find.byType(ModalBarrier), findsNWidgets(1));
});
testWidgets('showGeneralDialog ModalBarrier does not ignore pointers during transitions', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (BuildContext context) {
return TextButton(
onPressed: () {
showGeneralDialog<void>(
context: context,
transitionDuration: const Duration(milliseconds: 400),
pageBuilder: (BuildContext innerContext, __, ___) => TextButton(
onPressed: Navigator.of(innerContext).pop,
child: const Text('dialog'),
),
);
},
child: const Text('Show Dialog'),
);
},
),
),
);
// Open the dialog.
await tester.tap(find.byType(TextButton));
await tester.pump(const Duration(milliseconds: 200));
// Trigger pop while the transition is in progress
await tester.tap(find.text('dialog'));
await tester.pumpAndSettle();
// The dialog has been dismissed mid-transition
expect(find.text('dialog'), findsNothing);
});
testWidgets('showGeneralDialog adds non-dismissible barrier when barrierDismissible is false', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Builder(
......@@ -1306,6 +1371,67 @@ void main() {
});
});
testWidgets('does not ignore pointers when route on top of it pops', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
// Use a transitions builder that will keep the underlying content
// partially visible during a transition
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
},
)
),
home: const Text('Home'),
),
);
tester.state<NavigatorState>(find.byType(Navigator)).push<void>(
MaterialPageRoute<void>(builder: (_) => const Text('Page 2'))
);
await tester.pumpAndSettle();
expect(find.text('Page 2'), findsOneWidget);
tester.state<NavigatorState>(find.byType(Navigator)).pop();
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Page 2'), findsOneWidget); // Transition still in progress
await tester.tap(find.text('Home')); // Home route is tappable
});
testWidgets('does not ignore pointers during its own entrance animation', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
onGenerateRoute: (_) => MaterialPageRoute<void>(
builder: (_) => const Text('Home'),
),
),
);
await tester.tap(find.text('Home'));
tester.state<NavigatorState>(find.byType(Navigator)).push(
MaterialPageRoute<void>(
builder: (_) => const Text('Page 2'),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Home'), findsOneWidget); // Transition still in progress
// Can't test directly for taps because route is interactive but offstage
// One ignore pointer for each of two overlay entries (ModalScope, ModalBarrier) on each of two routes
expect(find.byType(IgnorePointer, skipOffstage: false), findsNWidgets(4));
final List<Element> ignorePointers = find.byType(IgnorePointer, skipOffstage: false).evaluate().toList();
expect((ignorePointers.first.widget as IgnorePointer).ignoring, true); // Home modalBarrier
expect((ignorePointers[1].widget as IgnorePointer).ignoring, true); // Home modalScope
expect((ignorePointers[2].widget as IgnorePointer).ignoring, false); // Page 2 modalBarrier
expect((ignorePointers.last.widget as IgnorePointer).ignoring, false); // Page 2 modalScope
});
testWidgets('reverseTransitionDuration defaults to transitionDuration', (WidgetTester tester) async {
final GlobalKey containerKey = GlobalKey();
......
......@@ -440,7 +440,7 @@ void main() {
await tester.tap(find.text('Next'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pumpAndSettle();
await tester.pageBack();
await tester.pump();
......
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