|
| 1 | +<!--docs: |
| 2 | +title: "Predictive Back" |
| 3 | +layout: detail |
| 4 | +section: foundations |
| 5 | +excerpt: "Predictive Back" |
| 6 | +iconId: predictive_back |
| 7 | +path: /foundations/predictive_back/ |
| 8 | +--> |
| 9 | + |
| 10 | +# Predictive Back |
| 11 | + |
| 12 | +Predictive Back is a navigation pattern tied to gesture navigation which shows |
| 13 | +the user a glimpse of where swiping back will bring them. Before completing a |
| 14 | +swipe, the user can decide to continue to the previous view or stay in the |
| 15 | +current view. |
| 16 | + |
| 17 | +In Android T (13), the OS introduced support for predictive back-to-home, which |
| 18 | +shows the user a preview of the home screen when swiping back to exit an app. |
| 19 | + |
| 20 | +With Android U (14), the OS adds support for in-app predictive back, which apps |
| 21 | +can take advantage of to show the user previous destinations when swiping back |
| 22 | +within the app itself. |
| 23 | + |
| 24 | +## Design & API documentation |
| 25 | + |
| 26 | +- Material Design guidelines: Predictive Back (coming soon) |
| 27 | +- [Framework & AndroidX Predictive Back developer guide](https://developer.android.com/guide/navigation/predictive-back-gesture) |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +To opt in to predictive back, apps must: |
| 32 | + |
| 33 | +1. Migrate from the legacy back handling APIs (`Activity#onBackPressed`, |
| 34 | +`KeyEvent.KEYCODE_BACK`, etc.) to the more recently introduced "back callback" |
| 35 | +APIs (`OnBackAnimationCallback`, `OnBackPressedCallback`, etc.). This involves |
| 36 | +flipping the `android:enableOnBackInvokedCallback` manifest flag to `true`, and |
| 37 | +registering callbacks to handle back pressed on Android T and above. More |
| 38 | +details on this general back migration can be found at the |
| 39 | +[Framework & AndroidX Predictive Back developer guide](https://developer.android.com/guide/navigation/predictive-back-gesture). |
| 40 | + |
| 41 | +2. Upgrade to MDC-Android library version **1.10.0-alpha01 (coming soon)** or |
| 42 | +above. |
| 43 | + |
| 44 | +Once completing these steps, you will get most of the predictive back animations |
| 45 | +within Material Components for free on Android U devices. See the section below |
| 46 | +to understand which components support predictive back and to learn about |
| 47 | +special considerations for each component. |
| 48 | + |
| 49 | +### Predictive Back Material Components |
| 50 | + |
| 51 | +The following Material Components support predictive back behavior and |
| 52 | +animations: |
| 53 | + |
| 54 | +- Search bar |
| 55 | +- Bottom sheet |
| 56 | +- Side sheet (support coming soon) |
| 57 | +- Navigation drawer |
| 58 | +- Navigation bar / Bottom navigation view (support coming soon) |
| 59 | +- Navigation rail (support coming soon) |
0 commit comments