Unverified Commit 568eef34 authored by chunhtai's avatar chunhtai Committed by GitHub

Revert "Dismiss Modal Barrier on `handleTapCancel` (#98191)" (#100784)

This reverts commit 58ad6e1b.
parent 9d0570a5
......@@ -47,8 +47,7 @@ class ModalBarrier extends StatelessWidget {
/// [ModalBarrier] built by [ModalRoute] pages.
final Color? color;
/// Specifies if the barrier will be dismissed when the user taps or
/// performs a scroll gesture on it.
/// Specifies if the barrier will be dismissed when the user taps on it.
///
/// If true, and [onDismiss] is non-null, [onDismiss] will be called,
/// otherwise the current route will be popped from the ambient [Navigator].
......@@ -229,14 +228,12 @@ class _AnyTapGestureRecognizer extends BaseTapGestureRecognizer {
: super(debugOwner: debugOwner);
VoidCallback? onAnyTapUp;
VoidCallback? onAnyTapCancel;
@protected
@override
bool isPointerAllowed(PointerDownEvent event) {
if (onAnyTapUp == null && onAnyTapCancel == null) {
if (onAnyTapUp == null)
return false;
}
return super.isPointerAllowed(event);
}
......@@ -255,7 +252,7 @@ class _AnyTapGestureRecognizer extends BaseTapGestureRecognizer {
@protected
@override
void handleTapCancel({PointerDownEvent? down, PointerCancelEvent? cancel, String? reason}) {
onAnyTapCancel?.call();
// Do nothing.
}
@override
......@@ -275,10 +272,9 @@ class _ModalBarrierSemanticsDelegate extends SemanticsGestureDelegate {
class _AnyTapGestureRecognizerFactory extends GestureRecognizerFactory<_AnyTapGestureRecognizer> {
const _AnyTapGestureRecognizerFactory({this.onAnyTapUp, this.onAnyTapCancel});
const _AnyTapGestureRecognizerFactory({this.onAnyTapUp});
final VoidCallback? onAnyTapUp;
final VoidCallback? onAnyTapCancel;
@override
_AnyTapGestureRecognizer constructor() => _AnyTapGestureRecognizer();
......@@ -286,7 +282,6 @@ class _AnyTapGestureRecognizerFactory extends GestureRecognizerFactory<_AnyTapGe
@override
void initializer(_AnyTapGestureRecognizer instance) {
instance.onAnyTapUp = onAnyTapUp;
instance.onAnyTapCancel = onAnyTapCancel;
}
}
......@@ -312,7 +307,7 @@ class _ModalBarrierGestureDetector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Map<Type, GestureRecognizerFactory> gestures = <Type, GestureRecognizerFactory>{
_AnyTapGestureRecognizer: _AnyTapGestureRecognizerFactory(onAnyTapUp: onDismiss, onAnyTapCancel: onDismiss),
_AnyTapGestureRecognizer: _AnyTapGestureRecognizerFactory(onAnyTapUp: onDismiss),
};
return RawGestureDetector(
......
......@@ -251,39 +251,6 @@ void main() {
);
});
testWidgets('ModalBarrier pops the Navigator when dismissed by tap cancel', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => const FirstWidget(),
'/modal': (BuildContext context) => const SecondWidget(),
};
await tester.pumpWidget(MaterialApp(routes: routes));
// Initially the barrier is not visible
expect(find.byKey(const ValueKey<String>('barrier')), findsNothing);
// Tapping on X routes to the barrier
await tester.tap(find.text('X'));
await tester.pump(); // begin transition
await tester.pump(const Duration(seconds: 1)); // end transition
// Press the barrier; it shouldn't dismiss yet
final TestGesture gesture = await tester.press(
find.byKey(const ValueKey<String>('barrier')),
);
await tester.pumpAndSettle(); // begin transition
expect(find.byKey(const ValueKey<String>('barrier')), findsOneWidget);
// Cancel the pointer; the barrier should be dismissed
await gesture.cancel();
await tester.pumpAndSettle(const Duration(seconds: 1)); // end transition
expect(
find.byKey(const ValueKey<String>('barrier')),
findsNothing,
reason: 'The route should have been dismissed by tapping the barrier.',
);
});
testWidgets('ModalBarrier may pop the Navigator when competing with other gestures', (WidgetTester tester) async {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (BuildContext context) => const FirstWidget(),
......
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