[iOS][SET] Back swipe rejected by `usePreventRemove` hides the shared element and stops shared transitions

Author: bartlomiejbloniarzCreated Sep 21, 2026Updated Sep 21, 2026
LabelsMissing reproPlatform: AndroidPlatform: iOSMissing info

Description

On iOS, a full back swipe on a screen guarded by usePreventRemove leaves shared element transitions broken for as long as that screen stays mounted.

This is the "unsaved changes" pattern from the React Navigation docs. The user swipes back on an edit screen, the swipe completes, react-native-screens puts the screen back, and an alert asks whether to discard the changes. From that moment:

  • The shared element on the guarded screen is invisible. It stays invisible after the user picks Stay.
  • Shared transitions to and from the guarded screen no longer run. The screens change, but the shared element jumps and the withCallback callback never fires.

It recovers once the guarded screen is really removed, for example after the user picks Discard. It only affects a guarded screen that contains an active SharedTransitionBoundary with a matching sharedTransitionTag.

Expected: after the rejected swipe the guarded screen looks the same as before, and shared transitions keep working.

Suspected cause

I have not confirmed this with a debugger. It comes from reading the code.

The completed swipe ends the progress transition with TransitionState::END, which creates an UncommittedScreenPop for the guarded screen. It is settled only when React removes that screen or when onGestureCancel arrives for it. A rejected dismissal produces neither. react-native-screens reports it with onNativeDismissCancelled, which Reanimated does not handle. While uncommittedScreenPop_ is set, pullTransaction never reaches the branch that starts shared transitions, and the source views hidden for the transition are not restored.

#9945 was the same kind of wait in the older closingScreenTag_ state and was fixed by #10371. This report is about the state that #10371 introduced.

Steps to reproduce

  1. Run the example below on iOS with ENABLE_SHARED_ELEMENT_TRANSITIONS enabled.
  2. Tap Edit. The photo animates to the edit screen.
  3. Swipe back from the left edge all the way across the screen and release. The edit screen comes back and the alert appears. The photo on the edit screen is gone.
  4. Tap Stay. The photo is still missing.
  5. Tap Open details, then Back. Neither runs a shared transition.
  6. Swipe back again and tap Discard. On the list, Open details animates again.

Snack or a link to a repository

App.tsx
typescript
import {
  NavigationContainer,
  useIsFocused,
  useNavigation,
  usePreventRemove,
} from '@react-navigation/native';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useState } from 'react';
import { Alert, Button, StyleSheet, Text, TextInput, View } from 'react-native';
import Animated, {
  SharedTransition,
  SharedTransitionBoundary,
} from 'react-native-reanimated';

type Routes = { List: undefined; Details: undefined; EditForm: undefined };
type Navigation = NativeStackNavigationProp<Routes>;
const Stack = createNativeStackNavigator<Routes>();

const transition = SharedTransition.duration(700).withCallback((finished) => {
  'worklet';
  console.log('[repro] shared transition finished:', finished);
});

function Photo({ size }: { size: number }) {
  return (
    <Animated.View
      sharedTransitionTag="photo"
      sharedTransitionStyle={transition}
      style={[styles.photo, { width: size, height: size }]}
    />
  );
}

function List() {
  const navigation = useNavigation<Navigation>();
  return (
    <SharedTransitionBoundary isActive={useIsFocused()}>
      <View style={styles.screen}>
        <Photo size={80} />
        <Button
          title="Open details"
          onPress={() => {
            console.log('[repro] open details');
            navigation.push('Details');
          }}
        />
        <Button
          title="Edit"
          onPress={() => {
            console.log('[repro] open form');
            navigation.push('EditForm');
          }}
        />
      </View>
    </SharedTransitionBoundary>
  );
}

function Details() {
  const navigation = useNavigation<Navigation>();
  return (
    <SharedTransitionBoundary isActive={useIsFocused()}>
      <View style={styles.screen}>
        <Photo size={240} />
        <Button
          title="Back"
          onPress={() => {
            console.log('[repro] back');
            navigation.goBack();
          }}
        />
      </View>
    </SharedTransitionBoundary>
  );
}

// The pattern from https://reactnavigation.org/docs/preventing-going-back
function EditForm() {
  const navigation = useNavigation<Navigation>();
  const [text, setText] = useState('draft');
  const hasUnsavedChanges = text !== '';

  usePreventRemove(hasUnsavedChanges, ({ data }) => {
    console.log('[repro] removal prevented');
    Alert.alert('Discard changes?', 'You have unsaved changes.', [
      { text: 'Stay', style: 'cancel' },
      {
        text: 'Discard',
        style: 'destructive',
        onPress: () => navigation.dispatch(data.action),
      },
    ]);
  });

  return (
    <SharedTransitionBoundary isActive={useIsFocused()}>
      <View style={styles.screen}>
        <Photo size={160} />
        <Text>Edit form</Text>
        <TextInput style={styles.input} value={text} onChangeText={setText} />
        <Button
          title="Open details"
          onPress={() => {
            console.log('[repro] open details');
            navigation.push('Details');
          }}
        />
      </View>
    </SharedTransitionBoundary>
  );
}

export default function UnsavedChangesRepro() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="List" component={List} />
        <Stack.Screen name="Details" component={Details} />
        <Stack.Screen name="EditForm" component={EditForm} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

const styles = StyleSheet.create({
  screen: { flex: 1, padding: 24, gap: 12, backgroundColor: 'white' },
  photo: { backgroundColor: '#f15946', alignSelf: 'center' },
  input: { borderWidth: 1, borderColor: '#999', padding: 8 },
});
Console output

The bug is the missing callback lines after the rejected swipe:

[repro] open form
[repro] shared transition finished: false
[repro] shared transition finished: true
[repro] removal prevented                     <- rejected swipe, then Stay
[repro] open details                          <- no transition
[repro] back                                  <- no transition
[repro] removal prevented                     <- second swipe, then Discard
[repro] open details
[repro] shared transition finished: false
[repro] shared transition finished: true     <- works again

The early finished: false appears on every push, also before the rejected swipe. A transition starts and is replaced right away by the one that completes. It is unrelated to this report.

https://github.com/user-attachments/assets/29c5478e-8daa-4326-8b52-0207ae74564a

Versions and environment

Field Value
Reanimated version 4.7.0-main (0c5e09d4)
Worklets version 0.13.0-main
React Native version 0.88.0-rc.1
react-native-screens 4.27.0
Platforms iOS
JavaScript runtime Hermes
Workflow React Native CLI
Architecture New Architecture (Fabric)
Reanimated feature flags ENABLE_SHARED_ELEMENT_TRANSITIONS: true
Build type Debug app & dev bundle
Device iOS simulator
Device model iPhone 17, iOS 26.3

I have not tested Android, Release builds, or a back action that does not use the swipe gesture.

Source: software-mansion/react-native-reanimated