format OC code

This commit is contained in:
pengfei.zhou
2019-10-12 14:48:19 +08:00
parent 820f1e9f8c
commit f9b599e7cf
43 changed files with 493 additions and 472 deletions

View File

@@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoricBridgeExtension : NSObject
- (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
NS_ASSUME_NONNULL_END

View File

@@ -23,33 +23,33 @@ - (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module me
DoricRegistry *registry = context.driver.registry;
Class pluginClass = [registry acquireNativePlugin:module];
DoricNativePlugin *nativePlugin = [context.pluginInstanceMap objectForKey:module];
if(nativePlugin == nil) {
if (nativePlugin == nil) {
nativePlugin = [[pluginClass alloc] initWithContext:context];
[context.pluginInstanceMap setObject:nativePlugin forKey:module];
}
unsigned int count;
id ret = nil;
Method *methods = class_copyMethodList(pluginClass, &count);
for (int i=0; i < count; i++) {
for (int i = 0; i < count; i++) {
NSString *methodName = [NSString stringWithCString:sel_getName(method_getName(methods[i])) encoding:NSUTF8StringEncoding];
NSArray *array = [methodName componentsSeparatedByString:@":"];
if(array && [array count]>0) {
if([array[0] isEqualToString:method]) {
if (array && [array count] > 0) {
if ([array[0] isEqualToString:method]) {
SEL selector = NSSelectorFromString(methodName);
NSMethodSignature *methodSignature = [nativePlugin methodSignatureForSelector:selector];
if (methodSignature) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
invocation.selector = selector;
invocation.target = nativePlugin;
__weak __typeof__ (self) _self = self;
void(^block)(void) = ^(){
__strong __typeof__ (_self) self = _self;
__weak __typeof__(self) _self = self;
void (^block)(void) = ^() {
__strong __typeof__(_self) self = _self;
@try {
for(int i = 2;i < methodSignature.numberOfArguments;i++) {
if(i-2 > [array count]) {
for (int i = 2; i < methodSignature.numberOfArguments; i++) {
if (i - 2 > [array count]) {
break;
}
id args = [self createParamWithMethodName:array[i-2] context:context callbackId:callbackId argument:argument];
id args = [self createParamWithMethodName:array[i - 2] context:context callbackId:callbackId argument:argument];
[invocation setArgument:&args atIndex:i];
}
[invocation invoke];
@@ -57,16 +57,16 @@ - (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module me
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);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
} else if (!strcmp(retType, @encode(id))) {
void *retValue;
block();
[invocation getReturnValue:&retValue];
id returnValue = (__bridge id)retValue;
id returnValue = (__bridge id) retValue;
ret = [JSValue valueWithObject:[returnValue copy] inContext:[JSContext currentContext]];
} else {
DoricLog(@"CallNative Error:%@", @"Must return object type");
@@ -83,8 +83,8 @@ - (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module me
return ret;
}
- (id) createParamWithMethodName:(NSString *)method context:(DoricContext *)context callbackId:(NSString *)callbackId argument:(id)argument {
if([method isEqualToString:@"withPromise"]){
- (id)createParamWithMethodName:(NSString *)method context:(DoricContext *)context callbackId:(NSString *)callbackId argument:(id)argument {
if ([method isEqualToString:@"withPromise"]) {
return [[DoricPromise alloc] initWithContext:context callbackId:callbackId];
}
return argument;