Is there a way to know if a `stickyHeader` inside ...
# compose-android
t
Is there a way to know if a
stickyHeader
inside a
LazyColumn
is at the top?
a
I have a function for this, if you bear with me a few moments I can copy it over from my personal laptop
(on my work one at the moment)
t
Any luck? 😄
s
We can only assume his work computer consumed him, not wanting him to touch another computer. Work computers are sneaky like that sometimes 💀
a
My work computer was sneaky like this
It did consume me because someone broke a change at work that I had to track down 🙈
I did however, make it out unscathed after the work computer had, in fact, consumed me 😛
Copy code
@Composable
fun rememberStickyHeaderActive(state: LazyListState, key: Any): State<Boolean> = remember(state) {
    derivedStateOf {
        val items = state.layoutInfo.visibleItemsInfo
        val header = items.getOrNull(0) ?: return@derivedStateOf false
        val item = items.getOrNull(1) ?: return@derivedStateOf false

        header.key == key && item.offset < header.size
    }
}
Sorry for the wait, here you go! You can probably easily make an extension function that provides this for within a sticky header without manually calling it
t
That's cool! Thank you! With this actually thinking to make a
stickyHeader(state) { isSticky: Boolean -> }
. I'll try to see if it workls later