From cc6ba0c1d83f04746751720a7fa0770a6bd65644 Mon Sep 17 00:00:00 2001 From: Eduardo Ferreras Carracedo Date: Mon, 24 Feb 2025 10:53:37 +0100 Subject: [PATCH] Removed Int.MAX_VALUE from nextOffset as it could lead to an int overflow --- .../me/gingerninja/lazy/StickyHeadersLayout.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sticky-headers/src/commonMain/kotlin/me/gingerninja/lazy/StickyHeadersLayout.kt b/sticky-headers/src/commonMain/kotlin/me/gingerninja/lazy/StickyHeadersLayout.kt index 2054a5f..8aa73d6 100644 --- a/sticky-headers/src/commonMain/kotlin/me/gingerninja/lazy/StickyHeadersLayout.kt +++ b/sticky-headers/src/commonMain/kotlin/me/gingerninja/lazy/StickyHeadersLayout.kt @@ -105,7 +105,6 @@ fun StickyHeadersLayout( val nextOffset = layoutInfoProvider.itemOffsetAt(interval.endIndex, orientation) - ?: Int.MAX_VALUE val itemOffset = layoutInfoProvider.itemOffsetAt(interval.startIndex, orientation) @@ -122,10 +121,15 @@ fun StickyHeadersLayout( // don't show the item if it's not visible anymore alpha = 0f } else { - val diff = nextOffset - spacing + beforePadding - stickyPadding + val diff = nextOffset + ?.let { it - spacing + beforePadding - stickyPadding } if (orientation == Orientation.Vertical) { - val y = (diff - size.height).coerceAtMost(0f) + val y = diff + ?.let { it - size.height } + ?.coerceAtMost(0f) + ?: 0f + val offset = (itemOffset + beforePadding).coerceAtLeast(0) @@ -133,7 +137,11 @@ fun StickyHeadersLayout( translationY = (offset + y + inset) * direction } else { - val x = (diff - size.width).coerceAtMost(0f) + val x = diff + ?.let { it - size.width } + ?.coerceAtMost(0f) + ?: 0f + val offset = (itemOffset + beforePadding).coerceAtLeast(0)