Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/react-native/React/Base/RCTBundleConsumer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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/RCTJavaScriptLoader.h>

@protocol RCTBundleConsumer <NSObject>

/**
* A reference to the RCTModuleRegistry. Useful for modules that require access
* to other NativeModules. To implement this in your module, just add `@synthesize
* moduleRegistry = _moduleRegistry;`. If using Swift, add
* `@objc var moduleRegistry: RCTModuleRegistry!` to your module.
*/
@property (nonatomic, weak, readwrite) RCTSource *source;

@end
8 changes: 4 additions & 4 deletions packages/react-native/React/Base/RCTJavaScriptLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ NS_ENUM(NSInteger){
/**
* URL of the source object.
*/
@property (strong, nonatomic, readonly) NSURL *url;
@property (strong, nonatomic, readwrite) NSURL *url;

/**
* JS source (or simply the binary header in the case of a RAM bundle).
*/
@property (strong, nonatomic, readonly) NSData *data;
@property (strong, nonatomic, readwrite) NSData *data;

/**
* Length of the entire JS bundle. Note that self.length != self.data.length in the case of certain bundle formats. For
Expand All @@ -56,7 +56,7 @@ NS_ENUM(NSInteger){
* - self.data.length is the length of the bundle header, i.e. sizeof(facebook::react::BundleHeader)
* - self.length is the length of the entire bundle file (header + contents)
*/
@property (nonatomic, readonly) NSUInteger length;
@property (nonatomic, readwrite) NSUInteger length;

/**
* Returns number of files changed when building this bundle:
Expand All @@ -65,7 +65,7 @@ NS_ENUM(NSInteger){
* - RCTSourceFilesChangedCountRebuiltFromScratch if the source was rebuilt from scratch by the bundler
* - Otherwise, the number of files changed when incrementally rebuilding the source
*/
@property (nonatomic, readonly) NSInteger filesChangedCount;
@property (nonatomic, readwrite) NSInteger filesChangedCount;

@end

Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/React/Base/RCTTurboModuleRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <React/RCTBridgeModule.h>

/**
* A protocol that allows TurboModules to do lookup on other TurboModules.
* Calling these methods may cause a module to be synchronously instantiated.
*/
@protocol RCTTurboModuleRegistry <NSObject>
- (id)moduleForName:(const char *)moduleName;
- (NSMutableArray<id<RCTBridgeModule>> *)modulesRespondingToSelector:(SEL)selector;

/**
* Rationale:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ @implementation RCTTurboModuleManager {
dispatch_queue_t _sharedModuleQueue;
}

- (NSMutableArray<id<RCTBridgeModule>> *)modulesRespondingToSelector:(SEL)selector{
id holders = [NSMutableArray new];
for(auto& [name, moduleHolder] : self->_moduleHolders){
id bridgeModule = moduleHolder.getModule();
if([moduleHolder.getModule() respondsToSelector:selector]) {
[holders addObject:bridgeModule];
}
}
return holders;
}

- (instancetype)initWithBridge:(RCTBridge *)bridge
bridgeProxy:(RCTBridgeProxy *)bridgeProxy
bridgeModuleDecorator:(RCTBridgeModuleDecorator *)bridgeModuleDecorator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,19 @@ - (void)_loadJSBundle:(NSURL *)sourceURL
// DevSettings module is needed by _loadScriptFromSource's callback so prior initialization is required
RCTDevSettings *const devSettings =
(RCTDevSettings *)[strongSelf->_turboModuleManager moduleForName:"DevSettings"];

NSString *selectorName = @"setSource:";
SEL selector = NSSelectorFromString(selectorName);
auto respondingModules = [strongSelf->_turboModuleManager modulesRespondingToSelector:(selector)];
for(id bridgeModule in respondingModules) {
RCTSource *sourceCopy = [RCTSource new];
sourceCopy.url = source.url;
sourceCopy.length = source.length;
sourceCopy.data = [source.data copy];
sourceCopy.filesChangedCount = source.filesChangedCount;
[bridgeModule performSelector:selector withObject:sourceCopy];
}

[strongSelf _loadScriptFromSource:source];
// Set up hot module reloading in Dev only.
[strongSelf->_performanceLogger markStopForTag:RCTPLScriptDownload];
Expand Down