mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Introduce RCTViewRegistry
Summary: ## Problem Many of our NativeModules use the bridge to access the UIManager. They then use the UIManager to call viewForReactTag. This makes all these NativeModules Venice-incompatible. P155700869 ## Solution This diff introduces a Venice-compatible API called RCTViewRegistry that will implement viewForReactTag. When the bridge exists, RCTViewRegistry will delegate to the UIManager. When the bridge doesn't exist, it'll delegate to RCTSurfacePresenter. Fingers crossed, this should allow us move ~50 NativeModuels off the bridge. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D25641391 fbshipit-source-id: 144f4f7a35af1245401ad640068852dd66bbf65d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fb4e06b1a5
commit
fced0765d6
@@ -6,12 +6,14 @@
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <React/RCTDefines.h>
|
||||
|
||||
@class RCTBridge;
|
||||
@protocol RCTBridgeMethod;
|
||||
@class RCTModuleRegistry;
|
||||
@class RCTViewRegistry;
|
||||
|
||||
/**
|
||||
* The type of a block that is capable of sending a response to a bridged
|
||||
@@ -122,6 +124,17 @@ RCT_EXTERN_C_END
|
||||
*/
|
||||
@property (nonatomic, weak, readonly) RCTModuleRegistry *moduleRegistry;
|
||||
|
||||
/**
|
||||
* A reference to the RCTViewRegistry. Useful for modules that query UIViews,
|
||||
* given a react tag. This API is deprecated, and only exists to help migrate
|
||||
* NativeModules to Venice.
|
||||
*
|
||||
* To implement this in your module, just add `@synthesize
|
||||
* viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;`. If using Swift, add
|
||||
* `@objc var viewRegistry_DEPRECATED: RCTViewRegistry!` to your module.
|
||||
*/
|
||||
@property (nonatomic, weak, readonly) RCTViewRegistry *viewRegistry_DEPRECATED;
|
||||
|
||||
/**
|
||||
* A reference to the RCTBridge. Useful for modules that require access
|
||||
* to bridge features, such as sending events or making JS calls. This
|
||||
@@ -392,3 +405,15 @@ RCT_EXTERN_C_END
|
||||
- (id)moduleForName:(const char *)moduleName;
|
||||
- (id)moduleForName:(const char *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyLoad;
|
||||
@end
|
||||
|
||||
typedef UIView * (^RCTBridgelessComponentViewProvider)(NSNumber *);
|
||||
|
||||
/**
|
||||
* A class that allows NativeModules to query for views, given React Tags.
|
||||
*/
|
||||
@interface RCTViewRegistry : NSObject
|
||||
- (void)setBridge:(RCTBridge *)bridge;
|
||||
- (void)setBridgelessComponentViewProvider:(RCTBridgelessComponentViewProvider)bridgelessComponentViewProvider;
|
||||
|
||||
- (UIView *)viewForReactTag:(NSNumber *)reactTag;
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its 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;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user