I'm confused trying get `AnimatedVisibility` worki...
# compose
s
I'm confused trying get
AnimatedVisibility
working. It works fine to hide my composable, but it doesn't show it when
visible
changes back to true.
K 1
I'm using the example from https://stackoverflow.com/questions/74381573/jetpack-compose-fab-hide-on-scroll-behavior to show/hide a FAB on scroll.
Copy code
Scaffold(
    floatingActionButton = {
            val showFab = listState.isScrollingUp().value
            println("showing fab: $showFab")
            AnimatedVisibility(visible = showFab) {
                FloatingActionButton(
                    onClick = {
                        ...
                    }
                ) {
                    Icon(
                        imageVector = Icons.Default.Add,
                        contentDescription = "add"
                    )
                }
            }
    },
    ...
)
y
Is the showFab changing when you scroll?
s
Yes, it does.
z
I would make
showFab
as
derivedStateOf
of
listState
. Like explained here: https://medium.com/androiddevelopers/jetpack-compose-when-should-i-use-derivedstateof-63ce7954c11b
val isEnabled = remember {
derivedStateOf { lazyListState.firstVisibleItemIndex > 0 }
}
s
I don't see why. That article states not to use
derivedStateOf
to combine values. I want the FAB to be visible when the user has last scrolled up, so the previous index needs to be remembered.
z
What happens if you move
showFab
before
Scaffold
?