Skip to content

Commit c7873f7

Browse files
authored
Merge pull request #1 from FossifyOrg/naveensingh-patch-1
fix: avoid division by zero
1 parent aacd05f commit c7873f7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

indicator-fast-scroll/src/main/java/com/reddit/indicatorfastscroll/FastScrollerView.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,22 @@ class FastScrollerView @JvmOverloads constructor(
353353
}
354354
is TextView -> {
355355
@Suppress("UNCHECKED_CAST")
356-
val possibleTouchedIndicators = view.tag as List<FastScrollItemIndicator.Text>
356+
val possibleTouchedIndicators = view.tag as List<FastScrollItemIndicator.Text>
357+
if (possibleTouchedIndicators.isEmpty() || heightForCalculations == 0) {
358+
return false
359+
}
360+
357361
val textIndicatorsTouchY = touchY - view.top
358362

359363
val textLineHeight = heightForCalculations / possibleTouchedIndicators.size
360-
val touchedIndicatorIndex = min(
361-
textIndicatorsTouchY / textLineHeight,
362-
possibleTouchedIndicators.lastIndex
363-
)
364+
val touchedIndicatorIndex = if (textLineHeight > 0) {
365+
min(
366+
textIndicatorsTouchY / textLineHeight,
367+
possibleTouchedIndicators.lastIndex
368+
)
369+
} else {
370+
0
371+
}
364372

365373
val touchedIndicator = possibleTouchedIndicators[touchedIndicatorIndex]
366374
val centerY = view.y.toInt() + (textLineHeight / 2) + (touchedIndicatorIndex * textLineHeight)

0 commit comments

Comments
 (0)