Differences from adrielcafe/voyager
The original voyager library does not support Compose Web
The original voyager library does not support path-based navigation.
voyager-androidxnow work differently: all lifecycle handling hooks from the original code have been removed (AndroidScreenLifecycleOwneris not used anymore). This is because it caused many issues: see for example issue 62. But this does not mean that android lifecycle events are ignored. When an activity is destroyed then all associatedScreenModelsandBlocsare automatically disposed and the associated flows cancelledAlso flows associated to blocs of an
Activityare automatically paused when theActivityis pausedNow Screen lifecycle is handled in the following way: A
Screen(and associated screen model and blocs) is disposed in the following casesWhen the
Screenis popped from the navigator stackWhen the parent
Activitywhere theScreencomposable was started is destroyed
In order to all this to work, now is required to declare the top level navigator in an activity with
RootNavigator:
class MainScreen: Screen {
@Composable
override fun Content() {
//... main screen implementation here
}
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
//*IMPORTANT* need to use RootNavigator to initialize root navigator for activity, not as in original voyager
RootNavigator(MainScreen())
}
}
}Last updated
Was this helpful?