what happens to `myNav` object, in case both `mode...
# compose
d
what happens to
myNav
object, in case both
model
and
navController
are immutable? will it get instantiated new at each recomposition?
Copy code
@Composable
fun Navigation(model : MyModel) {
   val appState by model.stateFlow.collectAsState()
   ...
   val navController = rememberNavController()
   val myNav = MyNav(model, navController)
   ...
}
s
Seems rememberNavController is @Composable function and take care of recomposition.
c
Yep it will be recreated on each recombination, to avoid this you should do:
remember(model, navController) { MyNav(model, navController) }
d
thanks @Chachako! should it be
remember
or
rememberSaveable
?
c
Use
rememberSaveable
when your instance wants to be retained after a configuration change. Reference: https://developer.android.com/jetpack/compose/state#restore-ui-state
👍 1
d
it seems to work with
remember
, but not with
rememberSaveable
:
Copy code
MyNav cannot be saved using the current SaveableStateRegistry. The default implementation only supports types which can be stored inside the Bundle. Please consider implementing a custom Saver for this class and pass it to rememberSaveable().
c
Yep, as the error stated, you need to create a custom
Saver
for MyNav