fix:when onDestroy call native plugin
This commit is contained in:
parent
82fdd5e46c
commit
496c4c1838
@ -163,7 +163,17 @@ public class DoricContext {
|
||||
}
|
||||
|
||||
public void teardown() {
|
||||
callEntity(DoricConstant.DORIC_ENTITY_DESTROY);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_DESTROY).setCallback(new AsyncResult.Callback<JSDecoder>() {
|
||||
@Override
|
||||
public void onResult(JSDecoder result) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
getDriver().asyncCall(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
@ -174,6 +184,8 @@ public class DoricContext {
|
||||
return null;
|
||||
}
|
||||
}, ThreadMode.UI);
|
||||
}
|
||||
});
|
||||
DoricContextManager.getInstance().destroyContext(this);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,6 @@ public class DoricContextManager {
|
||||
}
|
||||
|
||||
AsyncResult<Boolean> destroyContext(final DoricContext context) {
|
||||
doricContextMap.remove(context.getContextId());
|
||||
final AsyncResult<Boolean> result = new AsyncResult<>();
|
||||
context.getDriver().destroyContext(context.getContextId()).setCallback(new AsyncResult.Callback<Boolean>() {
|
||||
@Override
|
||||
@ -72,6 +71,7 @@ public class DoricContextManager {
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
doricContextMap.remove(context.getContextId());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
@ -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;
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
@ -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];
|
||||
|
@ -21,10 +21,12 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user