From 182ce4eb626e8343ba573d9209bcb390c89be6e1 Mon Sep 17 00:00:00 2001 From: ruifanyuan Date: Thu, 30 Nov 2023 11:33:33 +0800 Subject: [PATCH] fix(ios): fix weak ref issue in closure --- renderer/native/ios/renderer/HippyUIManager.mm | 8 ++++---- .../native/ios/renderer/component/view/HippyShadowView.mm | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 7da634d6e0b..9237e0219d5 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -416,10 +416,10 @@ - (void)setFrame:(CGRect)frame forView:(UIView *)view{ } __weak id weakSelf = self; std::vector> ops_ = {[hippyTag, rootTag, weakSelf, frame]() { - if (!weakSelf) { + HippyUIManager *strongSelf = weakSelf; + if (!strongSelf) { return; } - HippyUIManager *strongSelf = weakSelf; HippyShadowView *renderObject = [strongSelf->_shadowViewRegistry componentForTag:hippyTag onRootTag:rootTag]; if (renderObject == nil) { return; @@ -444,10 +444,10 @@ - (void)setFrame:(CGRect)frame forRootView:(UIView *)view { } __weak id weakSelf = self; std::vector> ops_ = {[componentTag, weakSelf, frame]() { - if (!weakSelf) { + HippyUIManager *strongSelf = weakSelf; + if (!strongSelf) { return; } - HippyUIManager *strongSelf = weakSelf; HippyShadowView *renderObject = [strongSelf->_shadowViewRegistry rootComponentForTag:componentTag]; if (renderObject == nil) { return; diff --git a/renderer/native/ios/renderer/component/view/HippyShadowView.mm b/renderer/native/ios/renderer/component/view/HippyShadowView.mm index 42e59869d60..502ceaa9f7c 100644 --- a/renderer/native/ios/renderer/component/view/HippyShadowView.mm +++ b/renderer/native/ios/renderer/component/view/HippyShadowView.mm @@ -329,10 +329,10 @@ - (void)setLayoutFrame:(CGRect)frame dirtyPropagation:(BOOL)dirtyPropagation { __weak HippyShadowView *weakSelf = self; std::vector> ops = {[weakSelf, domManager, frame, dirtyPropagation](){ @autoreleasepool { - if (!weakSelf) { + HippyShadowView *strongSelf = weakSelf; + if (!strongSelf) { return; } - HippyShadowView *strongSelf = weakSelf; int32_t componentTag = [[strongSelf hippyTag] intValue]; auto node = domManager->GetNode(strongSelf.rootNode, componentTag); auto renderManager = domManager->GetRenderManager().lock();