iOS module dir

This commit is contained in:
pengfei.zhou
2019-07-30 15:20:11 +08:00
parent 6e6dc4edef
commit c1fde16bee
77 changed files with 610 additions and 305 deletions

View File

@@ -0,0 +1,28 @@
//
// DoricAsyncResult.h
// Doric
//
// Created by pengfei.zhou on 2019/7/26.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@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;
- (void)setupResult:(R)result;
- (void)setupError:(NSException*)exception;
- (BOOL)hasResult;
- (R)getResult;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,63 @@
//
// DoricAsyncResult.m
// Doric
//
// Created by pengfei.zhou on 2019/7/26.
//
#import "DoricAsyncResult.h"
@interface DoricAsyncResult()
@property(nonatomic,strong) id result;
@end
@implementation DoricAsyncResult
- (void)setupResult:(id)result {
self.result = result;
if(self.resultCallback){
self.resultCallback(result);
}
if(self.finishCallback){
self.finishCallback();
}
}
- (void)setupError:(NSException *)exception {
self.result = exception;
if(self.exceptionCallback){
self.exceptionCallback(exception);
}
if(self.finishCallback){
self.finishCallback();
}
}
- (BOOL)hasResult {
return self.result;
}
- (id)getResult {
return self.result;
}
- (void)setResultCallback:(DoricResultCallback)callback {
_resultCallback = callback;
if(self.result && ![self.result isKindOfClass: [NSException class]]){
callback(self.result);
}
}
- (void)setExceptionCallback:(DoricExceptionCallback)exceptionCallback {
_exceptionCallback = exceptionCallback;
if([self.result isKindOfClass: [NSException class]]){
exceptionCallback(self.result);
}
}
- (void)setFinishCallback:(DoricFinishCallback)callback {
_finishCallback = callback;
if(self.result){
callback();
}
}
@end

View File

@@ -0,0 +1,39 @@
//
// DoricConstant.h
// Doric
//
// Created by pengfei.zhou on 2019/7/26.
//
#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 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_MODULE;
extern NSString * const TEMPLATE_CONTEXT_DESTROY;
extern NSString * const GLOBAL_DORIC;
extern NSString * const DORIC_CONTEXT_RELEASE;
extern NSString * const DORIC_CONTEXT_INVOKE;
extern NSString * const DORIC_TIMER_CALLBACK;
extern NSString * const DORIC_BRIDGE_RESOLVE;
extern NSString * const DORIC_BRIDGE_REJECT;
extern NSString * const DORIC_ENTITY_RESPONSE;

View File

@@ -0,0 +1,56 @@
//
// DoricConstant.m
// Doric
//
// Created by pengfei.zhou on 2019/7/26.
//
#import "DoricConstant.h"
NSString * const DORIC_BUNDLE_SANDBOX = @"doric-sandbox";
NSString * const DORIC_BUNDLE_LIB = @"doric-lib";
NSString * const DORIC_MODULE_LIB = @"./index";
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_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 GLOBAL_DORIC = @"doric";
NSString * const DORIC_CONTEXT_RELEASE = @"jsReleaseContext";
NSString * const DORIC_CONTEXT_INVOKE = @"jsCallEntityMethod";
NSString * const DORIC_TIMER_CALLBACK = @"jsCallbackTimer";
NSString * const DORIC_BRIDGE_RESOLVE = @"jsCallResolve";
NSString * const DORIC_BRIDGE_REJECT = @"jsCallReject";
NSString * const DORIC_ENTITY_RESPONSE = @"__response__";

View File

@@ -0,0 +1,12 @@
//
// DoricUtil.h
// Doric
//
// Created by pengfei.zhou on 2019/7/26.
//
#import <Foundation/Foundation.h>
void DoricLog(NSString * _Nonnull format, ...);
UIColor* _Nonnull DoricColor(NSNumber * _Nonnull number);

View File

@@ -0,0 +1,25 @@
//
// DoricUtil.m
// Doric
//
// Created by pengfei.zhou on 2019/7/26.
//
#import "DoricUtil.h"
void DoricLog(NSString * _Nonnull format, ...) {
va_list args;
va_start(args, format);
NSLogv([NSString stringWithFormat:@"Doric:%@",format],args);
va_end(args);
}
UIColor *DoricColor(NSNumber *number) {
CGFloat r, g, b, a;
long colorValue = [number longValue];
a = ((colorValue >> 6) & 0xff)/225.0f;
r = ((colorValue >> 4) & 0xff)/225.0f;
g = ((colorValue >> 2) & 0xff)/225.0f;
b = ((colorValue >> 0) & 0xff)/225.0f;
return [UIColor colorWithRed:r green:g blue:b alpha:a];
}