From f67a9cf67e2a10a816d8a10ca76acc35f3b11f8b Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Fri, 10 May 2024 23:58:04 +0800 Subject: [PATCH] Apply suggestions from code review --- .../core/platform/ios/ReactCommon/RCTTurboModule.h | 2 +- .../platform/ios/ReactCommon/RCTTurboModuleManager.mm | 11 ++++------- .../platform/ios/ReactCommon/RCTSampleTurboModule.h | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.h b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.h index a426758a37f35c..075fd2d3477d0f 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.h @@ -166,7 +166,7 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule { /** * Implements this function if a TurboModule needs to install its own JSI bindings. */ -- (RCTTurboModuleBindingsInstaller *)createBindingsInstaller; +- (nonnull RCTTurboModuleBindingsInstaller *)createBindingsInstaller; @end diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm index be37541355ba76..545f73eff3ebbf 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm @@ -306,8 +306,7 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy * (for now). */ -- (std::shared_ptr)provideTurboModule:(const char *)moduleName - withRuntime:(facebook::jsi::Runtime *)runtime +- (std::shared_ptr)provideTurboModule:(const char *)moduleName runtime:(facebook::jsi::Runtime *)runtime { auto turboModuleLookup = _turboModuleCache.find(moduleName); if (turboModuleLookup != _turboModuleCache.end()) { @@ -415,9 +414,7 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy if ([module respondsToSelector:@selector(createBindingsInstaller)]) { RCTTurboModuleBindingsInstaller *installer = (RCTTurboModuleBindingsInstaller *)[module performSelector:@selector(createBindingsInstaller)]; - if (installer != nil) { - installer.get(*runtime); - } + [installer get](*runtime); } return turboModule; } @@ -781,7 +778,7 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass * Attach method queue to id object. * This is necessary because the id object can be eagerly created/initialized before the method * queue is required. The method queue is required for an id for JS -> Native calls. So, we need it - * before we create the id's TurboModule jsi::HostObject in provideTurboModule:. + * before we create the id's TurboModule jsi::HostObject in provideTurboModule:runtime:. */ objc_setAssociatedObject(module, &kAssociatedMethodQueueKey, methodQueue, OBJC_ASSOCIATION_RETAIN); @@ -946,7 +943,7 @@ - (void)installJSBindings:(facebook::jsi::Runtime &)runtime * Additionally, if a TurboModule with the name `name` isn't found, then we * trigger an assertion failure. */ - auto turboModule = [self provideTurboModule:moduleName withRuntime:runtime]; + auto turboModule = [self provideTurboModule:moduleName runtime:runtime]; if (moduleWasNotInitialized && [self moduleIsInitialized:moduleName]) { [self->_bridge.performanceLogger markStopForTag:RCTPLTurboModuleSetup]; diff --git a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.h b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.h index 62d5771e4ae83a..7b25b5a387faf4 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.h +++ b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/ios/ReactCommon/RCTSampleTurboModule.h @@ -16,6 +16,6 @@ */ @interface RCTSampleTurboModule : NSObject -- (RCTTurboModuleBindingsInstaller *)createBindingsInstaller; +- (nonnull RCTTurboModuleBindingsInstaller *)createBindingsInstaller; @end