Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): make getTurboModule return null when module not exist #3872

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
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
18 changes: 10 additions & 8 deletions ios/sdk/module/turbo/HippyTurboModuleManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#import "HippyModuleData.h"
#import "HippyBridge+Private.h"
#import "HippyAssert.h"
#import "HippyLog.h"

static NSMutableDictionary<NSString *, Class> *HippyTurboModuleMap;

Expand Down Expand Up @@ -116,26 +117,27 @@ + (BOOL)isTurboModule:(NSString *)name {
}

- (__kindof HippyOCTurboModule *)turboModuleWithName:(NSString *)name {

if (!name || name.length == 0) {
return nil;
}

__kindof HippyOCTurboModule __block * module;
__kindof __block HippyOCTurboModule *turboModule;
dispatch_sync(_cacheQueue, ^{
if ([self.turboModuleCache.allKeys containsObject:name]) {
module = [self.turboModuleCache objectForKey:name];
turboModule = [self.turboModuleCache objectForKey:name];
} else {
Class moduleCls = [HippyTurboModuleMap objectForKey:name] ? : [HippyOCTurboModule class];
Class moduleCls = [HippyTurboModuleMap objectForKey:name];
if ([moduleCls conformsToProtocol:@protocol(HippyTurboModuleImpProtocol)]) {
module = [[moduleCls alloc] initWithName:name bridge:_bridge];
[self.turboModuleCache setObject:module forKey:name];
} else {
turboModule = [[moduleCls alloc] initWithName:name bridge:_bridge];
[self.turboModuleCache setObject:turboModule forKey:name];
} else if (moduleCls) {
HippyAssert(NO, @"moduleClass of %@ is not conformsToProtocol(HippyTurboModuleImpProtocol)!", name);
} else {
HippyLogWarn(@"TurboModule (%@) is not exist!", name);
}
}
});
return module;
return turboModule;
}

- (void)bindJSObject:(JSValue *)jsObj toModuleName:(NSString *)moduleName {
Expand Down
Loading