Files
react-native/React/Base/RCTBridgeModuleDecorator.m
T
Paige Sun 94b1b8a573 1/5 Refactor CxxBridge: Introduce RCTBridgeModuleDecorator to attach @synthesize ivars to RCTTurboModules, in Bridge mode
Summary:
Changelog: [iOS][Internal] Refactor CxxBridge: Introduce RCTBridgeModuleDecorator to attach synthesize ivars to RCTTurboModules, in Bridge mode

This doesn't change any logic. RCTBridgeModuleDecorator was created to consolidate several nearly identical implementations of the `attachInteropAPIsToModule` method to one place.

Most importantly, it allows us to attach interop APIs in RCTBridgeModuleDecorator to RCTViewManagers in diff 4/4, using  `attachInteropAPIsToModule`. Before this stack, these four synthesize ivars in RCTViewManagers are nil in Bridgeless mode, and point to instances in Bridge mode.

# Context
These are used in RCTBridgeModules to access APIs for view managers. These APIs are necessary and compatible with Bridgeless mode.

*  synthesize viewRegistry_DEPRECATED
*  synthesize bundleManager
*  synthesize callableJSModules
*  synthesize moduleRegistry

Reviewed By: RSNara

Differential Revision: D34437802

fbshipit-source-id: b773d511cf877d4896436fabf4893c978e5f8dd9
2022-02-25 08:50:34 -08:00

74 lines
2.4 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.
*/
#include "RCTBridgeModuleDecorator.h"
@implementation RCTBridgeModuleDecorator
- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
bundleManager:(RCTBundleManager *)bundleManager
callableJSModules:(RCTCallableJSModules *)callableJSModules
{
if (self = [super init]) {
_viewRegistry_DEPRECATED = viewRegistry;
_moduleRegistry = moduleRegistry;
_bundleManager = bundleManager;
_callableJSModules = callableJSModules;
}
return self;
}
- (void)attachInteropAPIsToModule:(id<RCTBridgeModule>)bridgeModule
{
/**
* Attach the RCTViewRegistry to this TurboModule, which allows this TurboModule
* To query a React component's UIView, given its reactTag.
*
* Usage: In the TurboModule @implementation, include:
* `@synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED`
*/
if ([bridgeModule respondsToSelector:@selector(setViewRegistry_DEPRECATED:)]) {
bridgeModule.viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;
}
/**
* Attach the RCTBundleManager to this TurboModule, which allows this TurboModule to
* read from/write to the app's bundle URL.
*
* Usage: In the TurboModule @implementation, include:
* `@synthesize bundleManager = _bundleManager`
*/
if ([bridgeModule respondsToSelector:@selector(setBundleManager:)]) {
bridgeModule.bundleManager = _bundleManager;
}
/**
* Attach the RCTCallableJSModules to this TurboModule, which allows this TurboModule
* to call JS Module methods.
*
* Usage: In the TurboModule @implementation, include:
* `@synthesize callableJSModules = _callableJSModules`
*/
if ([bridgeModule respondsToSelector:@selector(setCallableJSModules:)]) {
bridgeModule.callableJSModules = _callableJSModules;
}
/**
* Attach the RCTModuleRegistry to this TurboModule, which allows this TurboModule
* to require other TurboModules/NativeModules.
*
* Usage: In the TurboModule @implementation, include:
* `@synthesize moduleRegistry = _moduleRegistry`
*/
if ([bridgeModule respondsToSelector:@selector(setModuleRegistry:)]) {
bridgeModule.moduleRegistry = _moduleRegistry;
}
}
@end