scroll view patch

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-04-20 11:59:31 +08:00
parent 44b7cced09
commit bffdfae1f6
2 changed files with 81 additions and 1 deletions

View File

@@ -11,9 +11,13 @@ $ToolTipFix = "56956c33ef102ac0b5fc46b62bd2dd9f50a86616";
$NewOverScrollIndicator = "362b1de29974ffc1ed6faa826e1df870d7bec75f";
$BottomSheetPatch = "lib/scripts/bottom_sheet.patch"
$ScrollViewPatch = "lib/scripts/scroll_view.patch"
# TODO: remove
# https://github.com/flutter/flutter/issues/90223
$ModalBarrierPatch = "lib/scripts/modal_barrier.patch"
# TODO: remove
# https://github.com/flutter/flutter/issues/182466
$MouseCursorPatch = "lib/scripts/mouse_cursor.patch"
@@ -28,8 +32,11 @@ switch ($platform.ToLower()) {
"android" {
$reverts += $NewOverScrollIndicator
$patches += $BottomSheetPatch
$patches += $ScrollViewPatch
}
"ios" {
$patches += $ScrollViewPatch
}
"ios" {}
"linux" {
$picks += $ToolTipFix
}

View File

@@ -0,0 +1,73 @@
diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart
index ac854f7de8f..fdeba1a88f5 100644
--- a/packages/flutter/lib/src/widgets/scrollable.dart
+++ b/packages/flutter/lib/src/widgets/scrollable.dart
@@ -786,11 +786,13 @@ class ScrollableState extends State<Scrollable>
switch (widget.axis) {
case Axis.vertical:
_gestureRecognizers = <Type, GestureRecognizerFactory>{
- VerticalDragGestureRecognizer:
- GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>(
- () => VerticalDragGestureRecognizer(supportedDevices: _configuration.dragDevices),
- (VerticalDragGestureRecognizer instance) {
+ _VerticalDragGestureRecognizer:
+ GestureRecognizerFactoryWithHandlers<_VerticalDragGestureRecognizer>(
+ () =>
+ _VerticalDragGestureRecognizer(supportedDevices: _configuration.dragDevices),
+ (_VerticalDragGestureRecognizer instance) {
instance
+ ..isDyAllowed = _isDyAllowed
..onDown = _handleDragDown
..onStart = _handleDragStart
..onUpdate = _handleDragUpdate
@@ -859,6 +861,10 @@ class ScrollableState extends State<Scrollable>
Drag? _drag;
ScrollHoldController? _hold;
+ bool _isDyAllowed(double dy) {
+ return position.viewportDimension - dy > 30;
+ }
+
void _handleDragDown(DragDownDetails details) {
assert(_drag == null);
assert(_hold == null);
@@ -2553,3 +2559,39 @@ class _HorizontalInnerDimensionState extends ScrollableState {
return _configuration.buildOverscrollIndicator(context, child, details);
}
}
+
+typedef IsDyAllowed = bool Function(double dy);
+
+class _VerticalDragGestureRecognizer extends VerticalDragGestureRecognizer {
+ _VerticalDragGestureRecognizer({
+ super.debugOwner,
+ super.supportedDevices,
+ super.allowedButtonsFilter,
+ });
+
+ IsDyAllowed? isDyAllowed;
+
+ bool _isDyAllowed = true;
+
+ @override
+ bool isPointerAllowed(PointerEvent event) {
+ _isDyAllowed = isDyAllowed?.call(event.localPosition.dy) ?? true;
+ return super.isPointerAllowed(event);
+ }
+
+ @override
+ T? invokeCallback<T>(
+ String name,
+ RecognizerCallback<T> callback, {
+ String Function()? debugReport,
+ }) {
+ if (!_isDyAllowed) return null;
+ return super.invokeCallback(name, callback, debugReport: debugReport);
+ }
+
+ @override
+ void dispose() {
+ isDyAllowed = null;
+ super.dispose();
+ }
+}