Skip to content

Commit

Permalink
Fix a Scrollbar hittest penetration issue (#99328)
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-baolin authored Mar 2, 2022
1 parent 7372ad1 commit 4b20ce7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/flutter/lib/src/widgets/scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
if (ignorePointer) {
return false;
}

// The thumb is not able to be hit when transparent.
if (fadeoutOpacityAnimation.value == 0.0) {
return false;
Expand All @@ -745,7 +746,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
return false;
}

return _thumbRect!.contains(position!);
return _trackRect!.contains(position!);
}

@override
Expand Down
49 changes: 49 additions & 0 deletions packages/flutter/test/widgets/scrollbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
final FlutterExceptionHandler? handler = FlutterError.onError;
FlutterErrorDetails? error;
Expand Down

0 comments on commit 4b20ce7

Please sign in to comment.