react-native-reanimated
react-native-reanimated copied to clipboard
[SET] App freeze due to infinite loop when running transition multiple times
Description
There is an issue where getSharedElementForCurrentTransition
can get stuck in an infinite while loop if the transition has been run before. For me it was consistently happening when performing the same transition twice
We created a hacky patch that fixes the crashing issue:
diff --git a/node_modules/react-native-reanimated/apple/LayoutReanimation/REASharedTransitionManager.m b/node_modules/react-native-reanimated/apple/LayoutReanimation/REASharedTransitionManager.m
index 4cc7d02..41a3e6d 100644
--- a/node_modules/react-native-reanimated/apple/LayoutReanimation/REASharedTransitionManager.m
+++ b/node_modules/react-native-reanimated/apple/LayoutReanimation/REASharedTransitionManager.m
@@ -249,11 +249,18 @@ static BOOL _isConfigured = NO;
// find sibling for shared view
NSNumber *siblingViewTag = _findPrecedingViewTagForTransition(sharedView.reactTag);
REAUIView *siblingView = nil;
+
+ // Check if sibling view tag isn't updating
+ int *prevSiblingViewTag = nil;
do {
siblingView = [_animationManager viewForTag:siblingViewTag];
if (siblingView == nil) {
[self clearAllSharedConfigsForViewTag:siblingViewTag];
+ prevSiblingViewTag = siblingViewTag.intValue;
siblingViewTag = _findPrecedingViewTagForTransition(sharedView.reactTag);
+ if(prevSiblingViewTag == siblingViewTag.intValue){
+ break;
+ }
}
} while (siblingView == nil && siblingViewTag != nil);
Steps to reproduce
I have not had time to verify this in a new repo, but here are the steps I went through.
- Create a Native Stack Navigator
- Navigate to new screen while passing the sharedElementTag
navigation.navigate("MainScreen", { screen: "ScreenName", params: { data, sharedTransitionTag } })
- The animation works.
- Go back to
MainScreen
- Trigger the same navigation with the unchanged sharedTransitionTag
- APP FREEZE
Snack or a link to a repository
https://snack.expo.io/
Reanimated version
3.13.0
React Native version
0.73.6
Platforms
iOS
JavaScript runtime
Hermes
Workflow
None
Architecture
Paper (Old Architecture)
Build type
Debug app & production bundle
Device
Real device
Device model
No response
Acknowledgements
Yes