popRoot() behavioral question for Android rememberCircuitNavigator (with BackHandler) #2064
Closed
dfrancis-clear
started this conversation in
General
Replies: 1 comment 1 reply
-
Ya that this is a problem with how |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! Huge shout out to Zac and all the maintainers on the library. Absolutely love working with Circuit 💯
Now for my question 😅
I'm running into some (potentially) unexpected behavior with calling
popRoot()
within a nested Circuit (NavigableCircuitContent
using the Android version ofrememberCircuitNavigator()
that contains aBackHandler
- here).For example, not all of the app is in Circuit (yet) and we navigate into a Circuit via Fragment navigation, setting up the
NavigableCircuitContent
andNavigator
within the Fragment (important to note, theOnBackPressedDispatcher.onBackPressed()
behavior of this screen will pop / dismiss the Fragment to go back to wherever it came from).From the Circuit in this fragment, it starts on ScreenA, calls
navigator.goTo(ScreenB)
, which then has a "Close" button that invokesnavigator.popRoot()
(here) and with this,popRoot()
resets the root toScreenB
, thenpop()
is called, triggering theonRootPop
set up in the Android version ofrememberCircuitNavigator
(with aBackHandler
). With this, thebackStack
size is 1, so I'd expect this innerBackHandler
to be disabled (one of the enabled conditions isbackStack.size > 1
) and for theOnBackPressedDispatcher.onBackPressed()
callback that is invoked to be the one on the next level up (the Fragment's). What I see happening is that recomposition withinrememberCircuitNavigator
hasn't happened yet, so the innerOnBackHandler
is what gets invoked, falling into onBack() where thebackStack.size
is 1.After tapping the "Close" button again, invoking
navigator.popRoot()
again, it works as expected (recomposition has happened at this point, the innerBackHandler
is not enabled), invoking theOnBackPressedDispatcher.onBackPressed()
of the next level up (the Fragment).Am I misunderstanding what's expected to happen with
popRoot()
in this case?Messed around in the Star sample and was able to reproduce the issue: added a
BackHandler
Toast withinMainActivity
, changed its NavigableCircuitContent root toPetListScreen
, then changed the "Full bio on Petfinder" action onPetDetailScreen
to invokenavigator.popRoot()
.EDIT: If this should be opened or transferred to being an "Issue", let me know, happy to do it.
Screen_recording_20250430_114243.mp4
Beta Was this translation helpful? Give feedback.
All reactions