-
|
Hi! I'm working on a multi-screen registration flow and wondering about the best approach for sharing state across screens in Circuit. Use CaseScreen A (Personal Info) → Screen B (Address) → Screen C (Verification) → Screen D (Complete) ChallengeIn Compose Navigation + AAC ViewModel, I've been using SharedViewModel to share state across screens. This provides: // https://youtu.be/h61Wqy3qcKg?si=OqctoATR5MGbypOW
@Composable
inline fun <reified T : ViewModel> NavBackStackEntry.sharedViewModel(
navController: NavHostController,
): T {
val navGraphRoute = destination.parent?.route ?: return hiltViewModel()
val parentEntry = remember(this) {
navController.getBackStackEntry(navGraphRoute)
}
return hiltViewModel(parentEntry)
}State preservation when navigating back/forthNo need to pass complex data through navigation arguments QuestionWhat's the recommended Circuit pattern for this? Options I'm considering:
Since Circuit Presenters are tied to specific Screens(UI), how do you handle multi-screen flows that need shared state? Any guidance appreciated! Thanks! ⚡️ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Think our best example for a common presenter is the tacos sample, we also cover a this in a bit more detail in the composite presenter issue #1801 (comment). That approach mostly comes down to how coordinated or isolated the presentation needs to be, and how ephemeral the state is. For the outlined case I can still see a shared data layer handling the common state. With the screens sharing an identifier/session key of some sort that is used to retrieve and edit the state. The data layer (or business logic) can handle cleanup, memory/disk persistence etc. Some possible state restoration and testing advantages with that too. |
Beta Was this translation helpful? Give feedback.
Think our best example for a common presenter is the tacos sample, we also cover a this in a bit more detail in the composite presenter issue #1801 (comment). That approach mostly comes down to how coordinated or isolated the presentation needs to be, and how ephemeral the state is.
For the outlined case I can still see a shared data layer handling the common state. With the screens sharing an identifier/session key of some sort that is used to retrieve and edit the state. The data layer (or business logic) can handle cleanup, memory/disk persistence etc. Some possible state restoration and testing advantages with that too.