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: 0ebf85755042b7eeaf7af31af541d5a4117116d0
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Jul 7, 2023
1 parent 0ccbd65 commit d3a68a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d3a68a0

Please sign in to comment.