Skip to content

Commit

Permalink
Update when view are added to the ViewRegistry
Browse files Browse the repository at this point in the history
Summary:
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.

Differential Revision: D47262664

fbshipit-source-id: 737310d99c4fdc3e95869a6f1ecd1836c5854460
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Jul 6, 2023
1 parent f6c91bf commit 9f159c4
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 9f159c4

Please sign in to comment.