About the bottomBar, is there a way to avoid the view to recompose when switching between tabs ? Le...
l
About the bottomBar, is there a way to avoid the view to recompose when switching between tabs ? Let’s say I have a BottomBar with Tab A being a list, and a Tab B being a mapView. In Tab A I scroll the list, then open Tab B and I move the map. Then switch to Tab A, I would like my list to have the position as it where before. Same if I go back to the mapView, I don’t want to lose the map moved by the user.
👀 1
This problem occur in Now in Android app. sample code
Copy code
fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) {
        trace("Navigation: ${topLevelDestination.name}") {
            val topLevelNavOptions = navOptions {
                // Pop up to the start destination of the graph to
                // avoid building up a large stack of destinations
                // on the back stack as users select items
                popUpTo(navController.graph.findStartDestination().id) {
                    saveState = true
                }
                // Avoid multiple copies of the same destination when
                // reselecting the same item
                launchSingleTop = true
                // Restore state when reselecting a previously selected item
                restoreState = true
            }

            when (topLevelDestination) {
                FOR_YOU -> navController.navigateToForYou(topLevelNavOptions)
...
            }
        }
    }
p
l
@Pedro Alberto So, Should i hoist list scroll data and all map’s data? although each tabs have their own viewModels?
p
maybe your app would be a different scenario
s
Does list scroll position get lost when you’ve properly set save/restore state? I thought this worked out of the box? Just tested it in a sample project I have and it does save the scroll position.
About the Map information, I guess you’d also need some way to save this data in a bundle which is restorable, maybe even a rememberSaveable is enough? Again just tested with a simple
Int
and rememberSaveable solves this problem. Can you check if you can do the same for the data of the map which is being lost as you’re describing?