From f4fcb981b4955652560113bde05252746cc248c6 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 1 Aug 2022 15:30:31 +0800 Subject: [PATCH] iOS: optimize hot reload operation which causes render error --- doric-iOS/Pod/Classes/DoricContext.m | 16 ++++++++++------ doric-iOS/Pod/Classes/Plugin/DoricPromise.m | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doric-iOS/Pod/Classes/DoricContext.m b/doric-iOS/Pod/Classes/DoricContext.m index 79af29c9..32616c77 100644 --- a/doric-iOS/Pod/Classes/DoricContext.m +++ b/doric-iOS/Pod/Classes/DoricContext.m @@ -107,18 +107,22 @@ - (void)build:(CGSize)size { } - (void)reload:(NSString *)script { - [self.driver destroyContext:self.contextId]; + [[self.driver destroyContext:self.contextId] waitUntilResult]; self.rootNode.viewId = nil; [self.rootNode clearSubModel]; [self.rootNode.view.subviews forEach:^(__kindof UIView *obj) { [obj removeFromSuperview]; }]; self.script = script; - [self.driver createContext:self.contextId script:script source:self.source]; - [self init:self.extra]; - [self callEntity:DORIC_ENTITY_CREATE withArgumentsArray:@[]]; - [self callEntity:DORIC_ENTITY_BUILD withArgumentsArray:@[self.initialParams]]; - [self onShow]; + _destroyed = YES; + [self dispatchToMainQueue:^{ + _destroyed = NO; + [self.driver createContext:self.contextId script:script source:self.source]; + [self init:self.extra]; + [self callEntity:DORIC_ENTITY_CREATE withArgumentsArray:@[]]; + [self callEntity:DORIC_ENTITY_BUILD withArgumentsArray:@[self.initialParams]]; + [self onShow]; + }]; } - (void)onShow { diff --git a/doric-iOS/Pod/Classes/Plugin/DoricPromise.m b/doric-iOS/Pod/Classes/Plugin/DoricPromise.m index 72fb20b4..4d2bf447 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricPromise.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricPromise.m @@ -41,7 +41,7 @@ - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)c - (void)resolve:(id)result { __weak typeof(self) __self = self; - if (self.context == nil) { + if (self.context == nil || self.context.destroyed) { return; } [[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE @@ -58,7 +58,7 @@ - (void)resolve:(id)result { - (void)reject:(id)result { __weak typeof(self) __self = self; - if (self.context == nil) { + if (self.context == nil || self.context.destroyed) { return; } [[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT