add ts define

This commit is contained in:
pengfei.zhou
2020-04-09 17:07:24 +08:00
committed by osborn
parent dd06675253
commit 404b4b594f
13 changed files with 485 additions and 1 deletions

View File

@@ -52,6 +52,7 @@
#import "DoricCoordinatorPlugin.h"
#import "DoricSwitchNode.h"
#import "DoricNotchPlugin.h"
#import "DoricFlexNode.h"
@interface DoricLibraries : NSObject
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries;
@@ -139,6 +140,7 @@ - (void)innerRegister {
[self registerViewNode:DoricInputNode.class withName:@"Input"];
[self registerViewNode:DoricDraggableNode.class withName:@"Draggable"];
[self registerViewNode:DoricSwitchNode.class withName:@"Switch"];
[self registerViewNode:DoricFlexNode.class withName:@"FlexLayout"];
}
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {

View File

@@ -0,0 +1,25 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// Created by pengfei.zhou on 2020/4/9.
//
#import <Foundation/Foundation.h>
#import "DoricGroupNode.h"
@interface DoricFlexNode : DoricGroupNode <UIView *>
- (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexConfig;
@end

View File

@@ -0,0 +1,119 @@
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// Created by pengfei.zhou on 2020/4/9.
//
#import <YogaKit/UIView+Yoga.h>
#import "DoricFlexNode.h"
#import "DoricExtensions.h"
#import "YGLayout.h"
@interface DoricFlexView : UIView
@end
@implementation DoricFlexView
- (CGSize)sizeThatFits:(CGSize)size {
return [self.yoga calculateLayoutWithSize:size];
}
@end
@implementation DoricFlexNode
- (UIView *)build {
return [[DoricFlexView new] also:^(DoricFlexView *it) {
it.yoga.isEnabled = YES;
}];
}
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([name isEqualToString:@"flexConfig"]) {
if ([prop isKindOfClass:[NSDictionary class]]) {
[((DoricFlexNode *) self.superNode) blendSubNode:self flexConfig:prop];
}
} else {
[super blendView:view forPropName:name propValue:prop];
}
}
- (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexConfig {
}
- (void)blendYoga:(YGLayout *)yoga from:(NSDictionary *)flexConfig {
[flexConfig enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
[self blendYoga:yoga name:key value:obj];
}];
}
- (void)blendYoga:(YGLayout *)yoga name:(NSString *)name value:(id)value {
if ([name isEqualToString:@"direction"]) {
yoga.direction = (YGDirection) [(NSNumber *) value integerValue];
} else if ([name isEqualToString:@"flexDirection"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
} else if ([name isEqualToString:@"justifyContent"]) {
yoga.justifyContent = (YGJustify) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"alignContent"]) {
yoga.alignContent = (YGAlign) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}else if ([name isEqualToString:@"justifyContent"]) {
yoga.flexDirection = (YGFlexDirection) [(NSNumber *) value integerValue];
}
}
- (void)requestLayout {
[super requestLayout];
[self.view.yoga applyLayoutPreservingOrigin:NO];
}
@end

View File

@@ -29,6 +29,7 @@
#import "DoricSuperNode.h"
#import "DoricExtensions.h"
#import "DoricPromise.h"
#import "DoricFlexNode.h"
void DoricAddEllipticArcPath(CGMutablePathRef path,
CGPoint origin,
@@ -264,6 +265,11 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
} else if ([name isEqualToString:@"hidden"]) {
self.view.hidden = [prop boolValue];
self.view.doricLayout.disabled = [prop boolValue];
} else if ([name isEqualToString:@"flexConfig"]) {
if ([prop isKindOfClass:[NSDictionary class]]
&& [self.superNode isKindOfClass:[DoricFlexNode class]]) {
[((DoricFlexNode *) self.superNode) blendSubNode:self flexConfig:prop];
}
} else {
DoricLog(@"Blend View error for View Type :%@, prop is %@", self.class, name);
}