mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fbf196dd05
commit
5a7799eead
+3
-3
@@ -24,13 +24,13 @@ RCT_EXTERN void RCTTurboModuleSetBindingMode(facebook::react::TurboModuleBinding
|
||||
*/
|
||||
- (Class)getModuleClassFromName:(const char *)name;
|
||||
|
||||
@optional
|
||||
|
||||
/**
|
||||
* Given a module class, provide an instance for it. If not provided, default initializer is used.
|
||||
* Given a module class, provide an instance for it. If nil is returned, default initializer is used.
|
||||
*/
|
||||
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass;
|
||||
|
||||
@optional
|
||||
|
||||
/**
|
||||
* Create an instance of a TurboModule without relying on any ObjC++ module instance.
|
||||
*/
|
||||
|
||||
+6
-20
@@ -478,27 +478,13 @@ static Class getFallbackClassFromName(const char *name)
|
||||
*/
|
||||
|
||||
TurboModulePerfLogger::moduleCreateConstructStart(moduleName, moduleId);
|
||||
if ([_delegate respondsToSelector:@selector(getModuleInstanceFromClass:)]) {
|
||||
if (RCTTurboModuleManagerDelegateLockingDisabled()) {
|
||||
module = [_delegate getModuleInstanceFromClass:moduleClass];
|
||||
} else {
|
||||
std::lock_guard<std::mutex> delegateGuard(_turboModuleManagerDelegateMutex);
|
||||
module = [_delegate getModuleInstanceFromClass:moduleClass];
|
||||
}
|
||||
|
||||
/**
|
||||
* If the application is unable to create the TurboModule object from its class:
|
||||
* abort TurboModule creation, and early return nil.
|
||||
*/
|
||||
if (!module) {
|
||||
RCTLogError(
|
||||
@"TurboModuleManager delegate %@ returned nil TurboModule object for module with name=\"%s\" and class=%@",
|
||||
NSStringFromClass([_delegate class]),
|
||||
moduleName,
|
||||
NSStringFromClass(moduleClass));
|
||||
return nil;
|
||||
}
|
||||
if (RCTTurboModuleManagerDelegateLockingDisabled()) {
|
||||
module = [_delegate getModuleInstanceFromClass:moduleClass];
|
||||
} else {
|
||||
std::lock_guard<std::mutex> delegateGuard(_turboModuleManagerDelegateMutex);
|
||||
module = [_delegate getModuleInstanceFromClass:moduleClass];
|
||||
}
|
||||
if (!module) {
|
||||
module = [moduleClass new];
|
||||
}
|
||||
TurboModulePerfLogger::moduleCreateConstructEnd(moduleName, moduleId);
|
||||
|
||||
Reference in New Issue
Block a user