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

1
iOS/Example/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea/

View File

@ -15,11 +15,11 @@
#include <net/if.h> #include <net/if.h>
#include <ifaddrs.h> #include <ifaddrs.h>
typedef id (^ServerHandler)(GCDWebServerRequest * request); typedef id (^ServerHandler)(GCDWebServerRequest *request);
@interface DoricLocalServer() @interface DoricLocalServer ()
@property (nonatomic, strong) GCDWebServer *server; @property(nonatomic, strong) GCDWebServer *server;
@property (nonatomic, strong) NSMutableDictionary *handlers; @property(nonatomic, strong) NSMutableDictionary *handlers;
@end @end
@implementation DoricLocalServer @implementation DoricLocalServer
@ -36,14 +36,14 @@ - (instancetype)init {
- (NSString *)localIPAddress { - (NSString *)localIPAddress {
NSString *localIP = nil; NSString *localIP = nil;
struct ifaddrs *addrs; struct ifaddrs *addrs;
if (getifaddrs(&addrs)==0) { if (getifaddrs(&addrs) == 0) {
const struct ifaddrs *cursor = addrs; const struct ifaddrs *cursor = addrs;
while (cursor != NULL) { while (cursor != NULL) {
if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0) { if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0) {
//NSString *name = [NSString stringWithUTF8String:cursor->ifa_name]; //NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
//if ([name isEqualToString:@"en0"]) // Wi-Fi adapter //if ([name isEqualToString:@"en0"]) // Wi-Fi adapter
{ {
localIP = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)]; localIP = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *) cursor->ifa_addr)->sin_addr)];
break; break;
} }
} }
@ -65,7 +65,7 @@ - (GCDWebServerResponse *)handleRequest:(GCDWebServerRequest *)request {
return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>It's a API request.</p></body></html>"]; return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>It's a API request.</p></body></html>"];
} }
NSBundle *bundle = DoricBundle(); NSBundle *bundle = DoricBundle();
NSString *filePath = [NSString stringWithFormat:@"%@/dist%@",bundle.bundlePath,request.path]; NSString *filePath = [NSString stringWithFormat:@"%@/dist%@", bundle.bundlePath, request.path];
NSData *data = [NSData dataWithContentsOfFile:filePath]; NSData *data = [NSData dataWithContentsOfFile:filePath];
NSURL *url = [NSURL fileURLWithPath:filePath]; NSURL *url = [NSURL fileURLWithPath:filePath];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
@ -78,38 +78,38 @@ - (void)configurate {
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
[self.server addDefaultHandlerForMethod:@"GET" [self.server addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class] requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse * (GCDWebServerRequest * request) { processBlock:^GCDWebServerResponse *(GCDWebServerRequest *request) {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
return [self handleRequest:request]; return [self handleRequest:request];
}];
[self.handlers setObject:^id(GCDWebServerRequest *request) {
NSMutableArray *array = [[NSMutableArray alloc] init];
for(NSValue *value in [[DoricContextManager instance] aliveContexts]) {
DoricContext *context = value.nonretainedObjectValue;
[array addObject:@{
@"source":context.source,
@"id":context.contextId,
}]; }];
} [self.handlers setObject:^id(GCDWebServerRequest *request) {
return array; NSMutableArray *array = [[NSMutableArray alloc] init];
}
for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
DoricContext *context = value.nonretainedObjectValue;
[array addObject:@{
@"source": context.source,
@"id": context.contextId,
}];
}
return array;
}
forKey:@"allContexts"]; forKey:@"allContexts"];
[self.handlers setObject:^id(GCDWebServerRequest *request) { [self.handlers setObject:^id(GCDWebServerRequest *request) {
NSString *contextId = [request.query objectForKey:@"id"]; NSString *contextId = [request.query objectForKey:@"id"];
DoricContext *context = [[DoricContextManager instance] getContext:contextId]; DoricContext *context = [[DoricContextManager instance] getContext:contextId];
return @{ return @{
@"id":context.contextId, @"id": context.contextId,
@"source":context.source, @"source": context.source,
@"script":context.script @"script": context.script
}; };
} }
forKey:@"context"]; forKey:@"context"];
} }
- (void)startWithPort:(NSUInteger)port { - (void)startWithPort:(NSUInteger)port {
[self.server startWithPort:port bonjourName:nil]; [self.server startWithPort:port bonjourName:nil];
DoricLog(@"Start Server At %@:%d",[self localIPAddress],port); DoricLog(@"Start Server At %@:%d", [self localIPAddress], port);
} }
@end @end

View File

@ -10,19 +10,20 @@
#import "DoricUtil.h" #import "DoricUtil.h"
#import "DoricContextManager.h" #import "DoricContextManager.h"
@interface DoricWSClient()<SRWebSocketDelegate> @interface DoricWSClient () <SRWebSocketDelegate>
@property (nonatomic,strong) SRWebSocket *websocket; @property(nonatomic, strong) SRWebSocket *websocket;
@end @end
@implementation DoricWSClient @implementation DoricWSClient
- (instancetype)initWithUrl:(NSString *)url { - (instancetype)initWithUrl:(NSString *)url {
if(self = [super init]) { if (self = [super init]) {
_websocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:url]]; _websocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:url]];
_websocket.delegate = self; _websocket.delegate = self;
[_websocket open]; [_websocket open];
} }
return self; return self;
} }
- (void)webSocketDidOpen:(SRWebSocket *)webSocket { - (void)webSocketDidOpen:(SRWebSocket *)webSocket {
DoricLog(@"webSocketDidOpen"); DoricLog(@"webSocketDidOpen");
} }
@ -37,15 +38,15 @@ - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers options:NSJSONReadingMutableContainers
error:&err]; error:&err];
if(err) { if (err) {
DoricLog(@"webSocketdidReceiveMessage parse error%@",err); DoricLog(@"webSocketdidReceiveMessage parse error%@", err);
return; return;
} }
NSString *source = [[dic valueForKey:@"source"] mutableCopy]; NSString *source = [[dic valueForKey:@"source"] mutableCopy];
NSString *script = [dic valueForKey:@"script"]; NSString *script = [dic valueForKey:@"script"];
for(NSValue *value in [[DoricContextManager instance] aliveContexts]) { for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
DoricContext *context = value.nonretainedObjectValue; DoricContext *context = value.nonretainedObjectValue;
if([source containsString:context.source]) { if ([source containsString:context.source]) {
[context reload:script]; [context reload:script];
} }
} }

View File

@ -14,13 +14,13 @@ NS_ASSUME_NONNULL_BEGIN
@interface DoricContext : NSObject @interface DoricContext : NSObject
@property (nonatomic,strong) NSString *contextId; @property(nonatomic, strong) NSString *contextId;
@property (nonatomic,strong) DoricDriver *driver; @property(nonatomic, strong) DoricDriver *driver;
@property (nonatomic,strong) NSMutableDictionary *pluginInstanceMap; @property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
@property (nonatomic,strong) DoricRootNode *rootNode; @property(nonatomic, strong) DoricRootNode *rootNode;
@property (nonatomic,strong) NSString *source; @property(nonatomic, strong) NSString *source;
@property (nonatomic,strong) NSString *script;; @property(nonatomic, strong) NSString *script;;
@property (nonatomic,strong) NSDictionary *initialParams; @property(nonatomic, strong) NSDictionary *initialParams;
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source; - (instancetype)initWithScript:(NSString *)script source:(NSString *)source;

View File

@ -13,21 +13,21 @@
@implementation DoricContext @implementation DoricContext
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source { - (instancetype)initWithScript:(NSString *)script source:(NSString *)source {
if(self = [super init]){ if (self = [super init]) {
_driver = [DoricDriver instance]; _driver = [DoricDriver instance];
_pluginInstanceMap = [[NSMutableDictionary alloc] init]; _pluginInstanceMap = [[NSMutableDictionary alloc] init];
[[DoricContextManager instance] createContext:self script:script source:source]; [[DoricContextManager instance] createContext:self script:script source:source];
_rootNode = [[DoricRootNode alloc] initWithContext:self]; _rootNode = [[DoricRootNode alloc] initWithContext:self];
_script = script; _script = script;
_source = source; _source = source;
_initialParams =[@{@"width":@(LAYOUT_MATCH_PARENT) ,@"height":@(LAYOUT_MATCH_PARENT)} mutableCopy]; _initialParams = [@{@"width": @(LAYOUT_MATCH_PARENT), @"height": @(LAYOUT_MATCH_PARENT)} mutableCopy];
[self callEntity:DORIC_ENTITY_CREATE,nil]; [self callEntity:DORIC_ENTITY_CREATE, nil];
} }
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
[self callEntity:DORIC_ENTITY_DESTROY,nil]; [self callEntity:DORIC_ENTITY_DESTROY, nil];
[[DoricContextManager instance] destroyContext:self]; [[DoricContextManager instance] destroyContext:self];
} }
@ -50,21 +50,21 @@ - (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray
- (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height { - (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height {
[self.initialParams setValue:@(width) forKey:@"width"]; [self.initialParams setValue:@(width) forKey:@"width"];
[self.initialParams setValue:@(height) forKey:@"height"]; [self.initialParams setValue:@(height) forKey:@"height"];
[self callEntity:DORIC_ENTITY_INIT,self.initialParams,nil]; [self callEntity:DORIC_ENTITY_INIT, self.initialParams, nil];
} }
- (void)reload:(NSString *)script { - (void)reload:(NSString *)script {
self.script = script; self.script = script;
[self.driver createContext:self.contextId script:script source:self.source]; [self.driver createContext:self.contextId script:script source:self.source];
[self callEntity:DORIC_ENTITY_INIT,self.initialParams,nil]; [self callEntity:DORIC_ENTITY_INIT, self.initialParams, nil];
} }
- (void)onShow { - (void)onShow {
[self callEntity:DORIC_ENTITY_SHOW,nil]; [self callEntity:DORIC_ENTITY_SHOW, nil];
} }
- (void)onHidden { - (void)onHidden {
[self callEntity:DORIC_ENTITY_HIDDEN,nil]; [self callEntity:DORIC_ENTITY_HIDDEN, nil];
} }
@end @end

View File

@ -7,10 +7,11 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "DoricContext.h" #import "DoricContext.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricContextHolder : NSObject @interface DoricContextHolder : NSObject
@property (nonatomic,strong) DoricContext *doricContext; @property(nonatomic, strong) DoricContext *doricContext;
- (instancetype)initWithContext:(DoricContext *)doricContext; - (instancetype)initWithContext:(DoricContext *)doricContext;

View File

@ -10,7 +10,7 @@
@implementation DoricContextHolder @implementation DoricContextHolder
- (instancetype)initWithContext:(DoricContext *)doricContext { - (instancetype)initWithContext:(DoricContext *)doricContext {
if(self = [super init]){ if (self = [super init]) {
_doricContext = doricContext; _doricContext = doricContext;
} }
return self; return self;

View File

@ -8,17 +8,17 @@
#import "DoricContextManager.h" #import "DoricContextManager.h"
#import "DoricContext.h" #import "DoricContext.h"
@interface DoricContextManager() @interface DoricContextManager ()
@property (nonatomic) NSInteger counter; @property(nonatomic) NSInteger counter;
@property (nonatomic,strong) NSMutableDictionary *doricContextMap; @property(nonatomic, strong) NSMutableDictionary *doricContextMap;
@property (nonatomic,strong) dispatch_queue_t mapQueue; @property(nonatomic, strong) dispatch_queue_t mapQueue;
@end @end
@implementation DoricContextManager @implementation DoricContextManager
- (instancetype)init { - (instancetype)init {
if(self = [super init]){ if (self = [super init]) {
_doricContextMap = [[NSMutableDictionary alloc] init]; _doricContextMap = [[NSMutableDictionary alloc] init];
_counter = 0; _counter = 0;
_mapQueue = dispatch_queue_create("doric.contextmap", DISPATCH_QUEUE_SERIAL); _mapQueue = dispatch_queue_create("doric.contextmap", DISPATCH_QUEUE_SERIAL);
@ -26,7 +26,7 @@ - (instancetype)init {
return self; return self;
} }
+ (instancetype)instance{ + (instancetype)instance {
static DoricContextManager *_instance; static DoricContextManager *_instance;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
@ -36,9 +36,9 @@ + (instancetype)instance{
} }
- (void)createContext:(DoricContext *)context script:(NSString *)script source:(NSString *)source { - (void)createContext:(DoricContext *)context script:(NSString *)script source:(NSString *)source {
context.contextId = [NSString stringWithFormat:@"%ld", (long)self.counter++]; context.contextId = [NSString stringWithFormat:@"%ld", (long) self.counter++];
[context.driver createContext:context.contextId script:script source:source]; [context.driver createContext:context.contextId script:script source:source];
dispatch_sync(self.mapQueue, ^(){ dispatch_sync(self.mapQueue, ^() {
NSValue *value = [NSValue valueWithNonretainedObject:context]; NSValue *value = [NSValue valueWithNonretainedObject:context];
[self.doricContextMap setValue:value forKey:context.contextId]; [self.doricContextMap setValue:value forKey:context.contextId];
}); });
@ -56,7 +56,7 @@ - (DoricContext *)getContext:(NSString *)contextId {
- (void)destroyContext:(DoricContext *)context { - (void)destroyContext:(DoricContext *)context {
NSString *contextId = context.contextId; NSString *contextId = context.contextId;
[context.driver destroyContext:contextId].finishCallback = ^{ [context.driver destroyContext:contextId].finishCallback = ^{
dispatch_sync(self.mapQueue, ^(){ dispatch_sync(self.mapQueue, ^() {
[self.doricContextMap removeObjectForKey:contextId]; [self.doricContextMap removeObjectForKey:contextId];
}); });
}; };

View File

@ -18,19 +18,24 @@ typedef NS_ENUM(NSInteger, QueueMode) {
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricDriver : NSObject @interface DoricDriver : NSObject
+ (instancetype) instance; + (instancetype)instance;
@property (nonatomic,strong) DoricRegistry *registry; @property(nonatomic, strong) DoricRegistry *registry;
- (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)script source:(NSString *)source; - (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)script source:(NSString *)source;
- (DoricAsyncResult *)destroyContext:(NSString *)contextId; - (DoricAsyncResult *)destroyContext:(NSString *)contextId;
- (DoricAsyncResult *)invokeDoricMethod:(NSString *)method, ...; - (DoricAsyncResult *)invokeDoricMethod:(NSString *)method, ...;
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method, ...; - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method, ...;
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method arguments:(va_list) args;
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method arguments:(va_list)args;
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method argumentsArray:(NSArray *)args; - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method argumentsArray:(NSArray *)args;
- (void)connectDevKit:(NSString *)url; - (void)connectDevKit:(NSString *)url;
- (void)disconnectDevKit; - (void)disconnectDevKit;
@end @end

View File

@ -10,9 +10,9 @@
#import "DoricConstant.h" #import "DoricConstant.h"
#import "DoricWSClient.h" #import "DoricWSClient.h"
@interface DoricDriver() @interface DoricDriver ()
@property (nonatomic, strong) DoricJSEngine *jsExecutor; @property(nonatomic, strong) DoricJSEngine *jsExecutor;
@property (nonatomic, strong) DoricWSClient *wsclient; @property(nonatomic, strong) DoricWSClient *wsclient;
@end @end
@implementation DoricDriver @implementation DoricDriver
@ -20,7 +20,7 @@ @implementation DoricDriver
@dynamic registry; @dynamic registry;
- (instancetype)init { - (instancetype)init {
if(self = [super init]){ if (self = [super init]) {
_jsExecutor = [[DoricJSEngine alloc] init]; _jsExecutor = [[DoricJSEngine alloc] init];
} }
return self; return self;
@ -30,7 +30,7 @@ - (DoricRegistry *)registry {
return self.jsExecutor.registry; return self.jsExecutor.registry;
} }
+ (instancetype)instance{ + (instancetype)instance {
static DoricDriver *_instance; static DoricDriver *_instance;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
@ -39,7 +39,7 @@ + (instancetype)instance{
return _instance; return _instance;
} }
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method, ... { - (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method, ... {
va_list args; va_list args;
va_start(args, method); va_start(args, method);
DoricAsyncResult *ret = [self invokeDoricMethod:method arguments:args]; DoricAsyncResult *ret = [self invokeDoricMethod:method arguments:args];
@ -47,15 +47,15 @@ + (instancetype)instance{
return ret; return ret;
} }
- (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args { - (DoricAsyncResult<JSValue *> *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init]; DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
NSMutableArray *array = [[NSMutableArray alloc] init]; NSMutableArray *array = [[NSMutableArray alloc] init];
id arg; id arg;
while((arg = va_arg(args, id)) != nil){ while ((arg = va_arg(args, id)) != nil) {
[array addObject:arg]; [array addObject:arg];
} }
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){ dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
if (!self) return; if (!self) return;
@try { @try {
@ -68,7 +68,7 @@ + (instancetype)instance{
return ret; return ret;
} }
- (DoricAsyncResult<JSValue *> *)invokeContextEntity:(NSString *)contextId method:(NSString *)method,... { - (DoricAsyncResult<JSValue *> *)invokeContextEntity:(NSString *)contextId method:(NSString *)method, ... {
va_list args; va_list args;
va_start(args, method); va_start(args, method);
DoricAsyncResult *ret = [self invokeContextEntity:contextId method:method arguments:args]; DoricAsyncResult *ret = [self invokeContextEntity:contextId method:method arguments:args];
@ -82,12 +82,12 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
[array addObject:contextId]; [array addObject:contextId];
[array addObject:method]; [array addObject:method];
id arg = va_arg(args, id); id arg = va_arg(args, id);
while(arg != nil){ while (arg != nil) {
[array addObject:arg]; [array addObject:arg];
arg = va_arg(args, JSValue *); arg = va_arg(args, JSValue *);
} }
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){ dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
if (!self) return; if (!self) return;
@try { @try {
@ -99,16 +99,17 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
}); });
return ret; return ret;
} }
- (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method argumentsArray:(NSArray *)args { - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString *)method argumentsArray:(NSArray *)args {
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init]; DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
NSMutableArray *array = [[NSMutableArray alloc] init]; NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:contextId]; [array addObject:contextId];
[array addObject:method]; [array addObject:method];
for (id arg in args){ for (id arg in args) {
[array addObject: arg]; [array addObject:arg];
} }
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){ dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
if (!self) return; if (!self) return;
@try { @try {
@ -124,10 +125,10 @@ - (DoricAsyncResult *)invokeContextEntity:(NSString *)contextId method:(NSString
- (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)script source:(NSString *)source { - (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)script source:(NSString *)source {
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init]; DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){ dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
if(!self) return; if (!self) return;
@try{ @try {
[self.jsExecutor prepareContext:contextId script:script source:source]; [self.jsExecutor prepareContext:contextId script:script source:source];
[ret setupResult:[NSNumber numberWithBool:YES]]; [ret setupResult:[NSNumber numberWithBool:YES]];
} @catch (NSException *exception) { } @catch (NSException *exception) {
@ -140,10 +141,10 @@ - (DoricAsyncResult *)createContext:(NSString *)contextId script:(NSString *)scr
- (DoricAsyncResult *)destroyContext:(NSString *)contextId { - (DoricAsyncResult *)destroyContext:(NSString *)contextId {
DoricAsyncResult *ret = [[DoricAsyncResult alloc] init]; DoricAsyncResult *ret = [[DoricAsyncResult alloc] init];
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(self.jsExecutor.jsQueue, ^(){ dispatch_async(self.jsExecutor.jsQueue, ^() {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
if(!self) return; if (!self) return;
@try{ @try {
[self.jsExecutor destroyContext:contextId]; [self.jsExecutor destroyContext:contextId];
[ret setupResult:[NSNumber numberWithBool:YES]]; [ret setupResult:[NSNumber numberWithBool:YES]];
} @catch (NSException *exception) { } @catch (NSException *exception) {
@ -154,14 +155,14 @@ - (DoricAsyncResult *)destroyContext:(NSString *)contextId {
} }
- (void)connectDevKit:(NSString *)url { - (void)connectDevKit:(NSString *)url {
if(self.wsclient) { if (self.wsclient) {
[self.wsclient close]; [self.wsclient close];
} }
self.wsclient = [[DoricWSClient alloc] initWithUrl:url]; self.wsclient = [[DoricWSClient alloc] initWithUrl:url];
} }
- (void)disconnectDevKit { - (void)disconnectDevKit {
if(self.wsclient) { if (self.wsclient) {
[self.wsclient close]; [self.wsclient close];
self.wsclient = nil; self.wsclient = nil;
} }

View File

@ -16,16 +16,16 @@
@interface DoricRegistry () @interface DoricRegistry ()
@property (nonatomic,strong) NSMutableDictionary *bundles; @property(nonatomic, strong) NSMutableDictionary *bundles;
@property (nonatomic,strong) NSMutableDictionary *plugins; @property(nonatomic, strong) NSMutableDictionary *plugins;
@property (nonatomic,strong) NSMutableDictionary *nodes; @property(nonatomic, strong) NSMutableDictionary *nodes;
@end @end
@implementation DoricRegistry @implementation DoricRegistry
- (instancetype)init { - (instancetype)init {
if(self = [super init]){ if (self = [super init]) {
_bundles = [[NSMutableDictionary alloc] init]; _bundles = [[NSMutableDictionary alloc] init];
_plugins = [[NSMutableDictionary alloc] init]; _plugins = [[NSMutableDictionary alloc] init];
_nodes = [[NSMutableDictionary alloc] init]; _nodes = [[NSMutableDictionary alloc] init];

View File

@ -7,9 +7,10 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "DoricJSExecutorProtocal.h" #import "DoricJSExecutorProtocal.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricJSCoreExecutor : NSObject<DoricJSExecutorProtocal> @interface DoricJSCoreExecutor : NSObject <DoricJSExecutorProtocal>
@end @end

View File

@ -7,23 +7,23 @@
#import "DoricJSCoreExecutor.h" #import "DoricJSCoreExecutor.h"
@interface DoricJSCoreExecutor() @interface DoricJSCoreExecutor ()
@property(nonatomic,strong) JSContext *jsContext; @property(nonatomic, strong) JSContext *jsContext;
@end @end
@implementation DoricJSCoreExecutor @implementation DoricJSCoreExecutor
- (instancetype)init { - (instancetype)init {
if(self = [super init]){ if (self = [super init]) {
_jsContext = [[JSContext alloc] init]; _jsContext = [[JSContext alloc] init];
} }
return self; return self;
} }
- (void)checkJSException { - (void)checkJSException {
if(self.jsContext.exception){ if (self.jsContext.exception) {
NSString *errMsg = [NSString stringWithFormat:@"%@ (line %@ in the generated bundle)\n/***StackTrace***/\n%@/***StackTrace***/", self.jsContext.exception, self.jsContext.exception[@"line"],self.jsContext.exception[@"stack"]]; NSString *errMsg = [NSString stringWithFormat:@"%@ (line %@ in the generated bundle)\n/***StackTrace***/\n%@/***StackTrace***/", self.jsContext.exception, self.jsContext.exception[@"line"], self.jsContext.exception[@"stack"]];
@throw [[NSException alloc] initWithName:@"DoricJS" reason:errMsg userInfo:nil]; @throw [[NSException alloc] initWithName:@"DoricJS" reason:errMsg userInfo:nil];
} }
} }

View File

@ -13,9 +13,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface DoricJSEngine : NSObject @interface DoricJSEngine : NSObject
@property(nonatomic,strong) dispatch_queue_t jsQueue; @property(nonatomic, strong) dispatch_queue_t jsQueue;
@property(nonatomic,strong) DoricRegistry *registry; @property(nonatomic, strong) DoricRegistry *registry;
- (void)prepareContext:(NSString *)contextId script:(NSString *)script source:(NSString *)source; - (void)prepareContext:(NSString *)contextId script:(NSString *)script source:(NSString *)source;

View File

@ -12,19 +12,19 @@
#import "DoricUtil.h" #import "DoricUtil.h"
#import "DoricBridgeExtension.h" #import "DoricBridgeExtension.h"
@interface DoricJSEngine() @interface DoricJSEngine ()
@property(nonatomic,strong) id<DoricJSExecutorProtocal> jsExecutor; @property(nonatomic, strong) id <DoricJSExecutorProtocal> jsExecutor;
@property(nonatomic,strong) NSMutableDictionary *timers; @property(nonatomic, strong) NSMutableDictionary *timers;
@property(nonatomic,strong) DoricBridgeExtension *bridgeExtension; @property(nonatomic, strong) DoricBridgeExtension *bridgeExtension;
@end @end
@implementation DoricJSEngine @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]; _bridgeExtension = [[DoricBridgeExtension alloc] init];
dispatch_async(_jsQueue, ^(){ dispatch_async(_jsQueue, ^() {
self.timers = [[NSMutableDictionary alloc] init]; self.timers = [[NSMutableDictionary alloc] init];
self.jsExecutor = [[DoricJSCoreExecutor alloc] init]; self.jsExecutor = [[DoricJSCoreExecutor alloc] init];
self.registry = [[DoricRegistry alloc] init]; self.registry = [[DoricRegistry alloc] init];
@ -38,49 +38,49 @@ - (instancetype)init {
- (void)initJSExecutor { - (void)initJSExecutor {
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
[self.jsExecutor injectGlobalJSObject:INJECT_LOG obj:^(NSString * type, NSString * message) { [self.jsExecutor injectGlobalJSObject:INJECT_LOG obj:^(NSString *type, NSString *message) {
DoricLog(@"JS:%@",message); DoricLog(@"JS:%@", message);
}]; }];
[self.jsExecutor injectGlobalJSObject:INJECT_REQUIRE obj:^(NSString *name){ [self.jsExecutor injectGlobalJSObject:INJECT_REQUIRE obj:^(NSString *name) {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
if(!self) return NO; if (!self) return NO;
NSString *content = [self.registry acquireJSBundle:name]; NSString *content = [self.registry acquireJSBundle:name];
if(!content){ if (!content) {
DoricLog(@"require js bundle:%@ is empty", name); DoricLog(@"require js bundle:%@ is empty", name);
return NO; return NO;
} }
@try{ @try {
[self.jsExecutor loadJSScript:[self packageModuleScript:name content:content] [self.jsExecutor loadJSScript:[self packageModuleScript:name content:content]
source:[@"Module://" stringByAppendingString:name]]; source:[@"Module://" stringByAppendingString:name]];
}@catch(NSException *e){ } @catch (NSException *e) {
DoricLog(@"require js bundle:%@ error,for %@", name, e.reason); DoricLog(@"require js bundle:%@ error,for %@", name, e.reason);
} }
return YES; return YES;
}]; }];
[self.jsExecutor injectGlobalJSObject:INJECT_TIMER_SET [self.jsExecutor injectGlobalJSObject:INJECT_TIMER_SET
obj:^(NSNumber *timerId,NSNumber *interval,NSNumber *isInterval) { obj:^(NSNumber *timerId, NSNumber *interval, NSNumber *isInterval) {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
NSString *timerId_str = [timerId stringValue]; NSString *timerId_str = [timerId stringValue];
BOOL repeat = [isInterval boolValue]; BOOL repeat = [isInterval boolValue];
NSTimer *timer = [NSTimer timerWithTimeInterval:[interval doubleValue]/1000 target:self selector:@selector(callbackTimer:) userInfo:@{@"timerId":timerId,@"repeat":isInterval} repeats:repeat]; NSTimer *timer = [NSTimer timerWithTimeInterval:[interval doubleValue] / 1000 target:self selector:@selector(callbackTimer:) userInfo:@{@"timerId": timerId, @"repeat": isInterval} repeats:repeat];
[self.timers setValue:timer forKey:timerId_str]; [self.timers setValue:timer forKey:timerId_str];
dispatch_async(dispatch_get_main_queue(), ^(){ dispatch_async(dispatch_get_main_queue(), ^() {
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}); });
}]; }];
[self.jsExecutor injectGlobalJSObject:INJECT_TIMER_CLEAR [self.jsExecutor injectGlobalJSObject:INJECT_TIMER_CLEAR
obj:^(NSString *timerId) { obj:^(NSString *timerId) {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
NSTimer *timer = [self.timers valueForKey:timerId]; NSTimer *timer = [self.timers valueForKey:timerId];
if(timer){ if (timer) {
[timer invalidate]; [timer invalidate];
[self.timers removeObjectForKey:timerId]; [self.timers removeObjectForKey:timerId];
} }
}]; }];
[self.jsExecutor injectGlobalJSObject:INJECT_BRIDGE obj:^(NSString *contextId, NSString *module, NSString *method, NSString *callbackId, id argument){ [self.jsExecutor injectGlobalJSObject:INJECT_BRIDGE obj:^(NSString *contextId, NSString *module, NSString *method, NSString *callbackId, id argument) {
return [self.bridgeExtension callNativeWithContextId:contextId module:module method:method callbackId:callbackId argument:argument]; return [self.bridgeExtension callNativeWithContextId:contextId module:module method:method callbackId:callbackId argument:argument];
}]; }];
} }
@ -89,8 +89,8 @@ - (void)initDoricEnvironment {
[self loadBuiltinJS:DORIC_BUNDLE_SANDBOX]; [self loadBuiltinJS:DORIC_BUNDLE_SANDBOX];
NSString *path = [DoricBundle() pathForResource:DORIC_BUNDLE_LIB ofType:@"js" inDirectory:@"bundle"]; NSString *path = [DoricBundle() pathForResource:DORIC_BUNDLE_LIB ofType:@"js" inDirectory:@"bundle"];
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.jsExecutor loadJSScript:[self packageModuleScript: DORIC_MODULE_LIB content:jsContent] [self.jsExecutor loadJSScript:[self packageModuleScript:DORIC_MODULE_LIB content:jsContent]
source: [@"Module://" stringByAppendingString:DORIC_MODULE_LIB]]; source:[@"Module://" stringByAppendingString:DORIC_MODULE_LIB]];
} }
- (void)loadBuiltinJS:(NSString *)fileName { - (void)loadBuiltinJS:(NSString *)fileName {
@ -99,7 +99,7 @@ - (void)loadBuiltinJS:(NSString *)fileName {
[self.jsExecutor loadJSScript:jsContent source:[@"Assets://" stringByAppendingString:fileName]]; [self.jsExecutor loadJSScript:jsContent source:[@"Assets://" stringByAppendingString:fileName]];
} }
- (JSValue *)invokeDoricMethod:(NSString *)method,... { - (JSValue *)invokeDoricMethod:(NSString *)method, ... {
va_list args; va_list args;
va_start(args, method); va_start(args, method);
JSValue *ret = [self invokeDoricMethod:method arguments:args]; JSValue *ret = [self invokeDoricMethod:method arguments:args];
@ -110,7 +110,7 @@ - (JSValue *)invokeDoricMethod:(NSString *)method,... {
- (JSValue *)invokeDoricMethod:(NSString *)method arguments:(va_list)args { - (JSValue *)invokeDoricMethod:(NSString *)method arguments:(va_list)args {
NSMutableArray *array = [[NSMutableArray alloc] init]; NSMutableArray *array = [[NSMutableArray alloc] init];
id arg = va_arg(args, id); id arg = va_arg(args, id);
while(arg != nil){ while (arg != nil) {
[array addObject:arg]; [array addObject:arg];
arg = va_arg(args, JSValue *); arg = va_arg(args, JSValue *);
} }
@ -146,14 +146,14 @@ - (void)callbackTimer:(NSTimer *)timer {
NSNumber *timerId = [userInfo valueForKey:@"timerId"]; NSNumber *timerId = [userInfo valueForKey:@"timerId"];
NSNumber *repeat = [userInfo valueForKey:@"repeat"]; NSNumber *repeat = [userInfo valueForKey:@"repeat"];
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(self.jsQueue, ^(){ dispatch_async(self.jsQueue, ^() {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
@try { @try {
[self invokeDoricMethod:DORIC_TIMER_CALLBACK, timerId, nil]; [self invokeDoricMethod:DORIC_TIMER_CALLBACK, timerId, nil];
} @catch (NSException *exception) { } @catch (NSException *exception) {
DoricLog(@"Timer Callback error:%@", exception.reason); DoricLog(@"Timer Callback error:%@", exception.reason);
} }
if(![repeat boolValue]){ if (![repeat boolValue]) {
[self.timers removeObjectForKey:[timerId stringValue]]; [self.timers removeObjectForKey:[timerId stringValue]];
} }
}); });

View File

@ -12,11 +12,11 @@ NS_ASSUME_NONNULL_BEGIN
@protocol DoricJSExecutorProtocal <NSObject> @protocol DoricJSExecutorProtocal <NSObject>
- (NSString *) loadJSScript:(NSString *)script source:(NSString *)source; - (NSString *)loadJSScript:(NSString *)script source:(NSString *)source;
- (void) injectGlobalJSObject:(NSString *)name obj:(id)obj; - (void)injectGlobalJSObject:(NSString *)name obj:(id)obj;
- (JSValue *) invokeObject: (NSString *)objName method:(NSString *)funcName args:(NSArray *)args; - (JSValue *)invokeObject:(NSString *)objName method:(NSString *)funcName args:(NSArray *)args;
@end @end

View File

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

View File

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

View File

@ -7,6 +7,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "DoricNativePlugin.h" #import "DoricNativePlugin.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricModalPlugin : DoricNativePlugin @interface DoricModalPlugin : DoricNativePlugin

View File

@ -13,7 +13,7 @@ @implementation DoricModalPlugin
- (void)toast:(NSString *)message withPromise:(DoricPromise *)promise { - (void)toast:(NSString *)message withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"toast:%@",message); NSLog(@"toast:%@", message);
[promise resolve:@"Resolved"]; [promise resolve:@"Resolved"];
}); });
} }

View File

@ -11,11 +11,11 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricPromise : NSObject @interface DoricPromise : NSObject
- (instancetype)initWithContext: (DoricContext *)context callbackId:(NSString *)callbackId; - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)callbackId;
- (void)resolve:(id) result; - (void)resolve:(id)result;
- (void)reject:(id) result; - (void)reject:(id)result;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -8,16 +8,16 @@
#import "DoricPromise.h" #import "DoricPromise.h"
#import "DoricConstant.h" #import "DoricConstant.h"
@interface DoricPromise() @interface DoricPromise ()
@property (nonatomic,strong) DoricContext *context; @property(nonatomic, strong) DoricContext *context;
@property (nonatomic,strong) NSString *callbackId; @property(nonatomic, strong) NSString *callbackId;
@end @end
@implementation DoricPromise @implementation DoricPromise
- (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)callbackId { - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)callbackId {
if(self = [super init]) { if (self = [super init]) {
_context = context; _context = context;
_callbackId = callbackId; _callbackId = callbackId;
} }
@ -25,10 +25,10 @@ - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)c
} }
- (void)resolve:(id)result { - (void)resolve:(id)result {
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE, self.context.contextId, self.callbackId, result,nil]; [self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE, self.context.contextId, self.callbackId, result, nil];
} }
- (void)reject:(id)result { - (void)reject:(id)result {
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT, self.context.contextId, self.callbackId, result,nil]; [self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT, self.context.contextId, self.callbackId, result, nil];
} }
@end @end

View File

@ -14,7 +14,7 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
[self.doricContext.rootNode render:[argument objectForKey:@"props"]]; [self.doricContext.rootNode render:argument[@"props"]];
}); });
} }

View File

@ -9,13 +9,13 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricGroupNode <V:UIView *,P:LayoutParams *>: DoricViewNode<V> @interface DoricGroupNode <V:UIView *, P:LayoutParams *> : DoricViewNode<V>
@property (nonatomic,strong) NSMutableDictionary *children; @property(nonatomic, strong) NSMutableDictionary *children;
@property (nonatomic,strong) NSMutableArray *indexedChildren; @property(nonatomic, strong) NSMutableArray *indexedChildren;
@property (nonatomic) CGFloat desiredWidth; @property(nonatomic) CGFloat desiredWidth;
@property (nonatomic) CGFloat desiredHeight; @property(nonatomic) CGFloat desiredHeight;
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig; - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig;

View File

@ -10,12 +10,13 @@
@implementation DoricGroupNode @implementation DoricGroupNode
- (instancetype)initWithContext:(DoricContext *)doricContext { - (instancetype)initWithContext:(DoricContext *)doricContext {
if(self = [super initWithContext:doricContext]) { if (self = [super initWithContext:doricContext]) {
_children = [[NSMutableDictionary alloc] init]; _children = [[NSMutableDictionary alloc] init];
_indexedChildren = [[NSMutableArray alloc] init]; _indexedChildren = [[NSMutableArray alloc] init];
} }
return self; return self;
} }
- (UIView *)build:(NSDictionary *)props { - (UIView *)build:(NSDictionary *)props {
UIView *ret = [[UIView alloc] init]; UIView *ret = [[UIView alloc] init];
ret.clipsToBounds = YES; ret.clipsToBounds = YES;
@ -23,24 +24,24 @@ - (UIView *)build:(NSDictionary *)props {
} }
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {
if([name isEqualToString:@"children"]) { if ([name isEqualToString:@"children"]) {
NSArray *array = prop; NSArray *array = prop;
NSInteger i; NSInteger i;
NSMutableArray *tobeRemoved = [[NSMutableArray alloc] init]; NSMutableArray *tobeRemoved = [[NSMutableArray alloc] init];
for (i = 0; i< array.count; i++) { for (i = 0; i < array.count; i++) {
NSDictionary *val = array[i]; NSDictionary *val = array[i];
if (!val || (NSNull *)val == [NSNull null]) { if (!val || (NSNull *) val == [NSNull null]) {
continue; continue;
} }
NSString *type = [val objectForKey:@"type"]; NSString *type = val[@"type"];
NSString *viewId = [val objectForKey:@"id"]; NSString *viewId = val[@"id"];
DoricViewNode *node = [self.children objectForKey:viewId]; DoricViewNode *node = self.children[viewId];
if (node == nil) { if (node == nil) {
node = [DoricViewNode create:self.doricContext withType:type]; node = [DoricViewNode create:self.doricContext withType:type];
node.index = i; node.index = i;
node.parent = self; node.parent = self;
node.viewId = viewId; node.viewId = viewId;
[self.children setObject:node forKey:viewId]; self.children[viewId] = node;
} else { } else {
if (i != node.index) { if (i != node.index) {
[self.indexedChildren removeObjectAtIndex:i]; [self.indexedChildren removeObjectAtIndex:i];
@ -49,7 +50,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
} }
[tobeRemoved removeObject:node]; [tobeRemoved removeObject:node];
} }
DoricViewNode *old = i >= self.indexedChildren.count ? nil :[self.indexedChildren objectAtIndex:i]; DoricViewNode *old = i >= self.indexedChildren.count ? nil : self.indexedChildren[i];
if (old && old != node) { if (old && old != node) {
[old.view removeFromSuperview]; [old.view removeFromSuperview];
self.indexedChildren[i] = [NSNull null]; self.indexedChildren[i] = [NSNull null];
@ -61,27 +62,27 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
params = [self generateDefaultLayoutParams]; params = [self generateDefaultLayoutParams];
node.layoutParams = params; node.layoutParams = params;
} }
[node blend:[val objectForKey:@"props"]]; [node blend:val[@"props"]];
if (self.indexedChildren.count <= i) { if (self.indexedChildren.count <= i) {
[self.view addSubview:node.view]; [self.view addSubview:node.view];
[self.indexedChildren addObject:node]; [self.indexedChildren addObject:node];
}else if ([self.indexedChildren objectAtIndex:i] == [NSNull null]) { } else if (self.indexedChildren[i] == [NSNull null]) {
self.indexedChildren[i] = node; self.indexedChildren[i] = node;
[self.view insertSubview:node.view atIndex:i]; [self.view insertSubview:node.view atIndex:i];
} }
} }
NSUInteger start = i; NSInteger start = i;
while (start < self.indexedChildren.count) { while (start < self.indexedChildren.count) {
DoricViewNode *node = [self.indexedChildren objectAtIndex:start]; DoricViewNode *node = self.indexedChildren[(NSUInteger) start];
if (node) { if (node) {
[self.children removeObjectForKey: node.viewId]; [self.children removeObjectForKey:node.viewId];
[node.view removeFromSuperview]; [node.view removeFromSuperview];
[tobeRemoved removeObject:node]; [tobeRemoved removeObject:node];
} }
start++; start++;
} }
if (i < self.indexedChildren.count) { if (i < self.indexedChildren.count) {
[self.indexedChildren removeObjectsInRange:NSMakeRange(i, self.indexedChildren.count - i)]; [self.indexedChildren removeObjectsInRange:NSMakeRange((NSUInteger) i, self.indexedChildren.count - i)];
} }
for (DoricViewNode *node in tobeRemoved) { for (DoricViewNode *node in tobeRemoved) {
@ -100,13 +101,13 @@ - (LayoutParams *)generateDefaultLayoutParams {
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig { - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig {
LayoutParams *params = child.layoutParams; LayoutParams *params = child.layoutParams;
if ([params isKindOfClass:MarginLayoutParams.class]) { if ([params isKindOfClass:MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *)params; MarginLayoutParams *marginParams = (MarginLayoutParams *) params;
NSDictionary *margin = [layoutconfig objectForKey:@"margin"]; NSDictionary *margin = layoutconfig[@"margin"];
if (margin) { if (margin) {
marginParams.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue]; marginParams.margin.top = [(NSNumber *) margin[@"top"] floatValue];
marginParams.margin.left = [(NSNumber *)[margin objectForKey:@"left"] floatValue]; marginParams.margin.left = [(NSNumber *) margin[@"left"] floatValue];
marginParams.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue]; marginParams.margin.right = [(NSNumber *) margin[@"right"] floatValue];
marginParams.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue]; marginParams.margin.bottom = [(NSNumber *) margin[@"bottom"] floatValue];
} }
} }

View File

@ -9,9 +9,9 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricHLayoutNode : DoricGroupNode<UIView *,VHLayoutParams *> @interface DoricHLayoutNode : DoricGroupNode<UIView *, VHLayoutParams *>
@property (nonatomic) CGFloat space; @property(nonatomic) CGFloat space;
@property (nonatomic) DoricGravity gravity; @property(nonatomic) DoricGravity gravity;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -17,7 +17,7 @@ - (UIView *)build:(NSDictionary *)props {
- (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([name isEqualToString:@"imageUrl"]) { if ([name isEqualToString:@"imageUrl"]) {
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
[view sd_setImageWithURL:[NSURL URLWithString:prop] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { [view sd_setImageWithURL:[NSURL URLWithString:prop] completed:^(UIImage *_Nullable image, NSError *_Nullable error, SDImageCacheType cacheType, NSURL *_Nullable imageURL) {
__strong typeof(_self) self = _self; __strong typeof(_self) self = _self;
[self requestLayout]; [self requestLayout];
}]; }];

View File

@ -9,8 +9,8 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricStackNode : DoricGroupNode<UIView *,StackLayoutParams *> @interface DoricStackNode : DoricGroupNode<UIView *, StackLayoutParams *>
@property (nonatomic) DoricGravity gravity; @property(nonatomic) DoricGravity gravity;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -11,7 +11,7 @@
@implementation DoricStackNode @implementation DoricStackNode
- (instancetype)init { - (instancetype)init {
if (self = [super init]){ if (self = [super init]) {
_gravity = 0; _gravity = 0;
} }
return self; return self;
@ -20,7 +20,7 @@ - (instancetype)init {
- (void)measureByParent:(DoricGroupNode *)parent { - (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width; DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height; DoricLayoutDesc heightSpec = self.layoutParams.height;
CGFloat maxWidth = 0,maxHeight = 0; CGFloat maxWidth = 0, maxHeight = 0;
for (DoricViewNode *child in self.indexedChildren) { for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self]; [child measureByParent:self];
CGFloat placeWidth = child.measuredWidth; CGFloat placeWidth = child.measuredWidth;
@ -39,6 +39,7 @@ - (void)measureByParent:(DoricGroupNode *)parent {
self.height = maxHeight; self.height = maxHeight;
} }
} }
- (LayoutParams *)generateDefaultLayoutParams { - (LayoutParams *)generateDefaultLayoutParams {
return [[StackLayoutParams alloc] init]; return [[StackLayoutParams alloc] init];
} }
@ -49,7 +50,7 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
DoricLog(@"blend Stack child error,layout params not match"); DoricLog(@"blend Stack child error,layout params not match");
return; return;
} }
StackLayoutParams *params = (StackLayoutParams *)child.layoutParams; StackLayoutParams *params = (StackLayoutParams *) child.layoutParams;
// NSDictionary *margin = [layoutconfig objectForKey:@"margin"]; // NSDictionary *margin = [layoutconfig objectForKey:@"margin"];
// if (margin) { // if (margin) {
// params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue]; // params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue];
@ -57,7 +58,7 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
// params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue]; // params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue];
// params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue]; // params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue];
// } // }
NSNumber *alignment = [layoutconfig objectForKey:@"alignment"]; NSNumber *alignment = layoutconfig[@"alignment"];
if (alignment) { if (alignment) {
params.alignment = [alignment integerValue]; params.alignment = [alignment integerValue];
} }
@ -73,7 +74,7 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
} }
DoricGravity gravity = self.gravity; DoricGravity gravity = self.gravity;
if ([child.layoutParams isKindOfClass:StackLayoutParams.class]) { if ([child.layoutParams isKindOfClass:StackLayoutParams.class]) {
StackLayoutParams *layoutParams = (StackLayoutParams *)child.layoutParams; StackLayoutParams *layoutParams = (StackLayoutParams *) child.layoutParams;
gravity |= layoutParams.alignment; gravity |= layoutParams.alignment;
} }

View File

@ -18,11 +18,11 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
if ([name isEqualToString:@"text"]) { if ([name isEqualToString:@"text"]) {
view.text = prop; view.text = prop;
} else if ([name isEqualToString:@"textSize"]) { } else if ([name isEqualToString:@"textSize"]) {
view.font = [UIFont systemFontOfSize:[(NSNumber *)prop floatValue]]; view.font = [UIFont systemFontOfSize:[(NSNumber *) prop floatValue]];
} else if ([name isEqualToString:@"textColor"]) { } else if ([name isEqualToString:@"textColor"]) {
view.textColor = DoricColor(prop); view.textColor = DoricColor(prop);
} else if ([name isEqualToString:@"textAlignment"]) { } else if ([name isEqualToString:@"textAlignment"]) {
DoricGravity gravity = [(NSNumber *)prop integerValue]; DoricGravity gravity = [(NSNumber *) prop integerValue];
NSTextAlignment alignment = NSTextAlignmentCenter; NSTextAlignment alignment = NSTextAlignmentCenter;
switch (gravity) { switch (gravity) {
case LEFT: case LEFT:

View File

@ -9,9 +9,9 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricVLayoutNode : DoricGroupNode<UIView *,VHLayoutParams *> @interface DoricVLayoutNode : DoricGroupNode<UIView *, VHLayoutParams *>
@property (nonatomic) CGFloat space; @property(nonatomic) CGFloat space;
@property (nonatomic) DoricGravity gravity; @property(nonatomic) DoricGravity gravity;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -19,9 +19,9 @@ - (instancetype)init {
- (void)blendView:(id)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(id)view forPropName:(NSString *)name propValue:(id)prop {
if ([name isEqualToString:@"gravity"]) { if ([name isEqualToString:@"gravity"]) {
self.gravity = [(NSNumber *)prop integerValue]; self.gravity = [(NSNumber *) prop integerValue];
} else if ([name isEqualToString:@"space"]) { } else if ([name isEqualToString:@"space"]) {
self.space = [(NSNumber *)prop floatValue]; self.space = [(NSNumber *) prop floatValue];
} else { } else {
[super blendView:view forPropName:name propValue:prop]; [super blendView:view forPropName:name propValue:prop];
} }
@ -33,15 +33,15 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
DoricLog(@"blend VLayout child error,layout params not match"); DoricLog(@"blend VLayout child error,layout params not match");
return; return;
} }
VHLayoutParams *params = (VHLayoutParams *)child.layoutParams; VHLayoutParams *params = (VHLayoutParams *) child.layoutParams;
NSDictionary *margin = [layoutconfig objectForKey:@"margin"]; NSDictionary *margin = layoutconfig[@"margin"];
if (margin) { if (margin) {
params.margin.top = [(NSNumber *)[margin objectForKey:@"top"] floatValue]; params.margin.top = [(NSNumber *) margin[@"top"] floatValue];
params.margin.left = [(NSNumber *)[margin objectForKey:@"left"] floatValue]; params.margin.left = [(NSNumber *) margin[@"left"] floatValue];
params.margin.right = [(NSNumber *)[margin objectForKey:@"right"] floatValue]; params.margin.right = [(NSNumber *) margin[@"right"] floatValue];
params.margin.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue]; params.margin.bottom = [(NSNumber *) margin[@"bottom"] floatValue];
} }
NSNumber *alignment = [layoutconfig objectForKey:@"alignment"]; NSNumber *alignment = layoutconfig[@"alignment"];
if (alignment) { if (alignment) {
params.alignment = [alignment integerValue]; params.alignment = [alignment integerValue];
} }
@ -54,7 +54,7 @@ - (LayoutParams *)generateDefaultLayoutParams {
- (void)measureByParent:(DoricGroupNode *)parent { - (void)measureByParent:(DoricGroupNode *)parent {
DoricLayoutDesc widthSpec = self.layoutParams.width; DoricLayoutDesc widthSpec = self.layoutParams.width;
DoricLayoutDesc heightSpec = self.layoutParams.height; DoricLayoutDesc heightSpec = self.layoutParams.height;
CGFloat maxWidth = 0,maxHeight = 0; CGFloat maxWidth = 0, maxHeight = 0;
for (DoricViewNode *child in self.indexedChildren) { for (DoricViewNode *child in self.indexedChildren) {
[child measureByParent:self]; [child measureByParent:self];
CGFloat placeWidth = child.measuredWidth; CGFloat placeWidth = child.measuredWidth;
@ -90,7 +90,7 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
} else if ((self.gravity & BOTTOM) == BOTTOM) { } else if ((self.gravity & BOTTOM) == BOTTOM) {
yStart = self.height - self.desiredHeight; yStart = self.height - self.desiredHeight;
} else if ((self.gravity & CENTER_Y) == CENTER_Y) { } else if ((self.gravity & CENTER_Y) == CENTER_Y) {
yStart = (self.height -self.desiredHeight)/2; yStart = (self.height - self.desiredHeight) / 2;
} }
@ -102,14 +102,14 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
child.height = self.height; child.height = self.height;
} }
if ([child.layoutParams isKindOfClass:VHLayoutParams.class]) { if ([child.layoutParams isKindOfClass:VHLayoutParams.class]) {
VHLayoutParams *layoutParams = (VHLayoutParams *)child.layoutParams; VHLayoutParams *layoutParams = (VHLayoutParams *) child.layoutParams;
DoricGravity gravity = layoutParams.alignment | self.gravity; DoricGravity gravity = layoutParams.alignment | self.gravity;
if ((gravity & LEFT) == LEFT) { if ((gravity & LEFT) == LEFT) {
child.left = 0; child.left = 0;
} else if ((gravity & RIGHT) == RIGHT) { } else if ((gravity & RIGHT) == RIGHT) {
child.right = self.width; child.right = self.width;
} else if ((gravity & CENTER_X) == CENTER_X) { } else if ((gravity & CENTER_X) == CENTER_X) {
child.centerX = self.width/2; child.centerX = self.width / 2;
} }
} }
child.top = yStart; child.top = yStart;

View File

@ -7,7 +7,7 @@
#import "UIView+Doric.h" #import "UIView+Doric.h"
typedef NS_ENUM(NSInteger,DoricGravity) { typedef NS_ENUM(NSInteger, DoricGravity) {
SPECIFIED = 1, SPECIFIED = 1,
START = 1 << 1, START = 1 << 1,
END = 1 << 2, END = 1 << 2,
@ -22,7 +22,7 @@ typedef NS_ENUM(NSInteger,DoricGravity) {
CENTER = CENTER_X | CENTER_Y, CENTER = CENTER_X | CENTER_Y,
}; };
typedef NS_ENUM(NSInteger,DoricLayoutDesc) { typedef NS_ENUM(NSInteger, DoricLayoutDesc) {
LAYOUT_ABSOLUTE = 0, LAYOUT_ABSOLUTE = 0,
LAYOUT_MATCH_PARENT = -1, LAYOUT_MATCH_PARENT = -1,
LAYOUT_WRAP_CONTENT = -2, LAYOUT_WRAP_CONTENT = -2,
@ -30,51 +30,50 @@ typedef NS_ENUM(NSInteger,DoricLayoutDesc) {
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricRect :NSObject @interface DoricRect : NSObject
@property (nonatomic) CGFloat left; @property(nonatomic) CGFloat left;
@property (nonatomic) CGFloat right; @property(nonatomic) CGFloat right;
@property (nonatomic) CGFloat top; @property(nonatomic) CGFloat top;
@property (nonatomic) CGFloat bottom; @property(nonatomic) CGFloat bottom;
@end @end
@interface LayoutParams : NSObject @interface LayoutParams : NSObject
@property (nonatomic) DoricLayoutDesc width; @property(nonatomic) DoricLayoutDesc width;
@property (nonatomic) DoricLayoutDesc height; @property(nonatomic) DoricLayoutDesc height;
@end @end
@interface MarginLayoutParams : LayoutParams @interface MarginLayoutParams : LayoutParams
@property (nonatomic,strong) DoricRect *margin; @property(nonatomic, strong) DoricRect *margin;
@end @end
@interface StackLayoutParams : LayoutParams @interface StackLayoutParams : LayoutParams
@property (nonatomic) DoricGravity alignment; @property(nonatomic) DoricGravity alignment;
@end @end
@interface VHLayoutParams : MarginLayoutParams @interface VHLayoutParams : MarginLayoutParams
@property (nonatomic) DoricGravity alignment; @property(nonatomic) DoricGravity alignment;
@property (nonatomic) NSInteger weight; @property(nonatomic) NSInteger weight;
@end @end
@interface UIView(DoricContainer) @interface UIView (DoricContainer)
@property (nonatomic,strong) LayoutParams *layoutParams; @property(nonatomic, strong) LayoutParams *layoutParams;
- (void) layout; - (void)layout;
- (void) measure; - (void)measure;
@end @end
@interface Stack : UIView @interface Stack : UIView
@property (nonatomic) DoricGravity gravity; @property(nonatomic) DoricGravity gravity;
@end @end
@interface LinearLayout : UIView @interface LinearLayout : UIView
@property (nonatomic) DoricGravity gravity; @property(nonatomic) DoricGravity gravity;
@property (nonatomic) CGFloat space; @property(nonatomic) CGFloat space;
@end @end

View File

@ -10,7 +10,7 @@
@implementation DoricRect @implementation DoricRect
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_left = 0; _left = 0;
_right = 0; _right = 0;
_top = 0; _top = 0;
@ -22,32 +22,35 @@ - (instancetype)init {
@implementation LayoutParams @implementation LayoutParams
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_width = LAYOUT_WRAP_CONTENT; _width = LAYOUT_WRAP_CONTENT;
_height = LAYOUT_WRAP_CONTENT; _height = LAYOUT_WRAP_CONTENT;
} }
return self; return self;
} }
@end @end
@implementation MarginLayoutParams @implementation MarginLayoutParams
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_margin = [[DoricRect alloc] init]; _margin = [[DoricRect alloc] init];
} }
return self; return self;
}@end }
@end
@implementation StackLayoutParams @implementation StackLayoutParams
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_alignment = 0; _alignment = 0;
} }
return self; return self;
}@end }
@end
@implementation VHLayoutParams @implementation VHLayoutParams
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_alignment = 0; _alignment = 0;
_weight = 0; _weight = 0;
} }
@ -56,7 +59,7 @@ - (instancetype)init {
@end @end
@implementation UIView(DoricContainer) @implementation UIView (DoricContainer)
- (LayoutParams *)layoutParams { - (LayoutParams *)layoutParams {
return objc_getAssociatedObject(self, _cmd); return objc_getAssociatedObject(self, _cmd);
@ -71,7 +74,7 @@ - (void)layout {
} }
- (void)measure { - (void)measure {
if(self.layoutParams) { if (self.layoutParams) {
} }
} }

View File

@ -13,32 +13,32 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class DoricGroupNode; @class DoricGroupNode;
@interface DoricViewNode <V:UIView *>: DoricContextHolder @interface DoricViewNode <V:UIView *> : DoricContextHolder
@property (nonatomic,strong) V view; @property(nonatomic, strong) V view;
@property (nonatomic,weak) DoricGroupNode *parent; @property(nonatomic, weak) DoricGroupNode *parent;
@property (nonatomic) NSInteger index; @property(nonatomic) NSInteger index;
@property (nonatomic,strong) NSString *viewId; @property(nonatomic, strong) NSString *viewId;
@property (nonatomic,strong) LayoutParams *layoutParams; @property(nonatomic, strong) LayoutParams *layoutParams;
@property (nonatomic,strong,readonly) NSArray<NSString *> *idList; @property(nonatomic, strong, readonly) NSArray<NSString *> *idList;
@property (nonatomic) CGFloat x; @property(nonatomic) CGFloat x;
@property (nonatomic) CGFloat y; @property(nonatomic) CGFloat y;
@property (nonatomic) CGFloat width; @property(nonatomic) CGFloat width;
@property (nonatomic) CGFloat height; @property(nonatomic) CGFloat height;
@property (nonatomic) CGFloat centerX; @property(nonatomic) CGFloat centerX;
@property (nonatomic) CGFloat centerY; @property(nonatomic) CGFloat centerY;
@property (nonatomic) CGFloat top; @property(nonatomic) CGFloat top;
@property (nonatomic) CGFloat left; @property(nonatomic) CGFloat left;
@property (nonatomic) CGFloat right; @property(nonatomic) CGFloat right;
@property (nonatomic) CGFloat bottom; @property(nonatomic) CGFloat bottom;
@property (nonatomic,readonly) CGFloat measuredWidth; @property(nonatomic, readonly) CGFloat measuredWidth;
@property (nonatomic,readonly) CGFloat measuredHeight; @property(nonatomic, readonly) CGFloat measuredHeight;
- (V)build:(NSDictionary *)props; - (V)build:(NSDictionary *)props;
@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)blendView:(V)view forPropName:(NSString *)name propValue:(id)prop; - (void)blendView:(V)view forPropName:(NSString *)name propValue:(id)prop;
- (void)callJSResponse:(NSString *)funcId,...; - (void)callJSResponse:(NSString *)funcId, ...;
- (void)measureByParent:(DoricGroupNode *)parent; - (void)measureByParent:(DoricGroupNode *)parent;

View File

@ -12,62 +12,62 @@
#import "DoricConstant.h" #import "DoricConstant.h"
void DoricAddEllipticArcPath(CGMutablePathRef path, void DoricAddEllipticArcPath(CGMutablePathRef path,
CGPoint origin, CGPoint origin,
CGFloat radius, CGFloat radius,
CGFloat startAngle, CGFloat startAngle,
CGFloat endAngle) { CGFloat endAngle) {
CGAffineTransform t = CGAffineTransformMakeTranslation(origin.x, origin.y); CGAffineTransform t = CGAffineTransformMakeTranslation(origin.x, origin.y);
CGPathAddArc(path, &t, 0, 0, radius, startAngle, endAngle, NO); CGPathAddArc(path, &t, 0, 0, radius, startAngle, endAngle, NO);
} }
CGPathRef DoricCreateRoundedRectPath(CGRect bounds, CGPathRef DoricCreateRoundedRectPath(CGRect bounds,
CGFloat leftTop, CGFloat leftTop,
CGFloat rightTop, CGFloat rightTop,
CGFloat rightBottom, CGFloat rightBottom,
CGFloat leftBottom) { CGFloat leftBottom) {
const CGFloat minX = CGRectGetMinX(bounds); const CGFloat minX = CGRectGetMinX(bounds);
const CGFloat minY = CGRectGetMinY(bounds); const CGFloat minY = CGRectGetMinY(bounds);
const CGFloat maxX = CGRectGetMaxX(bounds); const CGFloat maxX = CGRectGetMaxX(bounds);
const CGFloat maxY = CGRectGetMaxY(bounds); const CGFloat maxY = CGRectGetMaxY(bounds);
CGMutablePathRef path = CGPathCreateMutable(); CGMutablePathRef path = CGPathCreateMutable();
DoricAddEllipticArcPath(path, (CGPoint){ DoricAddEllipticArcPath(path, (CGPoint) {
minX + leftTop, minY + leftTop minX + leftTop, minY + leftTop
}, leftTop, M_PI, 3 * M_PI_2); }, leftTop, M_PI, 3 * M_PI_2);
DoricAddEllipticArcPath(path, (CGPoint){ DoricAddEllipticArcPath(path, (CGPoint) {
maxX - rightTop, minY + rightTop maxX - rightTop, minY + rightTop
}, rightTop, 3 * M_PI_2, 0); }, rightTop, 3 * M_PI_2, 0);
DoricAddEllipticArcPath(path, (CGPoint){ DoricAddEllipticArcPath(path, (CGPoint) {
maxX - rightBottom, maxY -rightBottom maxX - rightBottom, maxY - rightBottom
}, rightBottom, 0, M_PI_2); }, rightBottom, 0, M_PI_2);
DoricAddEllipticArcPath(path, (CGPoint){ DoricAddEllipticArcPath(path, (CGPoint) {
minX + leftBottom, maxY - leftBottom minX + leftBottom, maxY - leftBottom
}, leftBottom, M_PI_2, M_PI); }, leftBottom, M_PI_2, M_PI);
CGPathCloseSubpath(path); CGPathCloseSubpath(path);
return path; return path;
} }
@interface DoricViewNode ()
@interface DoricViewNode() @property(nonatomic, strong) NSMutableDictionary *callbackIds;
@property (nonatomic,strong) NSMutableDictionary *callbackIds;
@end @end
@implementation DoricViewNode @implementation DoricViewNode
- (instancetype)initWithContext:(DoricContext *)doricContext { - (instancetype)initWithContext:(DoricContext *)doricContext {
if(self = [super initWithContext:doricContext]) { if (self = [super initWithContext:doricContext]) {
_callbackIds = [[NSMutableDictionary alloc] init]; _callbackIds = [[NSMutableDictionary alloc] init];
} }
return self; return self;
} }
- (UIView *)build:(NSDictionary *)props { - (UIView *)build:(NSDictionary *)props {
return [[UIView alloc] init]; return [[UIView alloc] init];
} }
- (void)blend:(NSDictionary *)props { - (void)blend:(NSDictionary *)props {
if(self.view == nil) { if (self.view == nil) {
self.view = [self build:props]; self.view = [self build:props];
} }
for (NSString *key in props) { for (NSString *key in props) {
@ -77,56 +77,56 @@ - (void)blend:(NSDictionary *)props {
} }
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {
if([name isEqualToString:@"width"]) { if ([name isEqualToString:@"width"]) {
NSNumber *width = (NSNumber *)prop; NSNumber *width = (NSNumber *) prop;
if ([width integerValue] < 0) { if ([width integerValue] < 0) {
self.layoutParams.width = [width integerValue]; self.layoutParams.width = [width integerValue];
} else { } else {
self.layoutParams.width = LAYOUT_ABSOLUTE; self.layoutParams.width = LAYOUT_ABSOLUTE;
view.width = [width floatValue]; view.width = [width floatValue];
} }
} else if([name isEqualToString:@"height"]) { } else if ([name isEqualToString:@"height"]) {
NSNumber *height = (NSNumber *)prop; NSNumber *height = (NSNumber *) prop;
if ([height integerValue] < 0) { if ([height integerValue] < 0) {
self.layoutParams.height = [height integerValue]; self.layoutParams.height = [height integerValue];
} else { } else {
self.layoutParams.height = LAYOUT_ABSOLUTE; self.layoutParams.height = LAYOUT_ABSOLUTE;
view.height = [height floatValue]; view.height = [height floatValue];
} }
} else if([name isEqualToString:@"x"]) { } else if ([name isEqualToString:@"x"]) {
view.x = [(NSNumber *)prop floatValue]; view.x = [(NSNumber *) prop floatValue];
} else if([name isEqualToString:@"y"]) { } else if ([name isEqualToString:@"y"]) {
view.y = [(NSNumber *)prop floatValue]; view.y = [(NSNumber *) prop floatValue];
} else if([name isEqualToString:@"bgColor"]) { } else if ([name isEqualToString:@"bgColor"]) {
view.backgroundColor = DoricColor(prop); view.backgroundColor = DoricColor(prop);
} else if([name isEqualToString:@"layoutConfig"]) { } else if ([name isEqualToString:@"layoutConfig"]) {
if(self.parent && [prop isKindOfClass:[NSDictionary class]]){ if (self.parent && [prop isKindOfClass:[NSDictionary class]]) {
[self.parent blendChild:self layoutConfig:prop]; [self.parent blendChild:self layoutConfig:prop];
} }
} else if([name isEqualToString:@"onClick"]) { } else if ([name isEqualToString:@"onClick"]) {
[self.callbackIds setObject:prop forKey:@"onClick"]; [self.callbackIds setObject:prop forKey:@"onClick"];
view.userInteractionEnabled = YES; view.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClick:)]; UITapGestureRecognizer *tapGesturRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClick:)];
[view addGestureRecognizer:tapGesturRecognizer]; [view addGestureRecognizer:tapGesturRecognizer];
} else if([name isEqualToString:@"border"]) { } else if ([name isEqualToString:@"border"]) {
NSDictionary *dic = prop; NSDictionary *dic = prop;
CGFloat width = [(NSNumber *)[dic objectForKey:@"width"] floatValue]; CGFloat width = [(NSNumber *) [dic objectForKey:@"width"] floatValue];
UIColor *color = DoricColor((NSNumber *)[dic objectForKey:@"color"]); UIColor *color = DoricColor((NSNumber *) [dic objectForKey:@"color"]);
view.layer.borderWidth = width; view.layer.borderWidth = width;
view.layer.borderColor = color.CGColor; view.layer.borderColor = color.CGColor;
} else if([name isEqualToString:@"corners"]) { } else if ([name isEqualToString:@"corners"]) {
if([prop isKindOfClass:NSNumber.class]) { if ([prop isKindOfClass:NSNumber.class]) {
view.layer.cornerRadius = [(NSNumber *)prop floatValue]; view.layer.cornerRadius = [(NSNumber *) prop floatValue];
} else if([prop isKindOfClass:NSDictionary.class]) { } else if ([prop isKindOfClass:NSDictionary.class]) {
NSDictionary *dic = prop; NSDictionary *dic = prop;
CGFloat leftTop = [(NSNumber *)[dic objectForKey:@"leftTop"] floatValue]; CGFloat leftTop = [(NSNumber *) [dic objectForKey:@"leftTop"] floatValue];
CGFloat rightTop = [(NSNumber *)[dic objectForKey:@"rightTop"] floatValue]; CGFloat rightTop = [(NSNumber *) [dic objectForKey:@"rightTop"] floatValue];
CGFloat rightBottom = [(NSNumber *)[dic objectForKey:@"rightBottom"] floatValue]; CGFloat rightBottom = [(NSNumber *) [dic objectForKey:@"rightBottom"] floatValue];
CGFloat leftBottom = [(NSNumber *)[dic objectForKey:@"leftBottom"] floatValue]; CGFloat leftBottom = [(NSNumber *) [dic objectForKey:@"leftBottom"] floatValue];
CALayer *mask = nil; CALayer *mask = nil;
if(ABS(leftTop - rightTop) > CGFLOAT_MIN if (ABS(leftTop - rightTop) > CGFLOAT_MIN
||ABS(leftTop - rightBottom) > CGFLOAT_MIN || ABS(leftTop - rightBottom) > CGFLOAT_MIN
||ABS(leftTop - leftBottom) > CGFLOAT_MIN) { || ABS(leftTop - leftBottom) > CGFLOAT_MIN) {
view.layer.cornerRadius = 0; view.layer.cornerRadius = 0;
CAShapeLayer *shapeLayer = [CAShapeLayer layer]; CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGPathRef path = DoricCreateRoundedRectPath(self.view.bounds, leftTop, rightTop, rightBottom, leftBottom); CGPathRef path = DoricCreateRoundedRectPath(self.view.bounds, leftTop, rightTop, rightBottom, leftBottom);
@ -138,15 +138,15 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
} }
view.layer.mask = mask; view.layer.mask = mask;
} }
} else if([name isEqualToString:@"shadow"]) { } else if ([name isEqualToString:@"shadow"]) {
NSDictionary *dic = prop; NSDictionary *dic = prop;
CGFloat opacity = [(NSNumber *)[dic objectForKey:@"opacity"] floatValue]; CGFloat opacity = [(NSNumber *) [dic objectForKey:@"opacity"] floatValue];
if (opacity > CGFLOAT_MIN) { if (opacity > CGFLOAT_MIN) {
view.clipsToBounds = NO; view.clipsToBounds = NO;
UIColor *color = DoricColor((NSNumber *)[dic objectForKey:@"color"]); UIColor *color = DoricColor((NSNumber *) [dic objectForKey:@"color"]);
view.layer.shadowColor = color.CGColor; view.layer.shadowColor = color.CGColor;
view.layer.shadowRadius = [(NSNumber *)[dic objectForKey:@"radius"] floatValue]; view.layer.shadowRadius = [(NSNumber *) [dic objectForKey:@"radius"] floatValue];
view.layer.shadowOffset = CGSizeMake([(NSNumber *)[dic objectForKey:@"offsetX"] floatValue],[(NSNumber *)[dic objectForKey:@"offsetY"] floatValue]); view.layer.shadowOffset = CGSizeMake([(NSNumber *) [dic objectForKey:@"offsetX"] floatValue], [(NSNumber *) [dic objectForKey:@"offsetY"] floatValue]);
view.layer.shadowOpacity = opacity; view.layer.shadowOpacity = opacity;
} else { } else {
view.clipsToBounds = YES; view.clipsToBounds = YES;
@ -158,20 +158,20 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
} }
- (void)onClick:(UIView *)view { - (void)onClick:(UIView *)view {
[self callJSResponse:[self.callbackIds objectForKey:@"onClick"],nil]; [self callJSResponse:[self.callbackIds objectForKey:@"onClick"], nil];
} }
- (CGFloat)measuredWidth { - (CGFloat)measuredWidth {
if ([self.layoutParams isKindOfClass: MarginLayoutParams.class]) { if ([self.layoutParams isKindOfClass:MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *)self.layoutParams; MarginLayoutParams *marginParams = (MarginLayoutParams *) self.layoutParams;
return self.width + marginParams.margin.left + marginParams.margin.right; return self.width + marginParams.margin.left + marginParams.margin.right;
} }
return self.width; return self.width;
} }
- (CGFloat)measuredHeight { - (CGFloat)measuredHeight {
if ([self.layoutParams isKindOfClass: MarginLayoutParams.class]) { if ([self.layoutParams isKindOfClass:MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *)self.layoutParams; MarginLayoutParams *marginParams = (MarginLayoutParams *) self.layoutParams;
return self.height + marginParams.margin.top + marginParams.margin.bottom; return self.height + marginParams.margin.top + marginParams.margin.bottom;
} }
return self.height; return self.height;
@ -200,7 +200,7 @@ - (void)layoutByParent:(DoricGroupNode *)parent {
return [[ret reverseObjectEnumerator] allObjects]; return [[ret reverseObjectEnumerator] allObjects];
} }
- (void)callJSResponse:(NSString *)funcId,... { - (void)callJSResponse:(NSString *)funcId, ... {
NSMutableArray *array = [[NSMutableArray alloc] init]; NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:self.idList]; [array addObject:self.idList];
[array addObject:funcId]; [array addObject:funcId];
@ -216,88 +216,88 @@ - (void)callJSResponse:(NSString *)funcId,... {
+ (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type { + (DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type {
DoricRegistry *registry = context.driver.registry; DoricRegistry *registry = context.driver.registry;
Class clz = [registry acquireViewNode:type]; Class clz = [registry acquireViewNode:type];
return [[clz alloc] initWithContext:context]; return [[clz alloc] initWithContext:context];
} }
- (CGFloat)x { - (CGFloat)x {
return ((UIView *)self.view).x; return ((UIView *) self.view).x;
} }
- (CGFloat)y { - (CGFloat)y {
return ((UIView *)self.view).y; return ((UIView *) self.view).y;
} }
- (CGFloat)width { - (CGFloat)width {
return ((UIView *)self.view).width; return ((UIView *) self.view).width;
} }
- (CGFloat)height { - (CGFloat)height {
return ((UIView *)self.view).height; return ((UIView *) self.view).height;
} }
- (CGFloat)top { - (CGFloat)top {
return ((UIView *)self.view).top; return ((UIView *) self.view).top;
} }
- (CGFloat)bottom { - (CGFloat)bottom {
return ((UIView *)self.view).bottom; return ((UIView *) self.view).bottom;
} }
- (CGFloat)left { - (CGFloat)left {
return ((UIView *)self.view).left; return ((UIView *) self.view).left;
} }
- (CGFloat)right { - (CGFloat)right {
return ((UIView *)self.view).right; return ((UIView *) self.view).right;
} }
- (CGFloat)centerX { - (CGFloat)centerX {
return ((UIView *)self.view).centerX; return ((UIView *) self.view).centerX;
} }
- (CGFloat)centerY { - (CGFloat)centerY {
return ((UIView *)self.view).centerY; return ((UIView *) self.view).centerY;
} }
- (void)setX:(CGFloat)x { - (void)setX:(CGFloat)x {
((UIView *)self.view).x = x; ((UIView *) self.view).x = x;
} }
- (void)setY:(CGFloat)y { - (void)setY:(CGFloat)y {
((UIView *)self.view).y = y; ((UIView *) self.view).y = y;
} }
- (void)setWidth:(CGFloat)width { - (void)setWidth:(CGFloat)width {
((UIView *)self.view).width = width; ((UIView *) self.view).width = width;
} }
- (void)setHeight:(CGFloat)height { - (void)setHeight:(CGFloat)height {
((UIView *)self.view).height = height; ((UIView *) self.view).height = height;
} }
- (void)setLeft:(CGFloat)left { - (void)setLeft:(CGFloat)left {
((UIView *)self.view).left = left; ((UIView *) self.view).left = left;
} }
- (void)setRight:(CGFloat)right { - (void)setRight:(CGFloat)right {
((UIView *)self.view).right = right; ((UIView *) self.view).right = right;
} }
- (void)setTop:(CGFloat)top { - (void)setTop:(CGFloat)top {
((UIView *)self.view).top = top; ((UIView *) self.view).top = top;
} }
- (void)setBottom:(CGFloat)bottom { - (void)setBottom:(CGFloat)bottom {
((UIView *)self.view).bottom = bottom; ((UIView *) self.view).bottom = bottom;
} }
- (void)setCenterX:(CGFloat)centerX { - (void)setCenterX:(CGFloat)centerX {
((UIView *)self.view).centerX = centerX; ((UIView *) self.view).centerX = centerX;
} }
- (void)setCenterY:(CGFloat)centerY { - (void)setCenterY:(CGFloat)centerY {
((UIView *)self.view).centerY = centerY; ((UIView *) self.view).centerY = centerY;
} }
- (void)requestLayout { - (void)requestLayout {

View File

@ -8,19 +8,20 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIView.h> #import <UIKit/UIView.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface UIView (Doric) @interface UIView (Doric)
@property (nonatomic) CGFloat x; @property(nonatomic) CGFloat x;
@property (nonatomic) CGFloat y; @property(nonatomic) CGFloat y;
@property (nonatomic) CGFloat width; @property(nonatomic) CGFloat width;
@property (nonatomic) CGFloat height; @property(nonatomic) CGFloat height;
@property (nonatomic) CGFloat centerX; @property(nonatomic) CGFloat centerX;
@property (nonatomic) CGFloat centerY; @property(nonatomic) CGFloat centerY;
@property (nonatomic) CGFloat top; @property(nonatomic) CGFloat top;
@property (nonatomic) CGFloat left; @property(nonatomic) CGFloat left;
@property (nonatomic) CGFloat right; @property(nonatomic) CGFloat right;
@property (nonatomic) CGFloat bottom; @property(nonatomic) CGFloat bottom;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -8,7 +8,7 @@
#import "UIView+Doric.h" #import "UIView+Doric.h"
@implementation UIView(Doric) @implementation UIView (Doric)
- (CGFloat)x { - (CGFloat)x {
return self.frame.origin.x; return self.frame.origin.x;
@ -91,22 +91,22 @@ - (void)setHeight:(CGFloat)height {
} }
- (CGFloat)centerX { - (CGFloat)centerX {
return self.frame.origin.x + self.frame.size.width/2; return self.frame.origin.x + self.frame.size.width / 2;
} }
- (void)setCenterX:(CGFloat)centerX { - (void)setCenterX:(CGFloat)centerX {
CGRect frame = self.frame; CGRect frame = self.frame;
frame.origin.x = centerX - self.frame.size.width/2; frame.origin.x = centerX - self.frame.size.width / 2;
[self setFrame:frame]; [self setFrame:frame];
} }
- (CGFloat)centerY { - (CGFloat)centerY {
return self.frame.origin.y + self.frame.size.height/2; return self.frame.origin.y + self.frame.size.height / 2;
} }
- (void)setCenterY:(CGFloat)centerY { - (void)setCenterY:(CGFloat)centerY {
CGRect frame = self.frame; CGRect frame = self.frame;
frame.origin.y = centerY - self.frame.size.height/2; frame.origin.y = centerY - self.frame.size.height / 2;
[self setFrame:frame]; [self setFrame:frame];
} }

View File

@ -10,18 +10,23 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricAsyncResult <R>: NSObject @interface DoricAsyncResult <R> : NSObject
typedef void(^DoricResultCallback)(R); typedef void(^DoricResultCallback)(R);
typedef void(^DoricExceptionCallback)(NSException *); typedef void(^DoricExceptionCallback)(NSException *);
typedef void(^DoricFinishCallback)(void); typedef void(^DoricFinishCallback)(void);
@property(nonatomic,strong) DoricResultCallback resultCallback; @property(nonatomic, strong) DoricResultCallback resultCallback;
@property(nonatomic,strong) DoricExceptionCallback exceptionCallback; @property(nonatomic, strong) DoricExceptionCallback exceptionCallback;
@property(nonatomic,strong) DoricFinishCallback finishCallback; @property(nonatomic, strong) DoricFinishCallback finishCallback;
- (void)setupResult:(R)result; - (void)setupResult:(R)result;
- (void)setupError:(NSException*)exception;
- (void)setupError:(NSException *)exception;
- (BOOL)hasResult; - (BOOL)hasResult;
- (R)getResult; - (R)getResult;
@end @end

View File

@ -7,43 +7,43 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
extern NSString * const DORIC_BUNDLE_SANDBOX; extern NSString *const DORIC_BUNDLE_SANDBOX;
extern NSString * const DORIC_BUNDLE_LIB; extern NSString *const DORIC_BUNDLE_LIB;
extern NSString * const DORIC_MODULE_LIB; extern NSString *const DORIC_MODULE_LIB;
extern NSString * const INJECT_LOG; extern NSString *const INJECT_LOG;
extern NSString * const INJECT_REQUIRE; extern NSString *const INJECT_REQUIRE;
extern NSString * const INJECT_TIMER_SET; extern NSString *const INJECT_TIMER_SET;
extern NSString * const INJECT_TIMER_CLEAR; extern NSString *const INJECT_TIMER_CLEAR;
extern NSString * const INJECT_BRIDGE; extern NSString *const INJECT_BRIDGE;
extern NSString * const TEMPLATE_CONTEXT_CREATE; extern NSString *const TEMPLATE_CONTEXT_CREATE;
extern NSString * const TEMPLATE_MODULE; extern NSString *const TEMPLATE_MODULE;
extern NSString * const TEMPLATE_CONTEXT_DESTROY; extern NSString *const TEMPLATE_CONTEXT_DESTROY;
extern NSString * const GLOBAL_DORIC; extern NSString *const GLOBAL_DORIC;
extern NSString * const DORIC_CONTEXT_RELEASE; extern NSString *const DORIC_CONTEXT_RELEASE;
extern NSString * const DORIC_CONTEXT_INVOKE; extern NSString *const DORIC_CONTEXT_INVOKE;
extern NSString * const DORIC_TIMER_CALLBACK; extern NSString *const DORIC_TIMER_CALLBACK;
extern NSString * const DORIC_BRIDGE_RESOLVE; extern NSString *const DORIC_BRIDGE_RESOLVE;
extern NSString * const DORIC_BRIDGE_REJECT; extern NSString *const DORIC_BRIDGE_REJECT;
extern NSString * const DORIC_ENTITY_RESPONSE; extern NSString *const DORIC_ENTITY_RESPONSE;
extern NSString * const DORIC_ENTITY_INIT; extern NSString *const DORIC_ENTITY_INIT;
extern NSString * const DORIC_ENTITY_CREATE; extern NSString *const DORIC_ENTITY_CREATE;
extern NSString * const DORIC_ENTITY_DESTROY; extern NSString *const DORIC_ENTITY_DESTROY;
extern NSString * const DORIC_ENTITY_SHOW; extern NSString *const DORIC_ENTITY_SHOW;
extern NSString * const DORIC_ENTITY_HIDDEN; extern NSString *const DORIC_ENTITY_HIDDEN;

View File

@ -7,60 +7,60 @@
#import "DoricConstant.h" #import "DoricConstant.h"
NSString * const DORIC_BUNDLE_SANDBOX = @"doric-sandbox"; NSString *const DORIC_BUNDLE_SANDBOX = @"doric-sandbox";
NSString * const DORIC_BUNDLE_LIB = @"doric-lib"; NSString *const DORIC_BUNDLE_LIB = @"doric-lib";
NSString * const DORIC_MODULE_LIB = @"doric"; NSString *const DORIC_MODULE_LIB = @"doric";
NSString * const INJECT_LOG = @"nativeLog"; NSString *const INJECT_LOG = @"nativeLog";
NSString * const INJECT_REQUIRE = @"nativeRequire"; NSString *const INJECT_REQUIRE = @"nativeRequire";
NSString * const INJECT_TIMER_SET = @"nativeSetTimer"; NSString *const INJECT_TIMER_SET = @"nativeSetTimer";
NSString * const INJECT_TIMER_CLEAR = @"nativeClearTimer"; NSString *const INJECT_TIMER_CLEAR = @"nativeClearTimer";
NSString * const INJECT_BRIDGE = @"nativeBridge"; NSString *const INJECT_BRIDGE = @"nativeBridge";
NSString * const TEMPLATE_CONTEXT_CREATE = @"Reflect.apply(" NSString *const TEMPLATE_CONTEXT_CREATE = @"Reflect.apply("
"function(doric,context,Entry,require,exports){" "\n" "function(doric,context,Entry,require,exports){" "\n"
"%@" "\n" "%@" "\n"
"},doric.jsObtainContext(\"%@\"),[" "},doric.jsObtainContext(\"%@\"),["
"undefined," "undefined,"
"doric.jsObtainContext(\"%@\")," "doric.jsObtainContext(\"%@\"),"
"doric.jsObtainEntry(\"%@\")," "doric.jsObtainEntry(\"%@\"),"
"doric.__require__" "doric.__require__"
",{}" ",{}"
"])"; "])";
NSString * const TEMPLATE_MODULE = @"Reflect.apply(doric.jsRegisterModule,this,[" NSString *const TEMPLATE_MODULE = @"Reflect.apply(doric.jsRegisterModule,this,["
"\"%@\"," "\"%@\","
"Reflect.apply(function(__module){" "Reflect.apply(function(__module){"
"(function(module,exports,require){" "\n" "(function(module,exports,require){" "\n"
"%@" "\n" "%@" "\n"
"})(__module,__module.exports,doric.__require__);" "})(__module,__module.exports,doric.__require__);"
"\nreturn __module.exports;" "\nreturn __module.exports;"
"},this,[{exports:{}}])" "},this,[{exports:{}}])"
"])"; "])";
NSString * const TEMPLATE_CONTEXT_DESTROY = @"doric.jsReleaseContext(\"%@\")"; NSString *const TEMPLATE_CONTEXT_DESTROY = @"doric.jsReleaseContext(\"%@\")";
NSString * const GLOBAL_DORIC = @"doric"; NSString *const GLOBAL_DORIC = @"doric";
NSString * const DORIC_CONTEXT_RELEASE = @"jsReleaseContext"; NSString *const DORIC_CONTEXT_RELEASE = @"jsReleaseContext";
NSString * const DORIC_CONTEXT_INVOKE = @"jsCallEntityMethod"; NSString *const DORIC_CONTEXT_INVOKE = @"jsCallEntityMethod";
NSString * const DORIC_TIMER_CALLBACK = @"jsCallbackTimer"; NSString *const DORIC_TIMER_CALLBACK = @"jsCallbackTimer";
NSString * const DORIC_BRIDGE_RESOLVE = @"jsCallResolve"; NSString *const DORIC_BRIDGE_RESOLVE = @"jsCallResolve";
NSString * const DORIC_BRIDGE_REJECT = @"jsCallReject"; NSString *const DORIC_BRIDGE_REJECT = @"jsCallReject";
NSString * const DORIC_ENTITY_RESPONSE = @"__response__"; NSString *const DORIC_ENTITY_RESPONSE = @"__response__";
NSString * const DORIC_ENTITY_INIT = @"__init__"; NSString *const DORIC_ENTITY_INIT = @"__init__";
NSString * const DORIC_ENTITY_CREATE = @"__onCreate__"; NSString *const DORIC_ENTITY_CREATE = @"__onCreate__";
NSString * const DORIC_ENTITY_DESTROY = @"__onDestroy__"; NSString *const DORIC_ENTITY_DESTROY = @"__onDestroy__";
NSString * const DORIC_ENTITY_SHOW = @"__onShow__"; NSString *const DORIC_ENTITY_SHOW = @"__onShow__";
NSString * const DORIC_ENTITY_HIDDEN = @"__onHidden__"; NSString *const DORIC_ENTITY_HIDDEN = @"__onHidden__";

View File

@ -7,8 +7,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
void DoricLog(NSString * _Nonnull format, ...); void DoricLog(NSString *_Nonnull format, ...);
UIColor* _Nonnull DoricColor(NSNumber * _Nonnull number); UIColor *_Nonnull DoricColor(NSNumber *_Nonnull number);
NSBundle *DoricBundle(); NSBundle *DoricBundle();

View File

@ -8,20 +8,20 @@
#import "DoricUtil.h" #import "DoricUtil.h"
#import "DoricContext.h" #import "DoricContext.h"
void DoricLog(NSString * _Nonnull format, ...) { void DoricLog(NSString *_Nonnull format, ...) {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
NSLogv([NSString stringWithFormat:@"Doric:%@",format],args); NSLogv([NSString stringWithFormat:@"Doric:%@", format], args);
va_end(args); va_end(args);
} }
UIColor *DoricColor(NSNumber *number) { UIColor *DoricColor(NSNumber *number) {
CGFloat r, g, b, a; CGFloat r, g, b, a;
long colorValue = [number longValue]; long colorValue = [number longValue];
a = ((colorValue >> 24) & 0xff)/255.0f; a = ((colorValue >> 24) & 0xff) / 255.0f;
r = ((colorValue >> 16) & 0xff)/255.0f; r = ((colorValue >> 16) & 0xff) / 255.0f;
g = ((colorValue >> 8) & 0xff)/255.0f; g = ((colorValue >> 8) & 0xff) / 255.0f;
b = ((colorValue >> 0) & 0xff)/255.0f; b = ((colorValue >> 0) & 0xff) / 255.0f;
return [UIColor colorWithRed:r green:g blue:b alpha:a]; return [UIColor colorWithRed:r green:g blue:b alpha:a];
} }