2/3 Make interop WebView component Bridgeless compatible, and make uiManager addUIBlock migration easier

Summary:
Changelog: [iOS] Add `_viewRegistry_DEPRECATED addUIBlock`  to replace `uiManager addUIBlock` for Fabric migration

Allow people to directly replace `uiManager addUIBlock` with `_viewRegistry_DEPRECATED addUIBlock` when they migrate the method in RCTViewManagers.

Currently we add an if check in the RCTViewManager, which makes migration a bit harder for OSS.
```
  if (self.bridge) {
    [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
      work();
    }];
  } else {
    RCTExecuteOnMainQueue(work);
  }
```

Reviewed By: sammy-SC

Differential Revision: D34532609

fbshipit-source-id: 19647fea03be8fd71d8f46dfe216275894d8165c
This commit is contained in:
Paige Sun
2022-03-02 14:09:56 -08:00
committed by Facebook GitHub Bot
parent fc9dec9a35
commit 2c268d7fe6
2 changed files with 27 additions and 0 deletions
+3
View File
@@ -437,6 +437,8 @@ typedef NSURL * (^RCTBridgelessBundleURLGetter)(void);
typedef UIView * (^RCTBridgelessComponentViewProvider)(NSNumber *);
typedef void (^RCTViewRegistryUIBlock)(RCTViewRegistry *viewRegistry);
/**
* A class that allows NativeModules to query for views, given React Tags.
*/
@@ -445,6 +447,7 @@ typedef UIView * (^RCTBridgelessComponentViewProvider)(NSNumber *);
- (void)setBridgelessComponentViewProvider:(RCTBridgelessComponentViewProvider)bridgelessComponentViewProvider;
- (UIView *)viewForReactTag:(NSNumber *)reactTag;
- (void)addUIBlock:(RCTViewRegistryUIBlock)block;
@end
typedef void (^RCTBridgelessJSModuleMethodInvoker)(
+24
View File
@@ -42,4 +42,28 @@
return view;
}
- (void)addUIBlock:(RCTViewRegistryUIBlock)block
{
if (!block) {
return;
}
__weak __typeof(self) weakSelf = self;
if (_bridge) {
[_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
__typeof(self) strongSelf = weakSelf;
if (strongSelf) {
block(strongSelf);
}
}];
} else {
RCTExecuteOnMainQueue(^{
__typeof(self) strongSelf = weakSelf;
if (strongSelf) {
block(strongSelf);
}
});
}
}
@end