format OC code
This commit is contained in:
parent
820f1e9f8c
commit
f9b599e7cf
1
iOS/Example/.gitignore
vendored
Normal file
1
iOS/Example/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea/
|
@ -23,6 +23,7 @@ - (instancetype)initWithUrl:(NSString *)url {
|
|||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)webSocketDidOpen:(SRWebSocket *)webSocket {
|
- (void)webSocketDidOpen:(SRWebSocket *)webSocket {
|
||||||
DoricLog(@"webSocketDidOpen");
|
DoricLog(@"webSocketDidOpen");
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#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
|
||||||
|
@ -23,14 +23,19 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@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
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ - (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];
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#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>
|
||||||
|
@ -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
|
||||||
|
@ -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"]];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
|
|||||||
}
|
}
|
||||||
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;
|
||||||
@ -32,15 +33,15 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
|||||||
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,18 +62,18 @@ - (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];
|
||||||
@ -81,7 +82,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
|||||||
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) {
|
||||||
@ -101,12 +102,12 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
|
|||||||
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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];
|
||||||
}
|
}
|
||||||
@ -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];
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,14 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
|
|||||||
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];
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@interface LayoutParams : NSObject
|
@interface LayoutParams : NSObject
|
||||||
@property(nonatomic) DoricLayoutDesc width;
|
@property(nonatomic) DoricLayoutDesc width;
|
||||||
@property(nonatomic) DoricLayoutDesc height;
|
@property(nonatomic) DoricLayoutDesc height;
|
||||||
|
@ -29,13 +29,15 @@ - (instancetype)init {
|
|||||||
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 {
|
||||||
@ -43,7 +45,8 @@ - (instancetype)init {
|
|||||||
_alignment = 0;
|
_alignment = 0;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}@end
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation VHLayoutParams
|
@implementation VHLayoutParams
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
|
@ -49,7 +49,6 @@ CGPathRef DoricCreateRoundedRectPath(CGRect bounds,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@interface DoricViewNode ()
|
@interface DoricViewNode ()
|
||||||
@property(nonatomic, strong) NSMutableDictionary *callbackIds;
|
@property(nonatomic, strong) NSMutableDictionary *callbackIds;
|
||||||
@end
|
@end
|
||||||
@ -62,6 +61,7 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
|
|||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIView *)build:(NSDictionary *)props {
|
- (UIView *)build:(NSDictionary *)props {
|
||||||
return [[UIView alloc] init];
|
return [[UIView alloc] init];
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#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)
|
||||||
|
@ -12,7 +12,9 @@ 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;
|
||||||
@ -20,8 +22,11 @@ typedef void(^DoricFinishCallback)(void);
|
|||||||
@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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user