diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index dce46f6fc5a..f3d54496e60 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -1295,9 +1295,8 @@ - (void)setRootView:(UIView *)rootView { // But one HippyBridge can only have one UIManager. HippyUIManager *uiManager = self.uiManager; if (!uiManager) { - uiManager = [[HippyUIManager alloc] init]; + uiManager = [[HippyUIManager alloc] initWithBridge:self]; [uiManager setDomManager:domManager]; - [uiManager setBridge:self]; self.uiManager = uiManager; } diff --git a/renderer/native/ios/renderer/HippyUIManager.h b/renderer/native/ios/renderer/HippyUIManager.h index 63d88dd132e..f39449098ec 100644 --- a/renderer/native/ios/renderer/HippyUIManager.h +++ b/renderer/native/ios/renderer/HippyUIManager.h @@ -68,7 +68,7 @@ HIPPY_EXTERN NSString *const HippyUIManagerDidEndBatchNotification; @interface HippyUIManager : NSObject /// HippyBridge instance -@property (nonatomic, weak) HippyBridge *bridge; +@property (nonatomic, weak, readonly) HippyBridge *bridge; /// View Registry of all nodes @property (nonatomic, readonly) HippyComponentMap *viewRegistry; @@ -78,6 +78,11 @@ HIPPY_EXTERN NSString *const HippyUIManagerDidEndBatchNotification; /// default is NO. @property (nonatomic, assign) BOOL uiCreationLazilyEnabled; +/// Init method +/// - Parameter bridge: HippyBridge +- (instancetype)initWithBridge:(HippyBridge *)bridge NS_DESIGNATED_INITIALIZER; +- (instancetype)init NS_UNAVAILABLE; ++ (instancetype)new NS_UNAVAILABLE; /// Gets the view associated with a hippyTag. /// - Parameters: diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index cddf92e26d2..5cfd1b514aa 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -206,12 +206,6 @@ @interface HippyUIManager() { -#if HIPPY_DEBUG -@property(nonatomic, assign) std::unordered_map>> domNodesMap; -- (std::shared_ptr)domNodeForTag:(int32_t)dom_tag onRootNode:(int32_t)root_tag; -- (std::vector>)childrenForNodeTag:(int32_t)tag onRootNode:(int32_t)root_tag; -#endif - @end @implementation HippyUIManager @@ -220,9 +214,10 @@ @implementation HippyUIManager #pragma mark Life cycle -- (instancetype)init { +- (instancetype)initWithBridge:(HippyBridge *)bridge { self = [super init]; if (self) { + _bridge = bridge; [self initContext]; } return self; @@ -671,9 +666,8 @@ - (void)updateView:(nonnull NSNumber *)componentTag }]; } -#pragma mark - Render Context Implementation - - (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName { + HippyBridge *strongBridge = self.bridge; if (!_viewManagers) { _viewManagers = [NSMutableDictionary dictionary]; if (_extraComponents) { @@ -686,7 +680,7 @@ - (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName { [_viewManagers setObject:cls forKey:viewName]; } } - NSArray *classes = HippyGetViewManagerClasses(self.bridge); + NSArray *classes = HippyGetViewManagerClasses(strongBridge); NSMutableDictionary *defaultViewManagerClasses = [NSMutableDictionary dictionaryWithCapacity:[classes count]]; for (Class cls in classes) { NSString *viewName = viewNameFromViewManagerClass(cls); @@ -701,7 +695,7 @@ - (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName { id object = [_viewManagers objectForKey:viewName]; if (object_isClass(object)) { HippyViewManager *viewManager = [object new]; - viewManager.bridge = self.bridge; + viewManager.bridge = strongBridge; NSAssert([viewManager isKindOfClass:[HippyViewManager class]], @"Must be a HippyViewManager instance"); [_viewManagers setObject:viewManager forKey:viewName]; object = viewManager; @@ -781,12 +775,6 @@ - (void)createRenderNodes:(std::vector> &&)nodes if (!strongRootNode) { return; } -#if HIPPY_DEBUG - auto &nodeMap = _domNodesMap[strongRootNode->GetId()]; - for (auto node : nodes) { - nodeMap[node->GetId()] = node; - } -#endif NSNumber *rootNodeTag = @(strongRootNode->GetId()); std::lock_guard lock([self renderQueueLock]); NativeRenderViewsRelation *manager = [[NativeRenderViewsRelation alloc] init]; @@ -877,12 +865,6 @@ - (void)updateRenderNodes:(std::vector>&&)nodes if (!strongRootNode) { return; } -#if HIPPY_DEBUG - auto &nodeMap = _domNodesMap[strongRootNode->GetId()]; - for (auto node : nodes) { - nodeMap[node->GetId()] = node; - } -#endif std::lock_guard lock([self renderQueueLock]); NSNumber *rootTag = @(strongRootNode->GetId()); for (const auto &node : nodes) { @@ -909,12 +891,6 @@ - (void)deleteRenderNodesIds:(std::vector> &&)no if (!strongRootNode) { return; } -#if HIPPY_DEBUG - auto &nodeMap = _domNodesMap[strongRootNode->GetId()]; - for (auto node : nodes) { - nodeMap[node->GetId()] = nullptr; - } -#endif std::lock_guard lock([self renderQueueLock]); NSNumber *rootTag = @(strongRootNode->GetId()); NSDictionary *currentRegistry = [_shadowViewRegistry componentsForRootTag:rootTag]; @@ -1508,26 +1484,6 @@ - (void)domEventDidHandle:(const std::string &)eventName forNode:(int32_t)tag on // no op } -#pragma mark Debug Methods -#if HIPPY_DEBUG -- (std::shared_ptr)domNodeForTag:(int32_t)dom_tag onRootNode:(int32_t)root_tag { - auto find = _domNodesMap.find(root_tag); - if (_domNodesMap.end() == find) { - return nullptr; - } - auto map = find->second; - auto domFind = map.find(dom_tag); - if (map.end() == domFind) { - return nullptr; - } - return domFind->second; -} -- (std::vector>)childrenForNodeTag:(int32_t)tag onRootNode:(int32_t)root_tag { - auto node = [self domNodeForTag:tag onRootNode:root_tag]; - return node ? node->GetChildren() : std::vector>{}; -} -#endif - @end