Jetpack Compose TopAppBar: How to remember collapsed state only per page

47 Views Asked by At

If I scroll down, the top app bar collapses as expected, and then I navigate to another screen (for the first time) from the bottom bar - however, the top app bar is in the collapsed state (because I had scrolled down in the previous tab). I want the new destination to show the top app bar and collapse only when I scroll down in this tab. In other words, the top app bar collapsed state should be per destination. Is that possible? I have

    @Composable
    fun Content() {
        val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(rememberTopAppBarState())
    
        Scaffold(
            modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
            topBar = {
                TopAppBar(
                    scrollBehavior = scrollBehavior,
                    colors = topAppBarColors(
                        containerColor = MaterialTheme.colorScheme.secondaryContainer,
                        titleContentColor = MaterialTheme.colorScheme.primary,
                    ),
                    title = {
                        Text("App")
                    },
                    actions = { ... },
                )
            },
            bottomBar = {
                NavigationBar { ... }
            }
        ) {
            ....
        }
    }
0

There are 0 best solutions below