Lilly
04/13/2021, 1:19 PMcompose-router
to jetpacks navigation-compose
and I'm wondering how to handle constructs like those properly:
// (container) screen with a BottomNavigationBar
fun ScreenContainer(
...
childs: @Composable (PaddingValues, SomeState, SomeHighOrderFunction) -> Unit
)
ScreenContainer(
...
) { innerPadding, SomeState, onError -> // How to easily pass things like innerPading or highorder functions to child screens?
NestedRouter(startPoint = Screen.A) { backStack ->
when(backStack.last())
is ScreenA -> ScreenA()
is ScreenB -> ScreenB()
}
}
vs.
NavHost(navController = navController, startDestination = "container") {
composable("container") { ScreenContainer(
...
) // childs are now called via navController
composable("screena") { ScreenA(innerPadding = ?, state = ?, onError = ?) } // How to get these parameters?
composable("screenb") { ScreenB(innerPadding = ?, state = ?, onError = ?) }
}
Thanks in advance!Joost Klitsie
04/13/2021, 1:31 PMJoost Klitsie
04/13/2021, 1:32 PMJoost Klitsie
04/13/2021, 1:33 PMLilly
04/13/2021, 1:39 PMIan Lake
04/13/2021, 2:02 PMLilly
04/13/2021, 2:28 PMpresenter/view model
so even child screens can receive errors and to not handle errors for every screen I want to hoist the "onError" events up to the parent so error handling is done in one place. The other reason for the tight coupling is that I pass down the status of the connection to the child screens, so that when device is connected the child screen starts fetching its screen content from the device. What do you think, how would I implement this properly?Joost Klitsie
04/13/2021, 2:29 PMLilly
04/13/2021, 2:34 PMIan Lake
04/13/2021, 2:36 PMcomposable
destination to reference state created and updated outside of the NavHost,
same with bubbling events up beyond the NavHost
Joost Klitsie
04/13/2021, 2:43 PMLilly
04/13/2021, 2:44 PMlateinit var state: SomeState
val onError: (String) -> Unit = { ... }
NavHost(navController = navController, startDestination = "container") {
composable("container") { ScreenContainer(onError = onError)
composable("screena") { ScreenA(innerPadding = ?, state = state, onError = onError) } // How to get these parameters?
composable("screenb") { ScreenB(innerPadding = ?, state = state, onError = onError) }
}
@Joost Klitsie Transitions aren't supported yet right?Joost Klitsie
04/13/2021, 2:46 PMIan Lake
04/13/2021, 4:12 PMLilly
04/13/2021, 4:15 PM