software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
9.09k stars 1.32k forks source link

Bridgeless with enableFreeze: useSharedValue resets to initialValue when navigating between screens #6728

Open vilindberg opened 3 days ago

vilindberg commented 3 days ago

Description

Wasn't sure if I should create this issue in this repo or in the react-native-screens one. But here we go!

When having enableFreeze(true), useSharedValue resets to the initial value when moving to another screen within a bottom tab navigator and then back again. Since FirstScreen is not unmounted, I would expect it to keep the value at 300.

Update: It seems to work (staying at 300) in RN 0.73 and in 0.74 when I disable new architecture, so it was likely introduced by the bridgeless mode.

https://github.com/user-attachments/assets/41c91b91-ea8f-4c8c-95cd-f11bbc46935e

Steps to reproduce

  1. Run the provided sample repo (https://github.com/vilindberg/reanimated-shared-value-between-stacks)
  2. Wait for the width to animate to 300 on FirstScreen
  3. Navigate to SecondScreen
  4. Navigate back to FirstScreen and the width will have been reset to 100

Snack or a link to a repository

https://github.com/vilindberg/reanimated-shared-value-between-stacks

Reanimated version

3.16.1

React Native version

0.76.2

Platforms

iOS

JavaScript runtime

None

Workflow

React Native

Architecture

Fabric (New Architecture)

Build type

None

Device

iOS simulator

Device model

iPhone 16 (iOS 18)

Acknowledgements

Yes