Skip to content

Instantly share code, notes, and snippets.

@zsoltk
Created December 21, 2019 23:02
Show Gist options
  • Save zsoltk/466b35a90e325b84f2bbcaa3e87b194c to your computer and use it in GitHub Desktop.
Save zsoltk/466b35a90e325b84f2bbcaa3e87b194c to your computer and use it in GitHub Desktop.
@Composable
fun Content(backPress: Backpress, cantPopBackStack: () -> Unit) {
// remainder omitted
var unhandledCount = +memo { State(0) }
val nbChildren = 2
val cantPopBackStackDelegate = {
// if we tried all of them and failed...
if (++unhandledCount.value == nbChildren) {
// ...then comes our local handling
if (!backStack.pop()) {
cantPopBackStack()
}
// don't forget to reset
unhandledCount.value = 0
}
}
SomeChild1.Content(
backPress = backPress,
cantPopBackStack = cantPopBackStackDelegate
)
SomeChild2.Content(
backPress = backPress,
cantPopBackStack = cantPopBackStackDelegate
)
// and so on ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment