https://kotlinlang.org logo
#compose
Title
# compose
z

Zoltan Demant

10/19/2023, 9:26 AM
I have an
isPinned
function that lets me know if a stickyHeader in a LazyColumn is stickied/pinned to the top. Logic below... Id like to rework this to instead calculate how pinned the item is (0-1f) but I dont quite know how that would look like. Any help is greatly appreciated! 🙏🏽
Copy code
private fun LazyListState.isPinned(key: Any): Boolean {
    val items = layoutInfo.visibleItemsInfo
    if (items.size >= 2) {
        val current = items[0]

        if (current.key == key) {
            val next = items[1]

            /**
             * TODO: Instead of returning a boolean
             * Return a 0-1f progression where 0f=not pinned, 1f=fully pinned
             */

            return current.size + current.offset >= next.offset
        }
    }

    return false
}
(this code lives in a
remember
+
derivedStateOf
)