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