Skip to content

Commit

Permalink
fix(bosskmk#214): allow drag with scrollbar thumb.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcb33 authored and bosskmk committed Jun 26, 2021
1 parent d1d952d commit 0592b6a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/src/widgets/pluto_scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class PlutoScrollbar extends StatefulWidget {

final Radius radius;

final bool onlyDraggingThumb = true;

final Radius radiusWhileDragging;

@override
Expand Down Expand Up @@ -376,6 +378,7 @@ class _CupertinoScrollbarState extends State<PlutoScrollbar>
() => _ThumbPressGestureRecognizer(
debugOwner: this,
customPaintKey: _customPaintKey,
onlyDraggingThumb: widget.onlyDraggingThumb,
),
(_ThumbPressGestureRecognizer instance) {
instance
Expand Down Expand Up @@ -424,6 +427,7 @@ class _ThumbPressGestureRecognizer extends LongPressGestureRecognizer {
PointerDeviceKind? kind,
required Object debugOwner,
required GlobalKey customPaintKey,
this.onlyDraggingThumb = false,
}) : _customPaintKey = customPaintKey,
super(
postAcceptSlopTolerance: postAcceptSlopTolerance,
Expand All @@ -433,10 +437,12 @@ class _ThumbPressGestureRecognizer extends LongPressGestureRecognizer {
);

final GlobalKey _customPaintKey;
final bool onlyDraggingThumb;

@override
bool isPointerAllowed(PointerDownEvent event) {
if (!_hitTestInteractive(_customPaintKey, event.position, event.kind)) {
if (!_hitTestInteractive(
_customPaintKey, event.position, event.kind, onlyDraggingThumb)) {
return false;
}
return super.isPointerAllowed(event);
Expand All @@ -446,8 +452,8 @@ class _ThumbPressGestureRecognizer extends LongPressGestureRecognizer {
// foregroundPainter also hit tests its children by default, but the
// scrollbar should only respond to a gesture directly on its thumb, so
// manually check for a hit on the thumb here.
bool _hitTestInteractive(
GlobalKey customPaintKey, Offset offset, PointerDeviceKind kind) {
bool _hitTestInteractive(GlobalKey customPaintKey, Offset offset,
PointerDeviceKind kind, bool onlyDraggingThumb) {
if (customPaintKey.currentContext == null) {
return false;
}
Expand All @@ -456,9 +462,10 @@ bool _hitTestInteractive(
final ScrollbarPainter painter =
customPaint.foregroundPainter! as ScrollbarPainter;
final Offset localOffset = _getLocalOffset(customPaintKey, offset);
// We only receive track taps that are not on the thumb.
return painter.hitTestInteractive(localOffset, kind) &&
!painter.hitTestOnlyThumbInteractive(localOffset, kind);
// We can only receive track taps that are on the thumb.
return onlyDraggingThumb
? painter.hitTestOnlyThumbInteractive(localOffset, kind)
: painter.hitTestInteractive(localOffset, kind);
}

Offset _getLocalOffset(GlobalKey scrollbarPainterKey, Offset position) {
Expand Down

0 comments on commit 0592b6a

Please sign in to comment.