Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
dc50308
commit 94b1b8a
Showing
5 changed files
with
119 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 "RCTBridgeModule.h" | ||
|
||
@class RCTBundleManager; | ||
@class RCTCallableJSModules; | ||
@class RCTModuleRegistry; | ||
@class RCTViewRegistry; | ||
|
||
/** | ||
RCTBridgeModuleDecorator contains instances that can be intialized with @synthesize | ||
in RCTBridgeModules. For the Fabric interop layer. | ||
In Bridgeless, @synthesize ivars are passed from RCTBridgeModuleDecorator. | ||
In Bridge, @synthesize ivars are passed from RCTModuleData. | ||
*/ | ||
@interface RCTBridgeModuleDecorator : NSObject | ||
@property (nonatomic, strong, readonly) RCTViewRegistry *viewRegistry_DEPRECATED; | ||
@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry; | ||
@property (nonatomic, strong, readonly) RCTBundleManager *bundleManager; | ||
@property (nonatomic, strong, readonly) RCTCallableJSModules *callableJSModules; | ||
|
||
- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry | ||
moduleRegistry:(RCTModuleRegistry *)moduleRegistry | ||
bundleManager:(RCTBundleManager *)bundleManager | ||
callableJSModules:(RCTCallableJSModules *)callableJSModules; | ||
|
||
- (void)attachInteropAPIsToModule:(id<RCTBridgeModule>)bridgeModule; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters