feat:call NativeView's method on UI thread

This commit is contained in:
pengfei.zhou 2019-11-18 17:04:00 +08:00
parent 99c994b11b
commit d123baa5f4
3 changed files with 15 additions and 20 deletions

View File

@ -114,7 +114,6 @@ public class ShaderPlugin extends DoricJavaPlugin {
name); name);
doricPromise.reject(new JavaValue(errMsg)); doricPromise.reject(new JavaValue(errMsg));
} else { } else {
DoricMethod doricMethod = method.getAnnotation(DoricMethod.class);
Callable<JavaValue> callable = new Callable<JavaValue>() { Callable<JavaValue> callable = new Callable<JavaValue>() {
@Override @Override
public JavaValue call() throws Exception { public JavaValue call() throws Exception {
@ -134,7 +133,7 @@ public class ShaderPlugin extends DoricJavaPlugin {
} }
}; };
AsyncResult<JavaValue> asyncResult = getDoricContext().getDriver() AsyncResult<JavaValue> asyncResult = getDoricContext().getDriver()
.asyncCall(callable, doricMethod == null ? ThreadMode.INDEPENDENT : doricMethod.thread()); .asyncCall(callable, ThreadMode.UI);
asyncResult.setCallback(new AsyncResult.Callback<JavaValue>() { asyncResult.setCallback(new AsyncResult.Callback<JavaValue>() {
@Override @Override
public void onResult(JavaValue result) { public void onResult(JavaValue result) {

View File

@ -100,22 +100,14 @@ - (id)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(Do
DoricLog(@"CallNative Error:%@", exception.reason); DoricLog(@"CallNative Error:%@", exception.reason);
} }
}; };
dispatch_async(dispatch_get_main_queue(), ^{
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))) {
void *retValue; void *retValue;
block(); block();
[invocation getReturnValue:&retValue]; [invocation getReturnValue:&retValue];
id returnValue = (__bridge id) retValue; id returnValue = (__bridge id) retValue;
[promise resolve:returnValue]; [promise resolve:returnValue];
} else { });
DoricLog(@"Command Error:%@", @"Must return object type"); return ret;
ret = nil;
[promise reject:@"Command: Must return object type"];
}
} }
break; break;
} }

View File

@ -152,15 +152,19 @@ - (void)callItem:(NSUInteger)position height:(CGFloat)height {
} }
- (DoricViewNode *)subNodeWithViewId:(NSString *)viewId { - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
for (UITableViewCell *tableViewCell in self.view.visibleCells) { __block DoricViewNode *ret = nil;
if ([tableViewCell isKindOfClass:[DoricTableViewCell class]]) { dispatch_sync(dispatch_get_main_queue(), ^{
DoricListItemNode *node = ((DoricTableViewCell *) tableViewCell).doricListItemNode; for (UITableViewCell *tableViewCell in self.view.visibleCells) {
if ([viewId isEqualToString:node.viewId]) { if ([tableViewCell isKindOfClass:[DoricTableViewCell class]]) {
return node; DoricListItemNode *node = ((DoricTableViewCell *) tableViewCell).doricListItemNode;
if ([viewId isEqualToString:node.viewId]) {
ret = node;
break;
}
} }
} }
} });
return nil; return ret;
} }
@end @end