Skip to content

Commit

Permalink
have RCTInstance decorate non-app provided turbomodules with bridgele…
Browse files Browse the repository at this point in the history
…ss APIs

Summary:
Changelog: [Internal]

`getModuleInstanceFromClass:` is a delegate method intended to be implemented by the product layer to provide modules. if it is not implemented to return a module for a given key, `RCTTurboModuleManager` will simply call `new` on the TM class.

however, these two paths differentiate - for `getModuleInstanceFromClass:`, we will call `_attachBridgelessAPIsToModule:` which provides objects like surfacePresenter to the native module.

if we fallback to calling `new`, then this attachment does not happen, even if the app has already been migrated to bridgeless modules.

thus, the fix in the case is to lift the fallback into RCTInstance as well, and decorate the APIs onto the new fallback.

Differential Revision: D66675034
  • Loading branch information
philIip authored and facebook-github-bot committed Dec 2, 2024
1 parent fa8a25e commit 1ba4e93
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,19 @@ - (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path

- (Class)getModuleClassFromName:(const char *)name
{
if ([_appTMMDelegate respondsToSelector:@selector(getModuleClassFromName:)]) {
return [_appTMMDelegate getModuleClassFromName:name];
}

return nil;
return [_appTMMDelegate getModuleClassFromName:name];
}

- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
{
if ([_appTMMDelegate respondsToSelector:@selector(getModuleInstanceFromClass:)]) {
id<RCTTurboModule> module = [_appTMMDelegate getModuleInstanceFromClass:moduleClass];
[self _attachBridgelessAPIsToModule:module];
return module;
id<RCTTurboModule> module = [_appTMMDelegate getModuleInstanceFromClass:moduleClass];

if (!module) {
module = [moduleClass new];
}

return nil;
[self _attachBridgelessAPIsToModule:module];
return module;
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
Expand Down

0 comments on commit 1ba4e93

Please sign in to comment.