From a21c4dcb750d512373cf6d7070e45ddb75110ced Mon Sep 17 00:00:00 2001 From: wwwcg Date: Mon, 13 May 2024 15:03:05 +0800 Subject: [PATCH] fix(ios): multi-threading issue in createView and resolve minor issue of duplicate assignment --- renderer/native/ios/renderer/HippyUIManager.mm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 1bf2deedb4b..0df1bd9691f 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -522,6 +522,7 @@ - (UIView *)createViewFromShadowView:(HippyShadowView *)shadowView { // 2. then, set necessary properties for this view. view.viewName = viewName; view.rootTag = rootTag; + view.hippyShadowView = shadowView; view.renderManager = [self renderManager]; [componentData setProps:props forView:view]; // Must be done before bgColor to prevent wrong default } @@ -602,9 +603,7 @@ - (UIView *)createViewRecursiveFromRenderObjectWithNOLock:(HippyShadowView *)sha index++; } - // set necessary properties and update frame - view.hippyShadowView = shadowView; - view.renderManager = [self renderManager]; + // finally, update frame [view hippySetFrame:shadowView.frame]; [view clearSortedSubviews]; @@ -806,9 +805,14 @@ - (void)createRenderNodes:(std::vector> &&)nodes NSNumber *componentTag = @(node->GetId()); HippyShadowView *shadowView = [_shadowViewRegistry componentForTag:componentTag onRootTag:rootNodeTag]; if (HippyCreationTypeInstantly == [shadowView creationType] && !_uiCreationLazilyEnabled) { + __weak __typeof(self)weakSelf = self; [self addUIBlock:^(HippyUIManager *uiManager, __unused NSDictionary *viewRegistry) { + __strong __typeof(weakSelf)strongSelf = weakSelf; + if (!strongSelf) { + return; + } + std::lock_guard lock([strongSelf renderQueueLock]); UIView *view = [uiManager createViewFromShadowView:shadowView]; - view.hippyShadowView = shadowView; [view hippySetFrame:shadowView.frame]; if (uiManager && view) { @@ -921,8 +925,8 @@ - (void)deleteRenderNodesIds:(std::vector> &&)no if (!strongSelf) { return; } - NSMutableArray *parentViews = [NSMutableArray arrayWithCapacity:8]; - NSMutableArray *views = [NSMutableArray arrayWithCapacity:8]; + NSMutableArray *parentViews = [NSMutableArray arrayWithCapacity:strongNodes.size()]; + NSMutableArray *views = [NSMutableArray arrayWithCapacity:strongNodes.size()]; for (auto domNode : strongNodes) { UIView *view = [viewRegistry objectForKey:@(domNode->GetId())]; if (!view) {