Skip to content

Commit

Permalink
Add Scrollbar properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
bosskmk committed Mar 7, 2023
1 parent 03b0c2e commit 2d38ed7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
16 changes: 16 additions & 0 deletions lib/src/pluto_grid_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ class PlutoGridScrollbarConfig {
this.draggableScrollbar = true,
this.isAlwaysShown = false,
this.onlyDraggingThumb = true,
this.enableScrollAfterDragEnd = true,
this.scrollbarThickness = PlutoScrollbar.defaultThickness,
this.scrollbarThicknessWhileDragging =
PlutoScrollbar.defaultThicknessWhileDragging,
Expand All @@ -671,6 +672,7 @@ class PlutoGridScrollbarConfig {
this.scrollbarRadius = PlutoScrollbar.defaultRadius,
this.scrollbarRadiusWhileDragging =
PlutoScrollbar.defaultRadiusWhileDragging,
this.longPressDuration,
this.dragDevices,
});

Expand All @@ -681,6 +683,13 @@ class PlutoGridScrollbarConfig {
/// If [onlyDraggingThumb] is false, scrolling can be done by dragging the track area.
final bool onlyDraggingThumb;

/// If you release the scroll bar after scrolling,
/// the scroll bar moves further according to the moving speed.
///
/// If set to false,
/// the scroll bar will stop moving as soon as the scroll bar is released.
final bool enableScrollAfterDragEnd;

final double scrollbarThickness;

final double scrollbarThicknessWhileDragging;
Expand All @@ -701,6 +710,9 @@ class PlutoGridScrollbarConfig {

final Radius scrollbarRadiusWhileDragging;

/// Set the long press time of the scroll bar. 100 ms if not set.
final Duration? longPressDuration;

final Set<PointerDeviceKind>? dragDevices;

@override
Expand All @@ -711,6 +723,7 @@ class PlutoGridScrollbarConfig {
draggableScrollbar == other.draggableScrollbar &&
isAlwaysShown == other.isAlwaysShown &&
onlyDraggingThumb == other.onlyDraggingThumb &&
enableScrollAfterDragEnd == other.enableScrollAfterDragEnd &&
scrollbarThickness == other.scrollbarThickness &&
scrollbarThicknessWhileDragging ==
other.scrollbarThicknessWhileDragging &&
Expand All @@ -722,6 +735,7 @@ class PlutoGridScrollbarConfig {
scrollbarRadius == other.scrollbarRadius &&
scrollbarRadiusWhileDragging ==
other.scrollbarRadiusWhileDragging &&
longPressDuration == other.longPressDuration &&
dragDevices == other.dragDevices;
}

Expand All @@ -730,6 +744,7 @@ class PlutoGridScrollbarConfig {
draggableScrollbar,
isAlwaysShown,
onlyDraggingThumb,
enableScrollAfterDragEnd,
scrollbarThickness,
scrollbarThicknessWhileDragging,
hoverWidth,
Expand All @@ -739,6 +754,7 @@ class PlutoGridScrollbarConfig {
scrollBarTrackColor,
scrollbarRadius,
scrollbarRadiusWhileDragging,
longPressDuration,
dragDevices,
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/ui/pluto_body_rows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PlutoBodyRowsState extends PlutoStateWithChange<PlutoBodyRows> {
isAlwaysShown: scrollbarConfig.isAlwaysShown,
onlyDraggingThumb: scrollbarConfig.onlyDraggingThumb,
enableHover: PlatformHelper.isDesktop,
enableScrollAfterDragEnd: scrollbarConfig.enableScrollAfterDragEnd,
thickness: scrollbarConfig.scrollbarThickness,
thicknessWhileDragging: scrollbarConfig.scrollbarThicknessWhileDragging,
hoverWidth: scrollbarConfig.hoverWidth,
Expand All @@ -88,6 +89,7 @@ class PlutoBodyRowsState extends PlutoStateWithChange<PlutoBodyRows> {
scrollBarTrackColor: scrollbarConfig.scrollBarTrackColor,
radius: scrollbarConfig.scrollbarRadius,
radiusWhileDragging: scrollbarConfig.scrollbarRadiusWhileDragging,
longPressDuration: scrollbarConfig.longPressDuration,
child: SingleChildScrollView(
controller: _horizontalScroll,
scrollDirection: Axis.horizontal,
Expand Down
20 changes: 16 additions & 4 deletions lib/src/widgets/pluto_scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const double _kScrollbarMinOverscrollLength = 8.0;
const Duration _kScrollbarTimeToFade = Duration(milliseconds: 1200);
const Duration _kScrollbarFadeDuration = Duration(milliseconds: 250);
const Duration _kScrollbarResizeDuration = Duration(milliseconds: 100);
const Duration _kScrollbarLongPressDuration = Duration(milliseconds: 100);

// Extracted from iOS 13.1 beta using Debug View Hierarchy.
const Color _kScrollbarColor = CupertinoDynamicColor.withBrightness(
Expand All @@ -39,13 +40,15 @@ class PlutoScrollbar extends StatefulWidget {
this.isAlwaysShown = false,
this.onlyDraggingThumb = true,
this.enableHover = true,
this.enableScrollAfterDragEnd = true,
this.thickness = defaultThickness,
this.thicknessWhileDragging = defaultThicknessWhileDragging,
this.hoverWidth = defaultScrollbarHoverWidth,
double? mainAxisMargin,
double? crossAxisMargin,
Color? scrollBarColor,
Color? scrollBarTrackColor,
Duration? longPressDuration,
this.radius = defaultRadius,
this.radiusWhileDragging = defaultRadiusWhileDragging,
required this.child,
Expand All @@ -57,6 +60,7 @@ class PlutoScrollbar extends StatefulWidget {
crossAxisMargin = crossAxisMargin ?? _kScrollbarCrossAxisMargin,
scrollBarColor = scrollBarColor ?? _kScrollbarColor,
scrollBarTrackColor = scrollBarTrackColor ?? _kTrackColor,
longPressDuration = longPressDuration ?? _kScrollbarLongPressDuration,
super(key: key);
final ScrollController? horizontalController;

Expand All @@ -68,6 +72,10 @@ class PlutoScrollbar extends StatefulWidget {

final bool enableHover;

final bool enableScrollAfterDragEnd;

final Duration longPressDuration;

final double thickness;

final double thicknessWhileDragging;
Expand Down Expand Up @@ -361,7 +369,9 @@ class PlutoGridCupertinoScrollbarState extends State<PlutoScrollbar>
_startFadeoutTimer();
_thicknessAnimationController.reverse();
_dragScrollbarAxisPosition = null;
final double scrollVelocity = _painter!.getTrackToScroll(trackVelocity);
final double scrollVelocity = widget.enableScrollAfterDragEnd
? _painter!.getTrackToScroll(trackVelocity)
: 0;
_drag?.end(DragEndDetails(
primaryVelocity: -scrollVelocity,
velocity: Velocity(
Expand Down Expand Up @@ -423,8 +433,9 @@ class PlutoGridCupertinoScrollbarState extends State<PlutoScrollbar>
gestures[_ThumbPressGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<_ThumbPressGestureRecognizer>(
() => _ThumbPressGestureRecognizer(
debugOwner: this,
customPaintKey: _customPaintKey,
debugOwner: this,
duration: widget.longPressDuration,
onlyDraggingThumb: widget.onlyDraggingThumb,
),
(_ThumbPressGestureRecognizer instance) {
Expand Down Expand Up @@ -1373,15 +1384,16 @@ class _ThumbPressGestureRecognizer extends LongPressGestureRecognizer {
_ThumbPressGestureRecognizer({
double? postAcceptSlopTolerance,
Set<PointerDeviceKind>? supportedDevices,
required Object debugOwner,
required GlobalKey customPaintKey,
required Object debugOwner,
required Duration duration,
this.onlyDraggingThumb = false,
}) : _customPaintKey = customPaintKey,
super(
postAcceptSlopTolerance: postAcceptSlopTolerance,
supportedDevices: supportedDevices,
debugOwner: debugOwner,
duration: const Duration(milliseconds: 100),
duration: duration,
);

final GlobalKey _customPaintKey;
Expand Down

0 comments on commit 2d38ed7

Please sign in to comment.