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() {
|
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>() {
|
getDriver().asyncCall(new Callable<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public Object call() {
|
public Object call() {
|
||||||
@ -174,6 +184,8 @@ public class DoricContext {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, ThreadMode.UI);
|
}, ThreadMode.UI);
|
||||||
|
}
|
||||||
|
});
|
||||||
DoricContextManager.getInstance().destroyContext(this);
|
DoricContextManager.getInstance().destroyContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -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')
|
||||||
|
}
|
||||||
}
|
}
|
@ -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];
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
Reference in New Issue
Block a user