spierce7
03/03/2023, 10:42 PMSrSouza
03/05/2023, 4:41 PMLocalNavigator.current
will never return the Navigator for the BottomSheetNavigator { Navigator(MyScreen) }
Don’t know if you are trying to do something like that, maybe you can explain a little bit.SrSouza
03/05/2023, 4:56 PMclass NavigatorReference(
val navigator: Navigator
)
val LocalNavigatorReference: ProvidableCompositionLocal<NavigatorReference> =
staticCompositionLocalOf { error("NavigatorReference not initialized") }
@Composable
private fun ProvideNavigatorReference(
navigator: Navigator,
content: @Composable () -> Unit
) {
CompositionLocalProvider(LocalNavigatorReference provides NavigatorReference(navigator)) {
content()
}
}
@Composable
fun BottomSheetWithNavigatorReference() {
var currentNavigator by remember { mutableStateOf<Navigator?>(null) }
BottomSheetNavigator(
sheetContent = {
// Current Navigator will never be null because `SheetContent` will always be called
// when it already called `content`.
ProvideNavigatorReference(currentNavigator!!) {
CurrentScreen()
}
},
content = { bottomSheetNavigator ->
Navigator(screen = YourStartScreen()) { navigator ->
LaunchedEffect(navigator) {
currentNavigator = navigator
}
ProvideNavigatorReference(navigator) {
CurrentScreen()
}
}
}
)
}
SrSouza
03/05/2023, 4:57 PMSrSouza
03/05/2023, 4:58 PMLocalNavigatorReference.current.navigator
(you can do a better API for it using Composable property to look like LocalNavigator.current
)