Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Add option to disable track #46

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class RecyclerViewFastScroller @JvmOverloads constructor(
const val hasEmptyItemDecorator: Boolean = true
const val handleVisibilityDuration: Int = 0
const val trackMargin: Int = 0
const val disableTrack = false
}

/**
Expand Down Expand Up @@ -214,6 +215,7 @@ class RecyclerViewFastScroller @JvmOverloads constructor(
field = value
refreshHandleImageViewSize()
}
var disableTrack: Boolean = Defaults.disableTrack

/**
* The duration for which the handle should remain visible, defaults to -1 (don't hide)
Expand Down Expand Up @@ -364,6 +366,9 @@ class RecyclerViewFastScroller @JvmOverloads constructor(
Defaults.trackMargin
)

disableTrack =
attribs.getBoolean(R.styleable.RecyclerViewFastScroller_disableTrack, Defaults.disableTrack)

TextViewCompat.setTextAppearance(
popupTextView,
attribs.getResourceId(
Expand Down Expand Up @@ -409,6 +414,23 @@ class RecyclerViewFastScroller @JvmOverloads constructor(

when (touchAction) {
MotionEvent.ACTION_MOVE, MotionEvent.ACTION_DOWN -> {
val handlePosition = IntArray(2).also {
handleImageView.getLocationOnScreen(it)
}
if (disableTrack) {
when (fastScrollDirection) {
FastScrollDirection.HORIZONTAL -> {
val handleRange = handlePosition[0].toFloat() .. handlePosition[0]+handleLength
if (!handleRange.contains(motionEvent.rawX))
return@OnTouchListener false
}
FastScrollDirection.VERTICAL -> {
val handleRange = handlePosition[1].toFloat() .. handlePosition[1]+handleLength
if (!handleRange.contains(motionEvent.rawY))
return@OnTouchListener false
}
}
}

// disallow parent to spy on touch events
requestDisallowInterceptTouchEvent(true)
Expand Down
4 changes: 3 additions & 1 deletion recyclerviewfastscroller/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
<attr name="handleHeight" format="dimension" />
<attr name="handleHasFixedSize" format="boolean" />
<attr name="supportSwipeToRefresh" format="boolean" />

<attr name="trackMarginStart" format="dimension" />
<attr name="trackMarginEnd" format="dimension" />

<attr name="handleVisibilityDuration" format="integer" />

<attr name="disableTrack" format="boolean"/>
</declare-styleable>
</resources>