Skip to content

Commit

Permalink
Update when view are added to the ViewRegistry (#38223)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Jul 7, 2023
1 parent 0ccbd65 commit 8d2eec3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Expand Up @@ -24,6 +24,7 @@ - (instancetype)initWithCoordinator:(RCTLegacyViewManagerInteropCoordinator *)co

- (void)dealloc
{
[_coordinator removeViewFromRegistryWithTag:_tag];
[_paperView removeFromSuperview];
[_coordinator removeObserveForTag:_tag];
}
Expand All @@ -39,6 +40,7 @@ - (UIView *)paperView
weakSelf.eventInterceptor(eventName, event);
}
}];
[_coordinator addViewToRegistry:_paperView withTag:_tag];
}
return _paperView;
}
Expand Down
Expand Up @@ -38,6 +38,10 @@ typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic event);
reactTag:(NSInteger)tag
paperView:(UIView *)paperView;

- (void)removeViewFromRegistryWithTag:(NSInteger)tag;

- (void)addViewToRegistry:(UIView *)view withTag:(NSInteger)tag;

@end

NS_ASSUME_NONNULL_END
Expand Up @@ -131,22 +131,19 @@ - (void)handleCommand:(NSString *)commandName
NSArray *newArgs = [@[ [NSNumber numberWithInteger:tag] ] arrayByAddingObjectsFromArray:args];

if (_bridge) {
[self _addViewToRegistry:paperView withTag:tag];
[_bridge.batchedBridge
dispatchBlock:^{
[method invokeWithBridge:self->_bridge module:self->_componentData.manager arguments:newArgs];
[self->_bridge.uiManager setNeedsLayout];
}
queue:RCTGetUIManagerQueue()];
[self _removeViewFromRegistryWithTag:tag];
} else {
// TODO T86826778 - Figure out which queue this should be dispatched to.
[method invokeWithBridge:nil module:self->_componentData.manager arguments:newArgs];
}
}

#pragma mark - Private
- (void)_addViewToRegistry:(UIView *)view withTag:(NSInteger)tag
- (void)addViewToRegistry:(UIView *)view withTag:(NSInteger)tag
{
[self _addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
if ([viewRegistry objectForKey:@(tag)] != NULL) {
Expand All @@ -158,7 +155,7 @@ - (void)_addViewToRegistry:(UIView *)view withTag:(NSInteger)tag
}];
}

- (void)_removeViewFromRegistryWithTag:(NSInteger)tag
- (void)removeViewFromRegistryWithTag:(NSInteger)tag
{
[self _addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
if ([viewRegistry objectForKey:@(tag)] == NULL) {
Expand All @@ -171,6 +168,8 @@ - (void)_removeViewFromRegistryWithTag:(NSInteger)tag
}];
}

#pragma mark - Private

- (void)_addUIBlock:(RCTViewManagerUIBlock)block
{
__weak __typeof__(self) weakSelf = self;
Expand Down

0 comments on commit 8d2eec3

Please sign in to comment.