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

@ -23,6 +23,7 @@ - (instancetype)initWithUrl:(NSString *)url {
}
return self;
}
- (void)webSocketDidOpen:(SRWebSocket *)webSocket {
DoricLog(@"webSocketDidOpen");
}

View File

@ -7,6 +7,7 @@
#import <Foundation/Foundation.h>
#import "DoricContext.h"
NS_ASSUME_NONNULL_BEGIN
@interface DoricContextHolder : NSObject

View File

@ -23,14 +23,19 @@ NS_ASSUME_NONNULL_BEGIN
@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 argumentsArray:(NSArray *)args;
- (void)connectDevKit:(NSString *)url;
- (void)disconnectDevKit;
@end

View File

@ -99,6 +99,7 @@ - (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];

View File

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

View File

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

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

@ -16,6 +16,7 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
}
return self;
}
- (UIView *)build:(NSDictionary *)props {
UIView *ret = [[UIView alloc] init];
ret.clipsToBounds = YES;
@ -32,15 +33,15 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
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,18 +62,18 @@ - (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];
[node.view removeFromSuperview];
@ -81,7 +82,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
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) {
@ -101,12 +102,12 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
LayoutParams *params = child.layoutParams;
if ([params isKindOfClass:MarginLayoutParams.class]) {
MarginLayoutParams *marginParams = (MarginLayoutParams *) params;
NSDictionary *margin = [layoutconfig objectForKey:@"margin"];
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

@ -39,6 +39,7 @@ - (void)measureByParent:(DoricGroupNode *)parent {
self.height = maxHeight;
}
}
- (LayoutParams *)generateDefaultLayoutParams {
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.bottom = [(NSNumber *)[margin objectForKey:@"bottom"] floatValue];
// }
NSNumber *alignment = [layoutconfig objectForKey:@"alignment"];
NSNumber *alignment = layoutconfig[@"alignment"];
if (alignment) {
params.alignment = [alignment integerValue];
}

View File

@ -34,14 +34,14 @@ - (void)blendChild:(DoricViewNode *)child layoutConfig:(NSDictionary *)layoutcon
return;
}
VHLayoutParams *params = (VHLayoutParams *) child.layoutParams;
NSDictionary *margin = [layoutconfig objectForKey:@"margin"];
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];
}

View File

@ -38,7 +38,6 @@ NS_ASSUME_NONNULL_BEGIN
@end
@interface LayoutParams : NSObject
@property(nonatomic) DoricLayoutDesc width;
@property(nonatomic) DoricLayoutDesc height;

View File

@ -29,13 +29,15 @@ - (instancetype)init {
return self;
}
@end
@implementation MarginLayoutParams
- (instancetype)init {
if (self = [super init]) {
_margin = [[DoricRect alloc] init];
}
return self;
}@end
}
@end
@implementation StackLayoutParams
- (instancetype)init {
@ -43,7 +45,8 @@ - (instancetype)init {
_alignment = 0;
}
return self;
}@end
}
@end
@implementation VHLayoutParams
- (instancetype)init {

View File

@ -49,7 +49,6 @@ CGPathRef DoricCreateRoundedRectPath(CGRect bounds,
}
@interface DoricViewNode ()
@property(nonatomic, strong) NSMutableDictionary *callbackIds;
@end
@ -62,6 +61,7 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
}
return self;
}
- (UIView *)build:(NSDictionary *)props {
return [[UIView alloc] init];
}

View File

@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIView.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIView (Doric)

View File

@ -12,7 +12,9 @@ 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;
@ -20,8 +22,11 @@ typedef void(^DoricFinishCallback)(void);
@property(nonatomic, strong) DoricFinishCallback finishCallback;
- (void)setupResult:(R)result;
- (void)setupError:(NSException *)exception;
- (BOOL)hasResult;
- (R)getResult;
@end