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 <ifaddrs.h>
typedef id (^ServerHandler)(GCDWebServerRequest * request);
typedef id (^ServerHandler)(GCDWebServerRequest *request);
@interface DoricLocalServer()
@property (nonatomic, strong) GCDWebServer *server;
@property (nonatomic, strong) NSMutableDictionary *handlers;
@interface DoricLocalServer ()
@property(nonatomic, strong) GCDWebServer *server;
@property(nonatomic, strong) NSMutableDictionary *handlers;
@end
@implementation DoricLocalServer
@ -36,14 +36,14 @@ - (instancetype)init {
- (NSString *)localIPAddress {
NSString *localIP = nil;
struct ifaddrs *addrs;
if (getifaddrs(&addrs)==0) {
if (getifaddrs(&addrs) == 0) {
const struct ifaddrs *cursor = addrs;
while (cursor != NULL) {
if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0) {
//NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
//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;
}
}
@ -65,7 +65,7 @@ - (GCDWebServerResponse *)handleRequest:(GCDWebServerRequest *)request {
return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>It's a API request.</p></body></html>"];
}
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];
NSURL *url = [NSURL fileURLWithPath:filePath];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
@ -78,38 +78,38 @@ - (void)configurate {
__weak typeof(self) _self = self;
[self.server addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse * (GCDWebServerRequest * request) {
processBlock:^GCDWebServerResponse *(GCDWebServerRequest *request) {
__strong typeof(_self) self = _self;
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,
}];
}
return array;
}
[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,
}];
}
return array;
}
forKey:@"allContexts"];
[self.handlers setObject:^id(GCDWebServerRequest *request) {
NSString *contextId = [request.query objectForKey:@"id"];
DoricContext *context = [[DoricContextManager instance] getContext:contextId];
return @{
@"id":context.contextId,
@"source":context.source,
@"script":context.script
};
}
NSString *contextId = [request.query objectForKey:@"id"];
DoricContext *context = [[DoricContextManager instance] getContext:contextId];
return @{
@"id": context.contextId,
@"source": context.source,
@"script": context.script
};
}
forKey:@"context"];
}
- (void)startWithPort:(NSUInteger)port {
[self.server startWithPort:port bonjourName:nil];
DoricLog(@"Start Server At %@:%d",[self localIPAddress],port);
DoricLog(@"Start Server At %@:%d", [self localIPAddress], port);
}
@end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,19 +18,24 @@ typedef NS_ENUM(NSInteger, QueueMode) {
NS_ASSUME_NONNULL_BEGIN
@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 *)destroyContext:(NSString *)contextId;
- (DoricAsyncResult *)invokeDoricMethod:(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;
- (void)connectDevKit:(NSString *)url;
- (void)disconnectDevKit;
@end

View File

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

View File

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

View File

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

View File

@ -7,23 +7,23 @@
#import "DoricJSCoreExecutor.h"
@interface DoricJSCoreExecutor()
@interface DoricJSCoreExecutor ()
@property(nonatomic,strong) JSContext *jsContext;
@property(nonatomic, strong) JSContext *jsContext;
@end
@implementation DoricJSCoreExecutor
- (instancetype)init {
if(self = [super init]){
if (self = [super init]) {
_jsContext = [[JSContext alloc] init];
}
return self;
}
- (void)checkJSException {
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"]];
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"]];
@throw [[NSException alloc] initWithName:@"DoricJS" reason:errMsg userInfo:nil];
}
}

View File

@ -13,9 +13,9 @@ NS_ASSUME_NONNULL_BEGIN
@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;

View File

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

View File

@ -12,11 +12,11 @@ NS_ASSUME_NONNULL_BEGIN
@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

View File

@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoricBridgeExtension : NSObject
- (id)callNativeWithContextId: (NSString *)contextId module:(NSString *)module method:(NSString *)method callbackId:(NSString *)callbackId argument:(id)argument;
- (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module method:(NSString *)method callbackId:(NSString *)callbackId argument:(id)argument;
@end
NS_ASSUME_NONNULL_END

View File

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

View File

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

View File

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

View File

@ -11,11 +11,11 @@
NS_ASSUME_NONNULL_BEGIN
@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
NS_ASSUME_NONNULL_END

View File

@ -8,16 +8,16 @@
#import "DoricPromise.h"
#import "DoricConstant.h"
@interface DoricPromise()
@property (nonatomic,strong) DoricContext *context;
@property (nonatomic,strong) NSString *callbackId;
@interface DoricPromise ()
@property(nonatomic, strong) DoricContext *context;
@property(nonatomic, strong) NSString *callbackId;
@end
@implementation DoricPromise
- (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)callbackId {
if(self = [super init]) {
if (self = [super init]) {
_context = context;
_callbackId = callbackId;
}
@ -25,10 +25,10 @@ - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)c
}
- (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 {
[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

View File

@ -14,7 +14,7 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
__weak typeof(self) _self = self;
dispatch_async(dispatch_get_main_queue(), ^{
__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
@interface DoricGroupNode <V:UIView *,P:LayoutParams *>: DoricViewNode<V>
@interface DoricGroupNode <V:UIView *, P:LayoutParams *> : DoricViewNode<V>
@property (nonatomic,strong) NSMutableDictionary *children;
@property (nonatomic,strong) NSMutableArray *indexedChildren;
@property(nonatomic, strong) NSMutableDictionary *children;
@property(nonatomic, strong) NSMutableArray *indexedChildren;
@property (nonatomic) CGFloat desiredWidth;
@property (nonatomic) CGFloat desiredHeight;
@property(nonatomic) CGFloat desiredWidth;
@property(nonatomic) CGFloat desiredHeight;
- (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutconfig;

View File

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

View File

@ -9,9 +9,9 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoricHLayoutNode : DoricGroupNode<UIView *,VHLayoutParams *>
@property (nonatomic) CGFloat space;
@property (nonatomic) DoricGravity gravity;
@interface DoricHLayoutNode : DoricGroupNode<UIView *, VHLayoutParams *>
@property(nonatomic) CGFloat space;
@property(nonatomic) DoricGravity gravity;
@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 {
if ([name isEqualToString:@"imageUrl"]) {
__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;
[self requestLayout];
}];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,32 +13,32 @@
NS_ASSUME_NONNULL_BEGIN
@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) NSInteger index;
@property(nonatomic, weak) DoricGroupNode *parent;
@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 y;
@property (nonatomic) CGFloat width;
@property (nonatomic) CGFloat height;
@property (nonatomic) CGFloat centerX;
@property (nonatomic) CGFloat centerY;
@property (nonatomic) CGFloat top;
@property (nonatomic) CGFloat left;
@property (nonatomic) CGFloat right;
@property (nonatomic) CGFloat bottom;
@property (nonatomic,readonly) CGFloat measuredWidth;
@property (nonatomic,readonly) CGFloat measuredHeight;
@property(nonatomic) CGFloat x;
@property(nonatomic) CGFloat y;
@property(nonatomic) CGFloat width;
@property(nonatomic) CGFloat height;
@property(nonatomic) CGFloat centerX;
@property(nonatomic) CGFloat centerY;
@property(nonatomic) CGFloat top;
@property(nonatomic) CGFloat left;
@property(nonatomic) CGFloat right;
@property(nonatomic) CGFloat bottom;
@property(nonatomic, readonly) CGFloat measuredWidth;
@property(nonatomic, readonly) CGFloat measuredHeight;
- (V)build:(NSDictionary *)props;
@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)blendView:(V)view forPropName:(NSString *)name propValue:(id)prop;
- (void)callJSResponse:(NSString *)funcId,...;
- (void)callJSResponse:(NSString *)funcId, ...;
- (void)measureByParent:(DoricGroupNode *)parent;

View File

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

View File

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

View File

@ -8,7 +8,7 @@
#import "UIView+Doric.h"
@implementation UIView(Doric)
@implementation UIView (Doric)
- (CGFloat)x {
return self.frame.origin.x;
@ -91,22 +91,22 @@ - (void)setHeight:(CGFloat)height {
}
- (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 {
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];
}
- (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 {
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];
}

View File

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

View File

@ -7,43 +7,43 @@
#import <Foundation/Foundation.h>
extern NSString * const DORIC_BUNDLE_SANDBOX;
extern NSString * const DORIC_BUNDLE_LIB;
extern NSString * const DORIC_MODULE_LIB;
extern NSString *const DORIC_BUNDLE_SANDBOX;
extern NSString *const DORIC_BUNDLE_LIB;
extern NSString *const DORIC_MODULE_LIB;
extern NSString * const INJECT_LOG;
extern NSString * const INJECT_REQUIRE;
extern NSString * const INJECT_TIMER_SET;
extern NSString * const INJECT_TIMER_CLEAR;
extern NSString * const INJECT_BRIDGE;
extern NSString *const INJECT_LOG;
extern NSString *const INJECT_REQUIRE;
extern NSString *const INJECT_TIMER_SET;
extern NSString *const INJECT_TIMER_CLEAR;
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"
NSString * const DORIC_BUNDLE_SANDBOX = @"doric-sandbox";
NSString * const DORIC_BUNDLE_LIB = @"doric-lib";
NSString * const DORIC_MODULE_LIB = @"doric";
NSString *const DORIC_BUNDLE_SANDBOX = @"doric-sandbox";
NSString *const DORIC_BUNDLE_LIB = @"doric-lib";
NSString *const DORIC_MODULE_LIB = @"doric";
NSString * const INJECT_LOG = @"nativeLog";
NSString * const INJECT_REQUIRE = @"nativeRequire";
NSString * const INJECT_TIMER_SET = @"nativeSetTimer";
NSString * const INJECT_TIMER_CLEAR = @"nativeClearTimer";
NSString * const INJECT_BRIDGE = @"nativeBridge";
NSString *const INJECT_LOG = @"nativeLog";
NSString *const INJECT_REQUIRE = @"nativeRequire";
NSString *const INJECT_TIMER_SET = @"nativeSetTimer";
NSString *const INJECT_TIMER_CLEAR = @"nativeClearTimer";
NSString *const INJECT_BRIDGE = @"nativeBridge";
NSString * const TEMPLATE_CONTEXT_CREATE = @"Reflect.apply("
"function(doric,context,Entry,require,exports){" "\n"
"%@" "\n"
"},doric.jsObtainContext(\"%@\"),["
"undefined,"
"doric.jsObtainContext(\"%@\"),"
"doric.jsObtainEntry(\"%@\"),"
"doric.__require__"
",{}"
"])";
NSString *const TEMPLATE_CONTEXT_CREATE = @"Reflect.apply("
"function(doric,context,Entry,require,exports){" "\n"
"%@" "\n"
"},doric.jsObtainContext(\"%@\"),["
"undefined,"
"doric.jsObtainContext(\"%@\"),"
"doric.jsObtainEntry(\"%@\"),"
"doric.__require__"
",{}"
"])";
NSString * const TEMPLATE_MODULE = @"Reflect.apply(doric.jsRegisterModule,this,["
"\"%@\","
"Reflect.apply(function(__module){"
"(function(module,exports,require){" "\n"
"%@" "\n"
"})(__module,__module.exports,doric.__require__);"
"\nreturn __module.exports;"
"},this,[{exports:{}}])"
"])";
NSString *const TEMPLATE_MODULE = @"Reflect.apply(doric.jsRegisterModule,this,["
"\"%@\","
"Reflect.apply(function(__module){"
"(function(module,exports,require){" "\n"
"%@" "\n"
"})(__module,__module.exports,doric.__require__);"
"\nreturn __module.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>
void DoricLog(NSString * _Nonnull format, ...);
void DoricLog(NSString *_Nonnull format, ...);
UIColor* _Nonnull DoricColor(NSNumber * _Nonnull number);
UIColor *_Nonnull DoricColor(NSNumber *_Nonnull number);
NSBundle *DoricBundle();

View File

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