Expected result:
Reusable ExtendedFloatingActionButton
should expand or collapse within a reusable Scaffold
when I scroll.
Current result:
ExtendedFloatingActionButton
does not expand or collapse when I scroll the list in my Scaffold
I followed this tutorial, but it was not created with reusability in mind. The part I'm confused about is the listState
varible within the section called "Joining Everything Together" because I'm not sure where within my code I need to declare it as I have done this a few times in different areas.
@Composable
fun MyReusableScaffold(scaffoldTitle: String, scaffoldFab: @Composable () -> Unit,
scaffoldContent: @Composable (contentPadding: PaddingValues) -> Unit) {
Scaffold(
topBar = { LargeTopAppBar( title = { Text(text = scaffoldTitle) } ) },
floatingActionButton = { scaffoldFab },
content = { contentPadding -> scaffoldContent(contentPadding = contentPadding) }
)
}
@Composable
fun MyFAB(listState: LazyListState) {
ExtendedFloatingActionButton(
text = { Text(text = "title") },
icon = { Icon(Icons.Filled.Add, "") },
expanded = listState.isScrollingUp()
)
}
@Composable
fun <T> MyLazyColumn(modifier: Modifier,
...
) {
val listState = rememberLazyListState()
LazyColumn(
state = listState
) {
...
}
}
@Composable
fun MyHomeScreen() {
MyScaffold(
scaffoldTitle = "title",
scaffoldFab = MyExtendedFAB(listState = LazyListState?)
scaffoldContent = { MyHomeScreenContent(contentPadding = it) },
)
}
@Composable
fun MyHomeScreenContent(
modifier: Modifier = Modifier,
contentPadding: PaddingValues = PaddingValues()
) {
}