diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 5a388db45be..dd5f2f9df52 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -69,20 +69,6 @@ using DomEvent = hippy::DomEvent; using RootNode = hippy::RootNode; -static NSMutableArray *HippyViewManagerClasses = nil; -NSArray *HippyGetViewManagerClasses(HippyBridge *bridge) { - if (!HippyViewManagerClasses) { - NSArray *classes = bridge.moduleClasses; - NSMutableArray *viewManagerClasses = [NSMutableArray array]; - for (id aClass in classes) { - if ([aClass isSubclassOfClass:HippyViewManager.class]) { - [viewManagerClasses addObject:aClass]; - } - } - HippyViewManagerClasses = viewManagerClasses; - } - return HippyViewManagerClasses; -} using HPViewBinding = std::map, std::vector>>; @@ -206,6 +192,8 @@ @interface HippyUIManager() { @property (atomic, strong) NSMutableDictionary *viewManagers; /// All extra components @property (atomic, strong) NSArray *extraComponents; +/// Cache of all ViewManager classes +@property (nonatomic, strong) NSArray *viewManagerClasses; @end @@ -220,12 +208,13 @@ - (instancetype)initWithBridge:(HippyBridge *)bridge { self = [super init]; if (self) { _bridge = bridge; - [self initContext]; + [self setupContext]; + [self setupViewManagerClassesCacheWithBridge:bridge]; } return self; } -- (void)initContext { +- (void)setupContext { _shadowViewRegistry = [[HippyComponentMap alloc] initWithComponentsReferencedType:HippyComponentReferenceTypeStrong]; _viewRegistry = [[HippyComponentMap alloc] initWithComponentsReferencedType:HippyComponentReferenceTypeWeak]; _viewRegistry.requireInMainThread = YES; @@ -238,6 +227,16 @@ - (void)initContext { HippyScreenSize(); } +- (void)setupViewManagerClassesCacheWithBridge:(HippyBridge *)bridge { + NSMutableArray *viewManagerClasses = [NSMutableArray array]; + for (Class aClass in bridge.moduleClasses) { + if ([aClass isSubclassOfClass:HippyViewManager.class]) { + [viewManagerClasses addObject:aClass]; + } + } + _viewManagerClasses = viewManagerClasses; +} + - (void)invalidate { __weak __typeof(self) weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ @@ -704,8 +703,7 @@ - (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName { } // Second, read the default view manager classes. - HippyBridge *strongBridge = self.bridge; - NSArray *classes = HippyGetViewManagerClasses(strongBridge); + NSArray *classes = self.viewManagerClasses; NSMutableDictionary *defaultViewManagerClasses = [NSMutableDictionary dictionaryWithCapacity:[classes count]]; for (Class cls in classes) { HippyAssert([cls respondsToSelector:@selector(moduleName)],