Skip to content

Commit 8d2eec3

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Update when view are added to the ViewRegistry (#38223)
Summary: Pull Request resolved: #38223 Before this change, the InteropLayer was adding the view to the registry right before invoking a command and right after the command was invoked. This model was too strict as some view commands may have async behaviors that make the lookup in the registry fail. After this change, we are going to register the view when it's created and we are going to remove it when the view is deallocated. ## Changelog: [iOS][Changed] - Update logic to add and remove views in the view registry for the interop layer. Reviewed By: sammy-SC Differential Revision: D47262664 fbshipit-source-id: 503f4e29e03bfc7ad861c1502129822b383ffcc0
1 parent 0ccbd65 commit 8d2eec3

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropCoordinatorAdapter.mm

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ - (instancetype)initWithCoordinator:(RCTLegacyViewManagerInteropCoordinator *)co
2424

2525
- (void)dealloc
2626
{
27+
[_coordinator removeViewFromRegistryWithTag:_tag];
2728
[_paperView removeFromSuperview];
2829
[_coordinator removeObserveForTag:_tag];
2930
}
@@ -39,6 +40,7 @@ - (UIView *)paperView
3940
weakSelf.eventInterceptor(eventName, event);
4041
}
4142
}];
43+
[_coordinator addViewToRegistry:_paperView withTag:_tag];
4244
}
4345
return _paperView;
4446
}

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.h

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic event);
3838
reactTag:(NSInteger)tag
3939
paperView:(UIView *)paperView;
4040

41+
- (void)removeViewFromRegistryWithTag:(NSInteger)tag;
42+
43+
- (void)addViewToRegistry:(UIView *)view withTag:(NSInteger)tag;
44+
4145
@end
4246

4347
NS_ASSUME_NONNULL_END

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.mm

+4-5
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,19 @@ - (void)handleCommand:(NSString *)commandName
131131
NSArray *newArgs = [@[ [NSNumber numberWithInteger:tag] ] arrayByAddingObjectsFromArray:args];
132132

133133
if (_bridge) {
134-
[self _addViewToRegistry:paperView withTag:tag];
135134
[_bridge.batchedBridge
136135
dispatchBlock:^{
137136
[method invokeWithBridge:self->_bridge module:self->_componentData.manager arguments:newArgs];
138137
[self->_bridge.uiManager setNeedsLayout];
139138
}
140139
queue:RCTGetUIManagerQueue()];
141-
[self _removeViewFromRegistryWithTag:tag];
142140
} else {
143141
// TODO T86826778 - Figure out which queue this should be dispatched to.
144142
[method invokeWithBridge:nil module:self->_componentData.manager arguments:newArgs];
145143
}
146144
}
147145

148-
#pragma mark - Private
149-
- (void)_addViewToRegistry:(UIView *)view withTag:(NSInteger)tag
146+
- (void)addViewToRegistry:(UIView *)view withTag:(NSInteger)tag
150147
{
151148
[self _addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
152149
if ([viewRegistry objectForKey:@(tag)] != NULL) {
@@ -158,7 +155,7 @@ - (void)_addViewToRegistry:(UIView *)view withTag:(NSInteger)tag
158155
}];
159156
}
160157

161-
- (void)_removeViewFromRegistryWithTag:(NSInteger)tag
158+
- (void)removeViewFromRegistryWithTag:(NSInteger)tag
162159
{
163160
[self _addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
164161
if ([viewRegistry objectForKey:@(tag)] == NULL) {
@@ -171,6 +168,8 @@ - (void)_removeViewFromRegistryWithTag:(NSInteger)tag
171168
}];
172169
}
173170

171+
#pragma mark - Private
172+
174173
- (void)_addUIBlock:(RCTViewManagerUIBlock)block
175174
{
176175
__weak __typeof__(self) weakSelf = self;

0 commit comments

Comments
 (0)