diff --git a/indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerView.kt b/indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerView.kt index 3343768..1a1ff03 100644 --- a/indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerView.kt +++ b/indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerView.kt @@ -353,14 +353,22 @@ class FastScrollerView @JvmOverloads constructor( } is TextView -> { @Suppress("UNCHECKED_CAST") - val possibleTouchedIndicators = view.tag as List + val possibleTouchedIndicators = view.tag as List + if (possibleTouchedIndicators.isEmpty() || heightForCalculations == 0) { + return false + } + val textIndicatorsTouchY = touchY - view.top val textLineHeight = heightForCalculations / possibleTouchedIndicators.size - val touchedIndicatorIndex = min( - textIndicatorsTouchY / textLineHeight, - possibleTouchedIndicators.lastIndex - ) + val touchedIndicatorIndex = if (textLineHeight > 0) { + min( + textIndicatorsTouchY / textLineHeight, + possibleTouchedIndicators.lastIndex + ) + } else { + 0 + } val touchedIndicator = possibleTouchedIndicators[touchedIndicatorIndex] val centerY = view.y.toInt() + (textLineHeight / 2) + (touchedIndicatorIndex * textLineHeight)