Unverified Commit 4b20ce74 authored by xubaolin's avatar xubaolin Committed by GitHub

Fix a Scrollbar hittest penetration issue (#99328)

parent 7372ad17
...@@ -736,6 +736,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter { ...@@ -736,6 +736,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
if (ignorePointer) { if (ignorePointer) {
return false; return false;
} }
// The thumb is not able to be hit when transparent. // The thumb is not able to be hit when transparent.
if (fadeoutOpacityAnimation.value == 0.0) { if (fadeoutOpacityAnimation.value == 0.0) {
return false; return false;
...@@ -745,7 +746,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter { ...@@ -745,7 +746,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
return false; return false;
} }
return _thumbRect!.contains(position!); return _trackRect!.contains(position!);
} }
@override @override
......
...@@ -1345,6 +1345,55 @@ void main() { ...@@ -1345,6 +1345,55 @@ void main() {
); );
}); });
testWidgets('hit test', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/99324
final ScrollController scrollController = ScrollController();
bool onTap = false;
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(),
child: PrimaryScrollController(
controller: scrollController,
child: RawScrollbar(
trackVisibility: true,
thumbVisibility: true,
controller: scrollController,
child: SingleChildScrollView(
child: GestureDetector(
onTap: () => onTap = true,
child: const SizedBox(
width: 4000.0,
height: 4000.0,
child: ColoredBox(color: Color(0x00000000)),
),
),
),
),
),
),
),
);
await tester.pumpAndSettle();
expect(onTap, false);
// Tap on track area.
await tester.tapAt(const Offset(795.0, 550.0));
await tester.pumpAndSettle();
expect(onTap, false);
// Tap on thumb area.
await tester.tapAt(const Offset(795.0, 10.0));
await tester.pumpAndSettle();
expect(onTap, false);
// Tap on content area.
await tester.tapAt(const Offset(400.0, 300.0));
await tester.pumpAndSettle();
expect(onTap, true);
});
testWidgets('RawScrollbar.thumbVisibility asserts that a ScrollPosition is attached', (WidgetTester tester) async { testWidgets('RawScrollbar.thumbVisibility asserts that a ScrollPosition is attached', (WidgetTester tester) async {
final FlutterExceptionHandler? handler = FlutterError.onError; final FlutterExceptionHandler? handler = FlutterError.onError;
FlutterErrorDetails? error; FlutterErrorDetails? error;
......
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