Fixed
Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
Author: Ian Lake <
Link:
Add transition aware LifecycleOwner to SinglePaneNavDisplay
Expand for full commit details
Add transition aware LifecycleOwner to SinglePaneNavDisplay
SinglePaneNavDisplay only displays one screen at a time and
that screen should be RESUMED.
However, since the transition between screens takes a
non-zero amount of time, there is a brief time when both
screens on visible and interactive. In this case, we
don't want both screens to be RESUMED during the
transition.
Instead, we want our Lifecycle.State to be:
- RESUMED only if that screen is on the back stack and
'settled' (no transition running)
- STARTED only if that screen is on the back stack and
in the middle of a transition
- CREATED if the screen is no longer on the back stack
(e.g., it has been popped) and is in the middle
of a transition
This has the added benefit that existing APIs like
dropUnlessResumed automatically start working,
avoiding accidental double clicks.
We can use the APIs provided by NavLocalProvider to
install a LocalLifecycleOwner that uses the current
transition state and the state of the back stack
as the input into the max Lifecycle.State, enforcing
the above requirements.
This first approach uses the existence of the key
on the back stack as a signal that it is on the back
stack since there's no way to tell two identical keys
apart when you only have a NavEntry.
Test: updated AnimatedTest
BUG: 399438567
Change-Id: Ic759e4d82f1e5adfc68cbbf07a10af25dd33a79a
Files:
- M
navigation3/navigation3/src/androidInstrumentedTest/kotlin/androidx/navigation3/AnimatedTest.kt
- M
navigation3/navigation3/src/androidMain/kotlin/androidx/navigation3/SinglePaneNavDisplay.android.kt
Hash: 92b07a00c1cac88ecf9443187248560efe843e10
Date: Fri Feb 28 22:54:35 2025
Description
In Navigation 2.X, developers could use
dropUnlessResumed
to drop clicks after a transition to another screen started. This is important to avoid accidental double click issues.It would be helpful if
SinglePaneNavDisplay
had that same guarantee. This would mean that theLocalLifecycleOwner
within eachNavEntry
would be 'aware' of the current transition state of theSinglePaneNavDisplay
At minimum, this would mean that the
Lifecycle.State
would beRESUMED
only when the transition is settled.Ideally, entering screens (ones that are on the back stack) should be
STARTED
and exiting screens (those no longer on the back stack) should beCREATED
(e.g., having gone throughonStop
), but I could imagine that could be a follow up CL to the originalRESUMED
vsSTARTED
distinction.