Skip to content

Commit

Permalink
fix(ios): make getTurboModule return null when module not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Jun 12, 2024
1 parent f201393 commit ad31bfa
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit ad31bfa

Please sign in to comment.