mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
2c268d7fe6
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
70 lines
1.5 KiB
Objective-C
70 lines
1.5 KiB
Objective-C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <React/RCTSurfacePresenterStub.h>
|
|
#import <React/RCTUIManager.h>
|
|
|
|
#import "RCTBridge.h"
|
|
#import "RCTBridgeModule.h"
|
|
|
|
@implementation RCTViewRegistry {
|
|
RCTBridgelessComponentViewProvider _bridgelessComponentViewProvider;
|
|
__weak RCTBridge *_bridge;
|
|
}
|
|
|
|
- (void)setBridge:(RCTBridge *)bridge
|
|
{
|
|
_bridge = bridge;
|
|
}
|
|
|
|
- (void)setBridgelessComponentViewProvider:(RCTBridgelessComponentViewProvider)bridgelessComponentViewProvider
|
|
{
|
|
_bridgelessComponentViewProvider = bridgelessComponentViewProvider;
|
|
}
|
|
|
|
- (UIView *)viewForReactTag:(NSNumber *)reactTag
|
|
{
|
|
UIView *view = nil;
|
|
|
|
RCTBridge *bridge = _bridge;
|
|
if (bridge) {
|
|
view = [bridge.uiManager viewForReactTag:reactTag];
|
|
}
|
|
|
|
if (view == nil && _bridgelessComponentViewProvider) {
|
|
view = _bridgelessComponentViewProvider(reactTag);
|
|
}
|
|
|
|
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
|