Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support Android 13's predictive back gesture #276

Merged
merged 2 commits into from
Aug 29, 2023
Merged

Conversation

jayohms
Copy link
Collaborator

@jayohms jayohms commented May 18, 2023

This allows the library's navigation to respect Android 13/14's new predictive back gesture. Documentation: https://developer.android.com/guide/navigation/predictive-back-gesture

This disable the Activity's OnBackPressedCallback when the current nav controller is at its start destination. This allows the system to take control over the back behavior when leaving the app and display a custom animation.

Even if a particular user doesn't not have the "Preditive back animations" Developer Option enabled in Android 13, this change still provides a tangible benefit. The app's main Activity will no longer .finish() when using the back gesture/button to leave the app. For the first time, Android 13 maintains the Activity instance if an app does not manually call .finish().

On Android 13, apps that want to opt into the predictive back gesture must enable the following AndroidManifest flag:

<application
    ...
    android:enableOnBackInvokedCallback="true">

Note that Android 14 will further expand on the predictive back gesture including between screens, but the AndroidX APIs are not finalized and it requires targeting SDK 34, which hasn't hit API stability yet.

jayohms added 2 commits May 18, 2023 14:33
…OnBackPressedCallback when the current nav controller is at its start destination, so the system can take over the back behavior.
@jayohms jayohms requested a review from jhutarek May 18, 2023 19:15
Copy link
Contributor

@mbarta mbarta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! 👍

@jayohms jayohms merged commit 125a8ed into main Aug 29, 2023
@jayohms jayohms deleted the predictive-back-gesture branch August 29, 2023 18:29
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants