From 2d38ed7550664da0cf77a7fa5c069bba14094e4f Mon Sep 17 00:00:00 2001 From: kmk Date: Tue, 7 Mar 2023 21:45:10 +0900 Subject: [PATCH] Add Scrollbar properties. --- lib/src/pluto_grid_configuration.dart | 16 ++++++++++++++++ lib/src/ui/pluto_body_rows.dart | 2 ++ lib/src/widgets/pluto_scrollbar.dart | 20 ++++++++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/src/pluto_grid_configuration.dart b/lib/src/pluto_grid_configuration.dart index 1b13748de..1973c35f7 100644 --- a/lib/src/pluto_grid_configuration.dart +++ b/lib/src/pluto_grid_configuration.dart @@ -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, @@ -671,6 +672,7 @@ class PlutoGridScrollbarConfig { this.scrollbarRadius = PlutoScrollbar.defaultRadius, this.scrollbarRadiusWhileDragging = PlutoScrollbar.defaultRadiusWhileDragging, + this.longPressDuration, this.dragDevices, }); @@ -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; @@ -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? dragDevices; @override @@ -711,6 +723,7 @@ class PlutoGridScrollbarConfig { draggableScrollbar == other.draggableScrollbar && isAlwaysShown == other.isAlwaysShown && onlyDraggingThumb == other.onlyDraggingThumb && + enableScrollAfterDragEnd == other.enableScrollAfterDragEnd && scrollbarThickness == other.scrollbarThickness && scrollbarThicknessWhileDragging == other.scrollbarThicknessWhileDragging && @@ -722,6 +735,7 @@ class PlutoGridScrollbarConfig { scrollbarRadius == other.scrollbarRadius && scrollbarRadiusWhileDragging == other.scrollbarRadiusWhileDragging && + longPressDuration == other.longPressDuration && dragDevices == other.dragDevices; } @@ -730,6 +744,7 @@ class PlutoGridScrollbarConfig { draggableScrollbar, isAlwaysShown, onlyDraggingThumb, + enableScrollAfterDragEnd, scrollbarThickness, scrollbarThicknessWhileDragging, hoverWidth, @@ -739,6 +754,7 @@ class PlutoGridScrollbarConfig { scrollBarTrackColor, scrollbarRadius, scrollbarRadiusWhileDragging, + longPressDuration, dragDevices, ); } diff --git a/lib/src/ui/pluto_body_rows.dart b/lib/src/ui/pluto_body_rows.dart index 4736fb38b..fc37f7209 100644 --- a/lib/src/ui/pluto_body_rows.dart +++ b/lib/src/ui/pluto_body_rows.dart @@ -79,6 +79,7 @@ class PlutoBodyRowsState extends PlutoStateWithChange { isAlwaysShown: scrollbarConfig.isAlwaysShown, onlyDraggingThumb: scrollbarConfig.onlyDraggingThumb, enableHover: PlatformHelper.isDesktop, + enableScrollAfterDragEnd: scrollbarConfig.enableScrollAfterDragEnd, thickness: scrollbarConfig.scrollbarThickness, thicknessWhileDragging: scrollbarConfig.scrollbarThicknessWhileDragging, hoverWidth: scrollbarConfig.hoverWidth, @@ -88,6 +89,7 @@ class PlutoBodyRowsState extends PlutoStateWithChange { scrollBarTrackColor: scrollbarConfig.scrollBarTrackColor, radius: scrollbarConfig.scrollbarRadius, radiusWhileDragging: scrollbarConfig.scrollbarRadiusWhileDragging, + longPressDuration: scrollbarConfig.longPressDuration, child: SingleChildScrollView( controller: _horizontalScroll, scrollDirection: Axis.horizontal, diff --git a/lib/src/widgets/pluto_scrollbar.dart b/lib/src/widgets/pluto_scrollbar.dart index 067d303af..641455bc4 100644 --- a/lib/src/widgets/pluto_scrollbar.dart +++ b/lib/src/widgets/pluto_scrollbar.dart @@ -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( @@ -39,6 +40,7 @@ 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, @@ -46,6 +48,7 @@ class PlutoScrollbar extends StatefulWidget { double? crossAxisMargin, Color? scrollBarColor, Color? scrollBarTrackColor, + Duration? longPressDuration, this.radius = defaultRadius, this.radiusWhileDragging = defaultRadiusWhileDragging, required this.child, @@ -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; @@ -68,6 +72,10 @@ class PlutoScrollbar extends StatefulWidget { final bool enableHover; + final bool enableScrollAfterDragEnd; + + final Duration longPressDuration; + final double thickness; final double thicknessWhileDragging; @@ -361,7 +369,9 @@ class PlutoGridCupertinoScrollbarState extends State _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( @@ -423,8 +433,9 @@ class PlutoGridCupertinoScrollbarState extends State gestures[_ThumbPressGestureRecognizer] = GestureRecognizerFactoryWithHandlers<_ThumbPressGestureRecognizer>( () => _ThumbPressGestureRecognizer( - debugOwner: this, customPaintKey: _customPaintKey, + debugOwner: this, + duration: widget.longPressDuration, onlyDraggingThumb: widget.onlyDraggingThumb, ), (_ThumbPressGestureRecognizer instance) { @@ -1373,15 +1384,16 @@ class _ThumbPressGestureRecognizer extends LongPressGestureRecognizer { _ThumbPressGestureRecognizer({ double? postAcceptSlopTolerance, Set? 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;