diff --git a/doric-android/doric/src/main/java/pub/doric/DoricContext.java b/doric-android/doric/src/main/java/pub/doric/DoricContext.java index 9d36fcde..33a0e1c7 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContext.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContext.java @@ -163,17 +163,29 @@ public class DoricContext { } public void teardown() { - callEntity(DoricConstant.DORIC_ENTITY_DESTROY); - getDriver().asyncCall(new Callable() { + callEntity(DoricConstant.DORIC_ENTITY_DESTROY).setCallback(new AsyncResult.Callback() { @Override - public Object call() { - for (DoricJavaPlugin javaPlugin : mPluginMap.values()) { - javaPlugin.onTearDown(); - } - mPluginMap.clear(); - return null; + public void onResult(JSDecoder result) { } - }, ThreadMode.UI); + + @Override + public void onError(Throwable t) { + } + + @Override + public void onFinish() { + getDriver().asyncCall(new Callable() { + @Override + public Object call() { + for (DoricJavaPlugin javaPlugin : mPluginMap.values()) { + javaPlugin.onTearDown(); + } + mPluginMap.clear(); + return null; + } + }, ThreadMode.UI); + } + }); DoricContextManager.getInstance().destroyContext(this); } diff --git a/doric-android/doric/src/main/java/pub/doric/DoricContextManager.java b/doric-android/doric/src/main/java/pub/doric/DoricContextManager.java index ec462fc7..a3046720 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContextManager.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContextManager.java @@ -57,7 +57,6 @@ public class DoricContextManager { } AsyncResult destroyContext(final DoricContext context) { - doricContextMap.remove(context.getContextId()); final AsyncResult result = new AsyncResult<>(); context.getDriver().destroyContext(context.getContextId()).setCallback(new AsyncResult.Callback() { @Override @@ -72,6 +71,7 @@ public class DoricContextManager { @Override public void onFinish() { + doricContextMap.remove(context.getContextId()); } }); return result; diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java index 696c3c8d..7d683789 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ImageNode.java @@ -17,7 +17,6 @@ package pub.doric.shader; import android.annotation.SuppressLint; import android.app.Activity; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Matrix; diff --git a/doric-demo/src/ImageDemo.ts b/doric-demo/src/ImageDemo.ts index 667c0b54..e41d4f15 100644 --- a/doric-demo/src/ImageDemo.ts +++ b/doric-demo/src/ImageDemo.ts @@ -1,4 +1,4 @@ -import { Group, Panel, coordinator, text, gravity, Color, LayoutSpec, log, vlayout, scroller, layoutConfig, image, ScaleType, Image } from "doric"; +import { Group, Panel, coordinator, text, gravity, Color, LayoutSpec, log, vlayout, scroller, layoutConfig, image, ScaleType, Image, modal } from "doric"; import { colors, label } from "./utils"; import { img_base64 } from "./image_base64"; @@ -221,4 +221,7 @@ class ImageDemo extends Panel { }) }).in(rootView) } + onDestroy() { + modal(context).toast('onDestroy') + } } \ No newline at end of file diff --git a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m index db91eef2..c874b683 100644 --- a/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/doric-iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -52,7 +52,6 @@ @implementation DoricJSEngine - (instancetype)init { if (self = [super init]) { _jsQueue = dispatch_queue_create("doric.jsengine", DISPATCH_QUEUE_SERIAL); - _bridgeExtension = [[DoricBridgeExtension alloc] init]; NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; struct utsname systemInfo; uname(&systemInfo); @@ -76,6 +75,8 @@ - (instancetype)init { dispatch_async(_jsQueue, ^() { self.timers = [[NSMutableDictionary alloc] init]; self.registry = [[DoricRegistry alloc] init]; + self.bridgeExtension = [DoricBridgeExtension new]; + self.bridgeExtension.registry = self.registry; [self initJSEngine]; [self initJSExecutor]; [self initDoricEnvironment]; diff --git a/doric-iOS/Pod/Classes/Extension/DoricBridgeExtension.h b/doric-iOS/Pod/Classes/Extension/DoricBridgeExtension.h index c510c162..dd865e32 100644 --- a/doric-iOS/Pod/Classes/Extension/DoricBridgeExtension.h +++ b/doric-iOS/Pod/Classes/Extension/DoricBridgeExtension.h @@ -21,10 +21,12 @@ // #import - +#import "DoricRegistry.h" NS_ASSUME_NONNULL_BEGIN @interface DoricBridgeExtension : NSObject +@property (nonatomic,weak) DoricRegistry *registry; + - (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module method:(NSString *)method callbackId:(NSString *)callbackId argument:(id)argument; @end diff --git a/doric-iOS/Pod/Classes/Extension/DoricBridgeExtension.m b/doric-iOS/Pod/Classes/Extension/DoricBridgeExtension.m index d122f521..13b9e1cc 100644 --- a/doric-iOS/Pod/Classes/Extension/DoricBridgeExtension.m +++ b/doric-iOS/Pod/Classes/Extension/DoricBridgeExtension.m @@ -34,11 +34,7 @@ @implementation DoricBridgeExtension - (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module method:(NSString *)method callbackId:(NSString *)callbackId argument:(id)argument { __strong DoricContext *context = [[DoricContextManager instance] getContext:contextId]; - if (!context) { - return nil; - } - DoricRegistry *registry = context.driver.registry; - Class pluginClass = [registry acquireNativePlugin:module]; + Class pluginClass = [self.registry acquireNativePlugin:module]; DoricNativePlugin *nativePlugin = context.pluginInstanceMap[module]; if (nativePlugin == nil) { nativePlugin = [(DoricNativePlugin *) [pluginClass alloc] initWithContext:context]; @@ -72,6 +68,7 @@ - (id)findClass:(Class)clz target:(id)target context:(DoricContext *)context met NSMethodSignature *methodSignature = [target methodSignatureForSelector:selector]; if (methodSignature) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; + [invocation retainArguments]; invocation.selector = selector; invocation.target = target; __weak __typeof__(self) _self = self; diff --git a/doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m index ecbd5d78..3c45fd68 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m @@ -95,6 +95,7 @@ - (void)findClass:(Class)clz target:(id)target method:(NSString *)name promise:( NSMethodSignature *methodSignature = [target methodSignatureForSelector:selector]; if (methodSignature) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; + [invocation retainArguments]; invocation.selector = selector; invocation.target = target; void *retValue;