Handling Back Navigation in Nested NavigableCircuitContent #1203
-
In our app, we've implemented nested navigation flows using Basic ExampleConsider a simple app structure:
Note: ProfileFlow is created like screen, so we start Profile Flow like - navigator.goTo(Profile Flow) Expected Behavior:
Current Issue:
Would like to hear how you handle nested flows:) Code example: fun MainActivity.tutorialOnCreate() {
val emailRepository = EmailRepository()
val circuit: Circuit =
Circuit.Builder()
//setting here both ui and presenter factories
setContent {
MaterialTheme {
val backStack = rememberSaveableBackStack { push(HomeScreen) }
val navigator = rememberCircuitNavigator(backStack)
CircuitCompositionLocals(circuit) {
NavigableCircuitContent(
navigator = navigator,
backStack = backStack,
decoration = GestureNavigationDecoration(
fallback = SlideNavDecoration,
onBackInvoked = navigator::pop
)
)
}
}
}
}
Navigate to the nested flow: class HomePresenter(
private val navigator: Navigator,
) : Presenter<HomeScreen.State> {
@Composable
override fun present(): HomeScreen.State {
return HomeScreen.State(myText) { event ->
when (event) {
HomeScreen.Event.GoToProfileFlow -> navigator.goTo(ProfileFlow)
}
}
}
The nested flow: @Composable
fun ProfileFlow(state: ProfileGraphScreen.State, modifier: Modifier = Modifier) {
val backStack = rememberSaveableBackStack { push(ProfileScreen) }
val navigator = rememberCircuitNavigator(backStack)
Scaffold(
modifier = modifier,
topBar = { TopAppBar(title = { Text("MailFlow") }) }) { innerPadding ->
NavigableCircuitContent(
backStack = backStack,
navigator = navigator,
decoration = GestureNavigationDecoration(onBackInvoked = navigator::pop),
modifier = Modifier.padding(innerPadding),
)
}
} I just check again the documentation (https://slackhq.github.io/circuit/tutorial/), |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Without any code sample, it's hard to advise anything here. |
Beta Was this translation helpful? Give feedback.
@ZacSweers there was something wrong with how i set the nested NavigableCircuitContent, the behaviour now is as expected.
thanks for your seeking to help:)