circuit: Root `BackHandler` possible bug
Having an issue in the following scenario. The root screen sometimes has a BackHandler like so:
@Composable
fun RootUi(
state: TestState,
modifier: Modifier,
) {
RootContent()
BackHandler {
// don't let the user out of the app just yet
}
}
At some point ScreenA is pushed to the backstack which has the following logic in its presenter:
navigator.apply {
pop() // or resetRoot(ScreenRoot)
goTo(ScreenB)
}
Effectively I want ScreenA to pop and to push ScreenB. Tapping android back button in ScreenB calls BackHandler on RootUi from my testing even thought it’s not visible on the screen. Removing BackHandler navigation logic works as expected and navigates back to ScreenRoot.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 15 (2 by maintainers)
Commits related to this issue
- Add the test from https://github.com/slackhq/circuit/issues/1580#issuecomment-2289032940 — committed to slackhq/circuit by stagg 2 years ago
- Update `CupertinoGestureNavigationDecoration` to be a `AnimatedNavDecorator` (#1939) Like `AndroidPredictiveBackNavigationDecoration` update `CupertinoGestureNavigationDecoration` to be based on `Ani... — committed to slackhq/circuit by stagg 2 years ago
Couple things to note:
This depends on which
rememberCircuitNavigatoris being used:BackHandleris still needed to manipulate the navigator.BackHandlerand handles theonRootPopdisaptching, also prevents any infinite looping.CupertinoGestureNavigationDecorationdoesn’t have any back handling in it, so aBackHandleris still needed along siderememberCircuitNavigatorto manipulate the backstack.So the test fails correctly here.
Retested again by doing swipe back from the left side or pressing the back button and can confirm that the
BackHandlerissue seems to be fixed when usingAndroidPredictiveBackNavigationDecoration.Same as #1927?
Managed to write a test case that fails : https://github.com/slackhq/circuit/commit/0e7467e973c1168db5ac570f15c7b8f247d5eb4b