Android predictive back
Preview the previous screen during the system Back gesture and customize how both screens animate.
On Android 14 and later, swipe inward from either edge to preview the previous screen in a native stack. Completing the gesture pops the current route. Reversing the gesture back to the edge and releasing restores the current screen.
The Android starter enables android:enableOnBackInvokedCallback on its main activity. In an existing app, check the activity's manifest and enable gesture navigation on the test device. Android versions without gesture progress still use the standard Back action. Android's predictive back guide
Choose a built-in effect
Both effects are functions exported by nitro-ui-navigation.
| Function | Effect |
|---|---|
defaultBackTransition | Shrinks and rounds the current screen while dimming the previous screen underneath. The stack uses this effect by default. |
zoomBackTransition | Slides a rounded, smaller screen toward the swipe to reveal more of the previous screen. |
Set androidBackTransition in the navigator's screenOptions to choose a default for the stack. Override it in a screen's options when that route needs a different effect.
import { defaultBackTransition, zoomBackTransition } from 'nitro-ui-navigation'
<Stack.Navigator screenOptions={{ androidBackTransition: zoomBackTransition }}>
<Stack.Screen name="Feed" component={FeedScreen} />
<Stack.Screen
name="Post"
component={PostScreen}
options={{ androidBackTransition: defaultBackTransition }}
/>
</Stack.Navigator>Write an interpolator
An AndroidBackTransition returns the style for the outgoing screen, the incoming screen, or both. You can define the entire effect or adjust the result of a built-in function. This example keeps the zoom effect and increases the outgoing screen's corner radius.
import { zoomBackTransition, type AndroidBackTransition } from 'nitro-ui-navigation'
const roundedZoom: AndroidBackTransition = (input) => {
const frame = zoomBackTransition(input)
return {
...frame,
outgoing: { ...frame.outgoing, cornerRadius: 32 * input.progress },
}
}
<Stack.Screen name="Post" component={PostScreen} options={{ androidBackTransition: roundedZoom }} />| Input | Meaning |
|---|---|
progress | Gesture progress from 0 to 1. It moves back toward 0 on cancellation and holds its last value during completion. |
completion | Progress from 0 to 1 after the gesture is confirmed. Use it to finish the motion or fade the outgoing screen. |
swipeEdge | AndroidBackSwipeEdge.Left or AndroidBackSwipeEdge.Right. |
touchOffsetY | Vertical finger movement since the swipe started, in dp. |
width, height | Size of the outgoing screen's content in dp. The height excludes the toolbar and the insets reserved by it. |
Each returned style accepts scale, translateX, translateY, opacity, and cornerRadius. Translation and radius values are in dp. The transforms and opacity are relative to the screen's resting style. An omitted property keeps its resting value.
The function runs synchronously on the UI thread during the gesture and its finishing animation. Keep it focused on calculating styles and leave React state updates and navigation actions to the rest of the app.
Custom Back handling and shared elements
A screen with onAndroidBackPress skips the stack preview and calls the handler when the user confirms Back. A route with a sharedElementId uses its shared element transition after confirmation. At the root of a stack, Back passes to Android when the screen has no custom Back handler. Shared element transitions