Skip to content

Commit 5a7799e

Browse files
philIipfacebook-github-bot
authored andcommitted
make getModuleInstanceFromClass: required
Summary: Changelog: [iOS][Breaking] continuing getting rid of optional methods, but this does have a behavioral change. if the delegate does not provide the module instance, then we lazily create it. before we were returning nil, idk why. this will be a breaking change if you have any classes that conform to `RCTTurboModuleManagerDelegate` #saynotoruntimechecks Reviewed By: cipolleschi Differential Revision: D45022139 fbshipit-source-id: 9635332caf3db7bb9306f99ee5c0d577091d38ea
1 parent fbf196d commit 5a7799e

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ RCT_EXTERN void RCTTurboModuleSetBindingMode(facebook::react::TurboModuleBinding
2424
*/
2525
- (Class)getModuleClassFromName:(const char *)name;
2626

27-
@optional
28-
2927
/**
30-
* Given a module class, provide an instance for it. If not provided, default initializer is used.
28+
* Given a module class, provide an instance for it. If nil is returned, default initializer is used.
3129
*/
3230
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass;
3331

32+
@optional
33+
3434
/**
3535
* Create an instance of a TurboModule without relying on any ObjC++ module instance.
3636
*/

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -478,27 +478,13 @@ - (TurboModuleHolder *)_getOrCreateTurboModuleHolder:(const char *)moduleName
478478
*/
479479

480480
TurboModulePerfLogger::moduleCreateConstructStart(moduleName, moduleId);
481-
if ([_delegate respondsToSelector:@selector(getModuleInstanceFromClass:)]) {
482-
if (RCTTurboModuleManagerDelegateLockingDisabled()) {
483-
module = [_delegate getModuleInstanceFromClass:moduleClass];
484-
} else {
485-
std::lock_guard<std::mutex> delegateGuard(_turboModuleManagerDelegateMutex);
486-
module = [_delegate getModuleInstanceFromClass:moduleClass];
487-
}
488-
489-
/**
490-
* If the application is unable to create the TurboModule object from its class:
491-
* abort TurboModule creation, and early return nil.
492-
*/
493-
if (!module) {
494-
RCTLogError(
495-
@"TurboModuleManager delegate %@ returned nil TurboModule object for module with name=\"%s\" and class=%@",
496-
NSStringFromClass([_delegate class]),
497-
moduleName,
498-
NSStringFromClass(moduleClass));
499-
return nil;
500-
}
481+
if (RCTTurboModuleManagerDelegateLockingDisabled()) {
482+
module = [_delegate getModuleInstanceFromClass:moduleClass];
501483
} else {
484+
std::lock_guard<std::mutex> delegateGuard(_turboModuleManagerDelegateMutex);
485+
module = [_delegate getModuleInstanceFromClass:moduleClass];
486+
}
487+
if (!module) {
502488
module = [moduleClass new];
503489
}
504490
TurboModulePerfLogger::moduleCreateConstructEnd(moduleName, moduleId);

0 commit comments

Comments
 (0)