fix:when onDestroy call native plugin

This commit is contained in:
pengfei.zhou 2020-04-23 17:42:32 +08:00 committed by osborn
parent 82fdd5e46c
commit 496c4c1838
8 changed files with 34 additions and 19 deletions

View File

@ -163,17 +163,29 @@ public class DoricContext {
} }
public void teardown() { public void teardown() {
callEntity(DoricConstant.DORIC_ENTITY_DESTROY); callEntity(DoricConstant.DORIC_ENTITY_DESTROY).setCallback(new AsyncResult.Callback<JSDecoder>() {
getDriver().asyncCall(new Callable<Object>() {
@Override @Override
public Object call() { public void onResult(JSDecoder result) {
for (DoricJavaPlugin javaPlugin : mPluginMap.values()) {
javaPlugin.onTearDown();
}
mPluginMap.clear();
return null;
} }
}, ThreadMode.UI);
@Override
public void onError(Throwable t) {
}
@Override
public void onFinish() {
getDriver().asyncCall(new Callable<Object>() {
@Override
public Object call() {
for (DoricJavaPlugin javaPlugin : mPluginMap.values()) {
javaPlugin.onTearDown();
}
mPluginMap.clear();
return null;
}
}, ThreadMode.UI);
}
});
DoricContextManager.getInstance().destroyContext(this); DoricContextManager.getInstance().destroyContext(this);
} }

View File

@ -57,7 +57,6 @@ public class DoricContextManager {
} }
AsyncResult<Boolean> destroyContext(final DoricContext context) { AsyncResult<Boolean> destroyContext(final DoricContext context) {
doricContextMap.remove(context.getContextId());
final AsyncResult<Boolean> result = new AsyncResult<>(); final AsyncResult<Boolean> result = new AsyncResult<>();
context.getDriver().destroyContext(context.getContextId()).setCallback(new AsyncResult.Callback<Boolean>() { context.getDriver().destroyContext(context.getContextId()).setCallback(new AsyncResult.Callback<Boolean>() {
@Override @Override
@ -72,6 +71,7 @@ public class DoricContextManager {
@Override @Override
public void onFinish() { public void onFinish() {
doricContextMap.remove(context.getContextId());
} }
}); });
return result; return result;

View File

@ -17,7 +17,6 @@ package pub.doric.shader;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Matrix; import android.graphics.Matrix;

View File

@ -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 { colors, label } from "./utils";
import { img_base64 } from "./image_base64"; import { img_base64 } from "./image_base64";
@ -221,4 +221,7 @@ class ImageDemo extends Panel {
}) })
}).in(rootView) }).in(rootView)
} }
onDestroy() {
modal(context).toast('onDestroy')
}
} }

View File

@ -52,7 +52,6 @@ @implementation DoricJSEngine
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_jsQueue = dispatch_queue_create("doric.jsengine", DISPATCH_QUEUE_SERIAL); _jsQueue = dispatch_queue_create("doric.jsengine", DISPATCH_QUEUE_SERIAL);
_bridgeExtension = [[DoricBridgeExtension alloc] init];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
struct utsname systemInfo; struct utsname systemInfo;
uname(&systemInfo); uname(&systemInfo);
@ -76,6 +75,8 @@ - (instancetype)init {
dispatch_async(_jsQueue, ^() { dispatch_async(_jsQueue, ^() {
self.timers = [[NSMutableDictionary alloc] init]; self.timers = [[NSMutableDictionary alloc] init];
self.registry = [[DoricRegistry alloc] init]; self.registry = [[DoricRegistry alloc] init];
self.bridgeExtension = [DoricBridgeExtension new];
self.bridgeExtension.registry = self.registry;
[self initJSEngine]; [self initJSEngine];
[self initJSExecutor]; [self initJSExecutor];
[self initDoricEnvironment]; [self initDoricEnvironment];

View File

@ -21,10 +21,12 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "DoricRegistry.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricBridgeExtension : NSObject @interface DoricBridgeExtension : NSObject
@property (nonatomic,weak) DoricRegistry *registry;
- (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;
@end @end

View File

@ -34,11 +34,7 @@ @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) { Class pluginClass = [self.registry acquireNativePlugin:module];
return nil;
}
DoricRegistry *registry = context.driver.registry;
Class pluginClass = [registry acquireNativePlugin:module];
DoricNativePlugin *nativePlugin = context.pluginInstanceMap[module]; DoricNativePlugin *nativePlugin = context.pluginInstanceMap[module];
if (nativePlugin == nil) { if (nativePlugin == nil) {
nativePlugin = [(DoricNativePlugin *) [pluginClass alloc] initWithContext:context]; 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]; NSMethodSignature *methodSignature = [target methodSignatureForSelector:selector];
if (methodSignature) { if (methodSignature) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[invocation retainArguments];
invocation.selector = selector; invocation.selector = selector;
invocation.target = target; invocation.target = target;
__weak __typeof__(self) _self = self; __weak __typeof__(self) _self = self;

View File

@ -95,6 +95,7 @@ - (void)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(
NSMethodSignature *methodSignature = [target methodSignatureForSelector:selector]; NSMethodSignature *methodSignature = [target methodSignatureForSelector:selector];
if (methodSignature) { if (methodSignature) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[invocation retainArguments];
invocation.selector = selector; invocation.selector = selector;
invocation.target = target; invocation.target = target;
void *retValue; void *retValue;