@@ -78,6 +78,7 @@ public abstract class MaterialScrollBar<T> extends RelativeLayout {
7878 private TypedArray a ; //XML attributes
7979 private Boolean rtl = false ;
8080 boolean hiddenByUser = false ;
81+ private float fastScrollSnapPercent = 0 ;
8182
8283 //Associated Objects
8384 RecyclerView recyclerView ;
@@ -88,6 +89,7 @@ public abstract class MaterialScrollBar<T> extends RelativeLayout {
8889 //Misc
8990 private OnLayoutChangeListener indicatorLayoutListener ;
9091 private Runnable onSetup ;
92+ private float previousScrollPercent = 0 ;
9193
9294
9395 //CHAPTER I - INITIAL SETUP
@@ -277,6 +279,10 @@ void identifySwipeRefreshParents(){
277279 }
278280 }
279281
282+ boolean isScrollChangeLargeEnoughForFastScroll (float currentScrollPercent ) {
283+ return Math .abs (currentScrollPercent - previousScrollPercent ) > fastScrollSnapPercent ;
284+ }
285+
280286 boolean sizeUnchecked = true ;
281287
282288 //Checks each time the bar is laid out. If there are few enough view that
@@ -371,6 +377,20 @@ private void checkCustomScrollingInterface(){
371377 }
372378 }
373379
380+ /**
381+ * With very long lists, it may be advantageous to put a buffer on the drag bar to give the
382+ * user some time to actually see the scroll handle and the content. This will make the
383+ * bar less "smooth scrolling" and instead, snap to specific scroll percents. This could
384+ * be useful for the {@link DateAndTimeIndicator} style scrollbars, where you don't need to see
385+ * every single date available.
386+ *
387+ * @param snapPercent percentage that the fast scroll bar should snap to.
388+ */
389+ public T setFastScrollSnapPercent (float snapPercent ) {
390+ fastScrollSnapPercent = snapPercent ;
391+ return (T )this ;
392+ }
393+
374394 /**
375395 * The scrollBar should attempt to use dev provided scrolling logic and not default logic.
376396 *
@@ -698,9 +718,15 @@ public void onAnimationEnd(Animator animation) {
698718 int top = handleThumb .getHeight () / 2 ;
699719 int bottom = recyclerView .getHeight () - Utils .getDP (72 , recyclerView .getContext ());
700720 float boundedY = Math .max (top , Math .min (bottom , event .getY () - getHandleOffset ()));
701- scrollUtils .scrollToPositionAtProgress ((boundedY - top ) / (bottom - top ));
702- scrollUtils .scrollHandleAndIndicator ();
703- recyclerView .onScrolled (0 , 0 );
721+
722+ float currentScrollPercent = (boundedY - top ) / (bottom - top );
723+ if (isScrollChangeLargeEnoughForFastScroll (currentScrollPercent ) ||
724+ currentScrollPercent == 0 || currentScrollPercent == 1 ) {
725+ previousScrollPercent = currentScrollPercent ;
726+ scrollUtils .scrollToPositionAtProgress (currentScrollPercent );
727+ scrollUtils .scrollHandleAndIndicator ();
728+ recyclerView .onScrolled (0 , 0 );
729+ }
704730
705731 if (lightOnTouch ) {
706732 handleThumb .setBackgroundColor (handleColour );
0 commit comments