Skip to content

Commit

Permalink
Use [RCTUIManager viewForReactTag:] instead of viewRegistry to av…
Browse files Browse the repository at this point in the history
…oid infinite loop in `[RCTComponentViewRegistry objectForKey:]` (#5957)

## Summary

This PR fixes the following infinite loop:


![obraz](https://github.com/software-mansion/react-native-reanimated/assets/20516055/196f62a3-1e8b-411f-9d66-3e3946dc406f)

For details, see expo/expo#28531.

## Test plan

1. Build Example app on iOS Paper on 0.74.0
2. Open Bokeh example
3. Go back
4. Reload the app by pressing <kbd>r</kbd> in Metro console
5. Repeat steps 2-4 several times
6. When the app hangs, press pause button in Xcode debugger
  • Loading branch information
tomekzaw authored May 1, 2024
1 parent a8c09ee commit 1c46a97
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions apple/LayoutReanimation/REASwizzledUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ - (RCTViewManagerUIBlock)reanimated_uiBlockWithLayoutUpdateForRootView:(RCTRootS
CGSize contentSize = shadowView.layoutMetrics.frame.size;

RCTExecuteOnMainQueue(^{
NSMutableDictionary<NSNumber *, REAUIView *> *viewRegistry = [self valueForKey:@"_viewRegistry"];
REAUIView *view = viewRegistry[reactTag];
RCTUIManager *uiManager = [self valueForKey:@"_uiManager"];
REAUIView *view = [uiManager viewForReactTag:(NSNumber *)reactTag];
RCTAssert(view != nil, @"view (for ID %@) not found", reactTag);

RCTRootView *rootView = (RCTRootView *)[view superview];
Expand All @@ -245,7 +245,7 @@ - (RCTViewManagerUIBlock)reanimated_uiBlockWithLayoutUpdateForRootView:(RCTRootS
for (NSNumber *reactTag in reactTags) {
RCTFrameData frameData = frameDataArray[index++];

REAUIView *view = viewRegistry[reactTag];
REAUIView *view = [uiManager viewForReactTag:(NSNumber *)reactTag];
CGRect frame = frameData.frame;

UIUserInterfaceLayoutDirection layoutDirection = frameData.layoutDirection;
Expand Down Expand Up @@ -331,7 +331,7 @@ - (RCTViewManagerUIBlock)reanimated_uiBlockWithLayoutUpdateForRootView:(RCTRootS
index = 0;
for (NSNumber *reactTag in reactTags) {
RCTFrameData frameData = frameDataArray[index++];
REAUIView *view = viewRegistry[reactTag];
REAUIView *view = [uiManager viewForReactTag:(NSNumber *)reactTag];
BOOL isNew = frameData.isNew;
CGRect frame = frameData.frame;

Expand Down
2 changes: 1 addition & 1 deletion apple/REANodesManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ - (void)configureUiProps:(nonnull NSSet<NSString *> *)uiPropsSet

- (BOOL)isNativeViewMounted:(NSNumber *)viewTag
{
REAUIView *view = _viewRegistry[viewTag];
REAUIView *view = [_uiManager viewForReactTag:(NSNumber *)viewTag];
if (view.superview != nil) {
return YES;
}
Expand Down

0 comments on commit 1c46a97

Please sign in to comment.