From d123baa5f4f036d994d6f726ccc1a5794933faed Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 18 Nov 2019 17:04:00 +0800 Subject: [PATCH] feat:call NativeView's method on UI thread --- .../java/pub/doric/plugin/ShaderPlugin.java | 3 +-- iOS/Pod/Classes/Plugin/DoricShaderPlugin.m | 14 +++----------- iOS/Pod/Classes/Shader/DoricListNode.m | 18 +++++++++++------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java b/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java index a13e75d6..10adc7e7 100644 --- a/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java +++ b/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java @@ -114,7 +114,6 @@ public class ShaderPlugin extends DoricJavaPlugin { name); doricPromise.reject(new JavaValue(errMsg)); } else { - DoricMethod doricMethod = method.getAnnotation(DoricMethod.class); Callable callable = new Callable() { @Override public JavaValue call() throws Exception { @@ -134,7 +133,7 @@ public class ShaderPlugin extends DoricJavaPlugin { } }; AsyncResult asyncResult = getDoricContext().getDriver() - .asyncCall(callable, doricMethod == null ? ThreadMode.INDEPENDENT : doricMethod.thread()); + .asyncCall(callable, ThreadMode.UI); asyncResult.setCallback(new AsyncResult.Callback() { @Override public void onResult(JavaValue result) { diff --git a/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m b/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m index 6a72d78c..73c796e8 100644 --- a/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m +++ b/iOS/Pod/Classes/Plugin/DoricShaderPlugin.m @@ -100,22 +100,14 @@ - (id)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(Do DoricLog(@"CallNative Error:%@", exception.reason); } }; - - const char *retType = methodSignature.methodReturnType; - if (!strcmp(retType, @encode(void))) { - ret = nil; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block); - } else if (!strcmp(retType, @encode(id))) { + dispatch_async(dispatch_get_main_queue(), ^{ void *retValue; block(); [invocation getReturnValue:&retValue]; id returnValue = (__bridge id) retValue; [promise resolve:returnValue]; - } else { - DoricLog(@"Command Error:%@", @"Must return object type"); - ret = nil; - [promise reject:@"Command: Must return object type"]; - } + }); + return ret; } break; } diff --git a/iOS/Pod/Classes/Shader/DoricListNode.m b/iOS/Pod/Classes/Shader/DoricListNode.m index aa06569e..d2f99259 100644 --- a/iOS/Pod/Classes/Shader/DoricListNode.m +++ b/iOS/Pod/Classes/Shader/DoricListNode.m @@ -152,15 +152,19 @@ - (void)callItem:(NSUInteger)position height:(CGFloat)height { } - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId { - for (UITableViewCell *tableViewCell in self.view.visibleCells) { - if ([tableViewCell isKindOfClass:[DoricTableViewCell class]]) { - DoricListItemNode *node = ((DoricTableViewCell *) tableViewCell).doricListItemNode; - if ([viewId isEqualToString:node.viewId]) { - return node; + __block DoricViewNode *ret = nil; + dispatch_sync(dispatch_get_main_queue(), ^{ + for (UITableViewCell *tableViewCell in self.view.visibleCells) { + if ([tableViewCell isKindOfClass:[DoricTableViewCell class]]) { + DoricListItemNode *node = ((DoricTableViewCell *) tableViewCell).doricListItemNode; + if ([viewId isEqualToString:node.viewId]) { + ret = node; + break; + } } } - } - return nil; + }); + return ret; } @end