Skip to content

Commit 3f2b7d9

Browse files
Do not block vertical drag gestures in CupertinoSheetRoute body (#161696)
Fixes #161623. Changes how the VerticalGestureRecognizer watches the sheet body. Before it stacked over the sheet and won all gesture arenas with vertical drags, so it didn't allow scrolling in the sheet. Now it has the sheet content as its child, so it will defer to child vertical gestures. This PR will allow scrolling to work in the sheet, but further work needs to be done to improve scrolling and drag to dismiss working together, see #161687. https://github.com/user-attachments/assets/71bee654-2d0d-499d-9d27-403188138fb5 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 90f926e commit 3f2b7d9

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

packages/flutter/lib/src/cupertino/sheet.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,10 @@ class _CupertinoDownGestureDetectorState<T> extends State<_CupertinoDownGestureD
669669

670670
@override
671671
Widget build(BuildContext context) {
672-
return Stack(
673-
fit: StackFit.passthrough,
674-
children: <Widget>[
675-
widget.child,
676-
Listener(onPointerDown: _handlePointerDown, behavior: HitTestBehavior.translucent),
677-
],
672+
return Listener(
673+
onPointerDown: _handlePointerDown,
674+
behavior: HitTestBehavior.translucent,
675+
child: widget.child,
678676
);
679677
}
680678
}

packages/flutter/test/cupertino/sheet_test.dart

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,5 +844,72 @@ void main() {
844844

845845
expect(find.text('Page 1'), findsOneWidget);
846846
});
847+
848+
testWidgets('Sheet should not block nested scroll', (WidgetTester tester) async {
849+
final GlobalKey homeKey = GlobalKey();
850+
851+
Widget sheetScaffoldContent(BuildContext context) {
852+
return ListView(
853+
children: const <Widget>[
854+
Text('Top of Scroll'),
855+
SizedBox(width: double.infinity, height: 100),
856+
Text('Middle of Scroll'),
857+
SizedBox(width: double.infinity, height: 100),
858+
],
859+
);
860+
}
861+
862+
await tester.pumpWidget(
863+
CupertinoApp(
864+
home: CupertinoPageScaffold(
865+
key: homeKey,
866+
child: Center(
867+
child: Column(
868+
children: <Widget>[
869+
const Text('Page 1'),
870+
CupertinoButton(
871+
onPressed: () {
872+
showCupertinoSheet<void>(
873+
context: homeKey.currentContext!,
874+
pageBuilder: (BuildContext context) {
875+
return CupertinoPageScaffold(child: sheetScaffoldContent(context));
876+
},
877+
);
878+
},
879+
child: const Text('Push Page 2'),
880+
),
881+
],
882+
),
883+
),
884+
),
885+
),
886+
);
887+
888+
await tester.tap(find.text('Push Page 2'));
889+
await tester.pumpAndSettle();
890+
891+
expect(find.text('Top of Scroll'), findsOneWidget);
892+
final double startPosition = tester.getTopLeft(find.text('Middle of Scroll')).dy;
893+
894+
final TestGesture gesture = await tester.createGesture();
895+
896+
await gesture.down(const Offset(100, 100));
897+
898+
// Need 2 events to form a valid drag.
899+
await tester.pump(const Duration(milliseconds: 100));
900+
await gesture.moveTo(const Offset(100, 80), timeStamp: const Duration(milliseconds: 100));
901+
await tester.pump(const Duration(milliseconds: 200));
902+
await gesture.moveTo(const Offset(100, 50), timeStamp: const Duration(milliseconds: 200));
903+
904+
await tester.pumpAndSettle();
905+
906+
final double endPosition = tester.getTopLeft(find.text('Middle of Scroll')).dy;
907+
908+
// Final position should be higher.
909+
expect(endPosition, lessThan(startPosition));
910+
911+
await gesture.up();
912+
await tester.pumpAndSettle();
913+
});
847914
});
848915
}

0 commit comments

Comments
 (0)