From 843826a68fd172851af400de8d5d14344fd4e570 Mon Sep 17 00:00:00 2001 From: TJ Dahunsi Date: Thu, 29 Jun 2023 15:03:28 +0100 Subject: [PATCH] Check if first item size == 0 Change-Id: I41acffad84d9db1cf407f77b04530643933f98bf --- .../component/scrollbar/LazyScrollbarUtilities.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/LazyScrollbarUtilities.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/LazyScrollbarUtilities.kt index c4ce8c22d..2c1df0c66 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/LazyScrollbarUtilities.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/LazyScrollbarUtilities.kt @@ -116,8 +116,11 @@ internal inline fun LazyState.inter if (firstItemIndex < 0) return Float.NaN + val firstItemSize = itemSize(firstItem) + if (firstItemSize == 0) return Float.NaN + val itemOffset = offset(firstItem).toFloat() - val offsetPercentage = abs(itemOffset) / itemSize(firstItem) + val offsetPercentage = abs(itemOffset) / firstItemSize val nextItem = nextItemOnMainAxis(firstItem) ?: return firstItemIndex + offsetPercentage