iOS module dir
This commit is contained in:
28
iOS/Pod/Classes/Util/DoricAsyncResult.h
Normal file
28
iOS/Pod/Classes/Util/DoricAsyncResult.h
Normal 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
|
63
iOS/Pod/Classes/Util/DoricAsyncResult.m
Normal file
63
iOS/Pod/Classes/Util/DoricAsyncResult.m
Normal 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
|
39
iOS/Pod/Classes/Util/DoricConstant.h
Normal file
39
iOS/Pod/Classes/Util/DoricConstant.h
Normal 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;
|
56
iOS/Pod/Classes/Util/DoricConstant.m
Normal file
56
iOS/Pod/Classes/Util/DoricConstant.m
Normal 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__";
|
12
iOS/Pod/Classes/Util/DoricUtil.h
Normal file
12
iOS/Pod/Classes/Util/DoricUtil.h
Normal 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);
|
25
iOS/Pod/Classes/Util/DoricUtil.m
Normal file
25
iOS/Pod/Classes/Util/DoricUtil.m
Normal 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];
|
||||
}
|
Reference in New Issue
Block a user