Skip to content

Commit

Permalink
fix(ios): multi-threading issue in createView
Browse files Browse the repository at this point in the history
and resolve minor issue of duplicate assignment
  • Loading branch information
wwwcg committed May 20, 2024
1 parent 00cd292 commit a21c4dc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -806,9 +805,14 @@ - (void)createRenderNodes:(std::vector<std::shared_ptr<DomNode>> &&)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<NSNumber *,UIView *> *viewRegistry) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
if (!strongSelf) {
return;
}
std::lock_guard<std::mutex> lock([strongSelf renderQueueLock]);
UIView *view = [uiManager createViewFromShadowView:shadowView];
view.hippyShadowView = shadowView;
[view hippySetFrame:shadowView.frame];
if (uiManager && view) {
Expand Down Expand Up @@ -921,8 +925,8 @@ - (void)deleteRenderNodesIds:(std::vector<std::shared_ptr<hippy::DomNode>> &&)no
if (!strongSelf) {
return;
}
NSMutableArray<UIView *> *parentViews = [NSMutableArray arrayWithCapacity:8];
NSMutableArray<UIView *> *views = [NSMutableArray arrayWithCapacity:8];
NSMutableArray<UIView *> *parentViews = [NSMutableArray arrayWithCapacity:strongNodes.size()];
NSMutableArray<UIView *> *views = [NSMutableArray arrayWithCapacity:strongNodes.size()];
for (auto domNode : strongNodes) {
UIView *view = [viewRegistry objectForKey:@(domNode->GetId())];
if (!view) {
Expand Down

0 comments on commit a21c4dc

Please sign in to comment.