fix iOS crash when call Destory

This commit is contained in:
pengfei.zhou 2020-05-06 17:34:48 +08:00 committed by osborn
parent c9c99cce06
commit 7828b24cd5
12 changed files with 43 additions and 2 deletions

View File

@ -43,6 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, strong) DoricRootNode *rootNode; @property(nonatomic, strong) DoricRootNode *rootNode;
@property(nonatomic, strong) NSMutableDictionary <NSString *, NSMutableDictionary <NSString *, DoricViewNode *> *> *headNodes; @property(nonatomic, strong) NSMutableDictionary <NSString *, NSMutableDictionary <NSString *, DoricViewNode *> *> *headNodes;
@property(nonatomic, copy) NSString *extra; @property(nonatomic, copy) NSString *extra;
@property(nonatomic, assign) BOOL destroyed;
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source extra:(NSString *)extra; - (instancetype)initWithScript:(NSString *)script source:(NSString *)source extra:(NSString *)extra;

View File

@ -60,6 +60,7 @@ - (DoricViewNode *)targetViewNode:(NSString *)viewId {
} }
- (void)dealloc { - (void)dealloc {
_destroyed = YES;
[[DoricContextManager instance] destroyContext:self]; [[DoricContextManager instance] destroyContext:self];
[self callEntity:DORIC_ENTITY_DESTROY withArgumentsArray:@[]]; [self callEntity:DORIC_ENTITY_DESTROY withArgumentsArray:@[]];
[self.driver destroyContext:self.contextId]; [self.driver destroyContext:self.contextId];

View File

@ -34,6 +34,9 @@ @implementation DoricBridgeExtension
- (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module method:(NSString *)method callbackId:(NSString *)callbackId argument:(id)argument { - (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module method:(NSString *)method callbackId:(NSString *)callbackId argument:(id)argument {
__strong DoricContext *context = [[DoricContextManager instance] getContext:contextId]; __strong DoricContext *context = [[DoricContextManager instance] getContext:contextId];
if (context.destroyed) {
return nil;
}
Class pluginClass = [self.registry acquireNativePlugin:module]; Class pluginClass = [self.registry acquireNativePlugin:module];
DoricNativePlugin *nativePlugin = context.pluginInstanceMap[module]; DoricNativePlugin *nativePlugin = context.pluginInstanceMap[module];
if (nativePlugin == nil) { if (nativePlugin == nil) {

View File

@ -35,7 +35,9 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
if (self.doricContext == nil) {
return;
}
NSString *viewId = argument[@"id"]; NSString *viewId = argument[@"id"];
if (self.doricContext.rootNode.viewId == nil && [@"Root" isEqualToString:argument[@"type"]]) { if (self.doricContext.rootNode.viewId == nil && [@"Root" isEqualToString:argument[@"type"]]) {
@ -53,6 +55,9 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
- (void)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise { - (void)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (self.doricContext == nil) {
return;
}
NSArray *viewIds = argument[@"viewIds"]; NSArray *viewIds = argument[@"viewIds"];
id args = argument[@"args"]; id args = argument[@"args"];
NSString *name = argument[@"name"]; NSString *name = argument[@"name"];

View File

@ -946,6 +946,7 @@ function NativeCall(target, propertyKey, descriptor) {
} }
var Panel = /** @class */ (function () { var Panel = /** @class */ (function () {
function Panel() { function Panel() {
this.destroyed = false;
this.__root__ = new Root; this.__root__ = new Root;
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
@ -1002,6 +1003,7 @@ var Panel = /** @class */ (function () {
this.onCreate(); this.onCreate();
}; };
Panel.prototype.__onDestroy__ = function () { Panel.prototype.__onDestroy__ = function () {
this.destroyed = true;
this.onDestroy(); this.onDestroy();
}; };
Panel.prototype.__onShow__ = function () { Panel.prototype.__onShow__ = function () {
@ -1101,6 +1103,9 @@ var Panel = /** @class */ (function () {
Panel.prototype.hookAfterNativeCall = function () { Panel.prototype.hookAfterNativeCall = function () {
var e_4, _a, e_5, _b; var e_4, _a, e_5, _b;
var _this = this; var _this = this;
if (this.destroyed) {
return;
}
var promises = []; var promises = [];
if (Environment.platform !== 'web') { if (Environment.platform !== 'web') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.

View File

@ -701,6 +701,7 @@ function NativeCall(target, propertyKey, descriptor) {
} }
class Panel { class Panel {
constructor() { constructor() {
this.destroyed = false;
this.__root__ = new Root; this.__root__ = new Root;
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
@ -757,6 +758,7 @@ class Panel {
this.onCreate(); this.onCreate();
} }
__onDestroy__() { __onDestroy__() {
this.destroyed = true;
this.onDestroy(); this.onDestroy();
} }
__onShow__() { __onShow__() {
@ -819,6 +821,9 @@ class Panel {
} }
} }
hookAfterNativeCall() { hookAfterNativeCall() {
if (this.destroyed) {
return;
}
const promises = []; const promises = [];
if (Environment.platform !== 'web') { if (Environment.platform !== 'web') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.

View File

@ -2160,6 +2160,7 @@ function NativeCall(target, propertyKey, descriptor) {
} }
class Panel { class Panel {
constructor() { constructor() {
this.destroyed = false;
this.__root__ = new Root; this.__root__ = new Root;
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
@ -2216,6 +2217,7 @@ class Panel {
this.onCreate(); this.onCreate();
} }
__onDestroy__() { __onDestroy__() {
this.destroyed = true;
this.onDestroy(); this.onDestroy();
} }
__onShow__() { __onShow__() {
@ -2278,6 +2280,9 @@ class Panel {
} }
} }
hookAfterNativeCall() { hookAfterNativeCall() {
if (this.destroyed) {
return;
}
const promises = []; const promises = [];
if (Environment.platform !== 'web') { if (Environment.platform !== 'web') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.

View File

@ -3,6 +3,7 @@ import { Root } from '../widget/layouts';
import { BridgeContext } from '../runtime/global'; import { BridgeContext } from '../runtime/global';
export declare function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor; export declare function NativeCall(target: Panel, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
export declare abstract class Panel { export declare abstract class Panel {
private destroyed;
context: BridgeContext; context: BridgeContext;
onCreate(): void; onCreate(): void;
onDestroy(): void; onDestroy(): void;

View File

@ -35,6 +35,7 @@ export function NativeCall(target, propertyKey, descriptor) {
} }
export class Panel { export class Panel {
constructor() { constructor() {
this.destroyed = false;
this.__root__ = new Root; this.__root__ = new Root;
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
@ -91,6 +92,7 @@ export class Panel {
this.onCreate(); this.onCreate();
} }
__onDestroy__() { __onDestroy__() {
this.destroyed = true;
this.onDestroy(); this.onDestroy();
} }
__onShow__() { __onShow__() {
@ -153,6 +155,9 @@ export class Panel {
} }
} }
hookAfterNativeCall() { hookAfterNativeCall() {
if (this.destroyed) {
return;
}
const promises = []; const promises = [];
if (Environment.platform !== 'web') { if (Environment.platform !== 'web') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.

View File

@ -33,6 +33,7 @@ type Frame = { width: number, height: number }
declare function nativeEmpty(): void declare function nativeEmpty(): void
export abstract class Panel { export abstract class Panel {
private destroyed = false
context!: BridgeContext context!: BridgeContext
onCreate() { } onCreate() { }
onDestroy() { } onDestroy() { }
@ -103,6 +104,7 @@ export abstract class Panel {
@NativeCall @NativeCall
private __onDestroy__() { private __onDestroy__() {
this.destroyed = true
this.onDestroy() this.onDestroy()
} }
@ -175,6 +177,9 @@ export abstract class Panel {
} }
private hookAfterNativeCall() { private hookAfterNativeCall() {
if (this.destroyed) {
return
}
const promises: Promise<any>[] = [] const promises: Promise<any>[] = []
if (Environment.platform !== 'web') { if (Environment.platform !== 'web') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.

View File

@ -2218,6 +2218,7 @@ function NativeCall(target, propertyKey, descriptor) {
} }
class Panel { class Panel {
constructor() { constructor() {
this.destroyed = false;
this.__root__ = new Root; this.__root__ = new Root;
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
@ -2274,6 +2275,7 @@ class Panel {
this.onCreate(); this.onCreate();
} }
__onDestroy__() { __onDestroy__() {
this.destroyed = true;
this.onDestroy(); this.onDestroy();
} }
__onShow__() { __onShow__() {
@ -2336,6 +2338,9 @@ class Panel {
} }
} }
hookAfterNativeCall() { hookAfterNativeCall() {
if (this.destroyed) {
return;
}
const promises = []; const promises = [];
if (Environment.platform !== 'web') { if (Environment.platform !== 'web') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.

File diff suppressed because one or more lines are too long