Skip to content

Navigation containers should only allow a child screen's lifecycle to advance to RESUMED once transition animations are complete. #1414

@zach-klippenstein

Description

@zach-klippenstein

This allows screens to use LifecycleResumeEffect to perform actions that should only be done once the screen is ready to be interacted with. The biggest use case for this is requesting focus.

E.g. This is wrong, because it will (1) request the keyboard as soon as the animation starts, at which point the thing requesting focus isn't even visible on the screen, and (2) if predictive back is supported, the focus will be stolen by the previous screen as soon as the back gesture begins, even if it's later cancelled.

DisposableEffect(focusRequester) {
  focusRequester.requestFocus()
  onDispose {}
}

If we make this change, then the code can instead be:

LifecycleResumeEffect(focusRequester) {
  focusRequester.requestFocus()
  onPauseOrDispose {}
}

There is precedent for this change: The new Jetpack Nav3 library has this behavior already. We also discussed in Slack.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions