feat:sync lost commits
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef UIEdgeInsets DoricMargin;
|
||||
typedef UIEdgeInsets DoricPadding;
|
||||
|
||||
DoricMargin DoricMarginMake(CGFloat left, CGFloat top, CGFloat right, CGFloat bottom);
|
||||
|
||||
@@ -82,6 +83,10 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
||||
@property(nonatomic, strong) DoricLayoutConfig *layoutConfig;
|
||||
@end
|
||||
|
||||
@interface UIView (DoricPadding)
|
||||
@property(nonatomic, assign) DoricPadding padding;
|
||||
@end
|
||||
|
||||
@interface UIView (DoricTag)
|
||||
@property(nonatomic, copy) NSString *tagString;
|
||||
|
||||
|
@@ -37,6 +37,24 @@ - (DoricLayoutConfig *)layoutConfig {
|
||||
|
||||
@end
|
||||
|
||||
static const void *kLayoutPadding = &kLayoutPadding;
|
||||
|
||||
@implementation UIView (DoricPadding)
|
||||
@dynamic padding;
|
||||
|
||||
- (void)setPadding:(DoricPadding)padding {
|
||||
objc_setAssociatedObject(self, kLayoutPadding, [NSValue value:&padding withObjCType:@encode(DoricPadding)], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (DoricPadding)padding {
|
||||
DoricPadding value;
|
||||
value.left = value.right = value.top = value.bottom = 0;
|
||||
[objc_getAssociatedObject(self, kLayoutPadding) getValue:&value];
|
||||
return value;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static const void *kTagString = &kTagString;
|
||||
|
||||
@implementation UIView (DoricTag)
|
||||
@@ -79,13 +97,15 @@ - (CGSize)measureSize:(CGSize)targetSize {
|
||||
|| config.heightSpec == DoricLayoutWrapContent) {
|
||||
height = targetSize.height - config.margin.top - config.margin.bottom;
|
||||
}
|
||||
|
||||
CGSize contentSize = [self sizeThatFits:CGSizeMake(width, height)];
|
||||
DoricPadding padding = self.padding;
|
||||
CGSize contentSize = [self sizeThatFits:CGSizeMake(
|
||||
width - padding.left - padding.right,
|
||||
height - padding.top - padding.bottom)];
|
||||
if (config.widthSpec == DoricLayoutWrapContent) {
|
||||
width = contentSize.width;
|
||||
width = contentSize.width + padding.left + padding.right;
|
||||
}
|
||||
if (config.heightSpec == DoricLayoutWrapContent) {
|
||||
height = contentSize.height;
|
||||
height = contentSize.height + padding.left + padding.top + padding.bottom;
|
||||
}
|
||||
return CGSizeMake(width, height);
|
||||
}
|
||||
@@ -208,6 +228,8 @@ - (CGSize)sizeThatFits:(CGSize)size {
|
||||
- (void)layoutSelf:(CGSize)targetSize {
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
DoricPadding padding = self.padding;
|
||||
|
||||
for (UIView *child in self.subviews) {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
@@ -219,33 +241,35 @@ - (void)layoutSelf:(CGSize)targetSize {
|
||||
if (!childConfig) {
|
||||
childConfig = [DoricLayoutConfig new];
|
||||
}
|
||||
CGSize size = [child measureSize:CGSizeMake(targetSize.width, targetSize.height)];
|
||||
CGSize size = [child measureSize:CGSizeMake(
|
||||
targetSize.width - padding.left - padding.right,
|
||||
targetSize.height - padding.top - padding.bottom)];
|
||||
[child layoutSelf:size];
|
||||
DoricGravity gravity = childConfig.alignment;
|
||||
if ((gravity & LEFT) == LEFT) {
|
||||
child.left = 0;
|
||||
child.left = padding.left;
|
||||
} else if ((gravity & RIGHT) == RIGHT) {
|
||||
child.right = targetSize.width;
|
||||
child.right = targetSize.width - padding.right;
|
||||
} else if ((gravity & CENTER_X) == CENTER_X) {
|
||||
child.centerX = targetSize.width / 2;
|
||||
child.centerX = (targetSize.width - padding.left - padding.right) / 2;
|
||||
} else {
|
||||
if (childConfig.margin.left) {
|
||||
child.left = childConfig.margin.left;
|
||||
child.left = childConfig.margin.left + padding.left;
|
||||
} else if (childConfig.margin.right) {
|
||||
child.right = targetSize.width - childConfig.margin.right;
|
||||
child.right = targetSize.width - childConfig.margin.right - padding.right;
|
||||
}
|
||||
}
|
||||
if ((gravity & TOP) == TOP) {
|
||||
child.top = 0;
|
||||
child.top = padding.top;
|
||||
} else if ((gravity & BOTTOM) == BOTTOM) {
|
||||
child.bottom = targetSize.height;
|
||||
child.bottom = targetSize.height - padding.bottom;
|
||||
} else if ((gravity & CENTER_Y) == CENTER_Y) {
|
||||
child.centerY = targetSize.height / 2;
|
||||
child.centerY = (targetSize.height - padding.top - padding.bottom) / 2;
|
||||
} else {
|
||||
if (childConfig.margin.top) {
|
||||
child.top = childConfig.margin.top;
|
||||
child.top = childConfig.margin.top + padding.top;
|
||||
} else if (childConfig.margin.bottom) {
|
||||
child.bottom = targetSize.height - childConfig.margin.bottom;
|
||||
child.bottom = targetSize.height - childConfig.margin.bottom - padding.bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -292,15 +316,16 @@ - (CGSize)sizeThatFits:(CGSize)size {
|
||||
- (void)layoutSelf:(CGSize)targetSize {
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
CGFloat yStart = 0;
|
||||
DoricPadding padding = self.padding;
|
||||
CGFloat yStart = padding.top;
|
||||
if ((self.gravity & TOP) == TOP) {
|
||||
yStart = 0;
|
||||
yStart = padding.top;
|
||||
} else if ((self.gravity & BOTTOM) == BOTTOM) {
|
||||
yStart = targetSize.height - self.contentHeight;
|
||||
yStart = targetSize.height - self.contentHeight - padding.bottom;
|
||||
} else if ((self.gravity & CENTER_Y) == CENTER_Y) {
|
||||
yStart = (targetSize.height - self.contentHeight) / 2;
|
||||
yStart = (targetSize.height - self.contentHeight - padding.top - padding.bottom) / 2;
|
||||
}
|
||||
CGFloat remain = targetSize.height - self.contentHeight;
|
||||
CGFloat remain = targetSize.height - self.contentHeight - padding.top - padding.bottom;
|
||||
for (UIView *child in self.subviews) {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
@@ -313,24 +338,26 @@ - (void)layoutSelf:(CGSize)targetSize {
|
||||
childConfig = [DoricLayoutConfig new];
|
||||
}
|
||||
|
||||
CGSize size = [child measureSize:CGSizeMake(targetSize.width, targetSize.height - yStart)];
|
||||
CGSize size = [child measureSize:CGSizeMake(
|
||||
targetSize.width - padding.left - padding.right,
|
||||
targetSize.height - yStart - padding.bottom)];
|
||||
if (childConfig.weight) {
|
||||
size.height += remain / self.contentWeight * childConfig.weight;
|
||||
}
|
||||
[child layoutSelf:size];
|
||||
DoricGravity gravity = childConfig.alignment | self.gravity;
|
||||
if ((gravity & LEFT) == LEFT) {
|
||||
child.left = 0;
|
||||
child.left = padding.left;
|
||||
} else if ((gravity & RIGHT) == RIGHT) {
|
||||
child.right = self.width;
|
||||
child.right = self.width - padding.right;
|
||||
} else if ((gravity & CENTER_X) == CENTER_X) {
|
||||
child.centerX = targetSize.width / 2;
|
||||
child.centerX = (targetSize.width - padding.left - padding.right) / 2;
|
||||
} else if (childConfig.margin.left) {
|
||||
child.left = childConfig.margin.left + padding.left;
|
||||
} else if (childConfig.margin.right) {
|
||||
child.right = targetSize.width - childConfig.margin.right - padding.right;
|
||||
} else {
|
||||
if (childConfig.margin.left) {
|
||||
child.left = childConfig.margin.left;
|
||||
} else if (childConfig.margin.right) {
|
||||
child.right = targetSize.width - childConfig.margin.right;
|
||||
}
|
||||
child.left = padding.left;
|
||||
}
|
||||
if (childConfig.margin.top) {
|
||||
yStart += childConfig.margin.top;
|
||||
@@ -380,17 +407,16 @@ - (CGSize)sizeThatFits:(CGSize)size {
|
||||
- (void)layoutSelf:(CGSize)targetSize {
|
||||
self.width = targetSize.width;
|
||||
self.height = targetSize.height;
|
||||
CGFloat xStart = 0;
|
||||
if (self.contentWeight) {
|
||||
xStart = 0;
|
||||
} else if ((self.gravity & LEFT) == LEFT) {
|
||||
xStart = 0;
|
||||
DoricPadding padding = self.padding;
|
||||
CGFloat xStart = padding.left;
|
||||
if ((self.gravity & LEFT) == LEFT) {
|
||||
xStart = padding.left;
|
||||
} else if ((self.gravity & RIGHT) == RIGHT) {
|
||||
xStart = targetSize.width - self.contentWidth;
|
||||
xStart = targetSize.width - self.contentWidth - padding.right;
|
||||
} else if ((self.gravity & CENTER_X) == CENTER_X) {
|
||||
xStart = (targetSize.width - self.contentWidth) / 2;
|
||||
xStart = (targetSize.width - self.contentWidth - padding.left - padding.right) / 2;
|
||||
}
|
||||
CGFloat remain = targetSize.width - self.contentWidth;
|
||||
CGFloat remain = targetSize.width - self.contentWidth - padding.left - padding.right;
|
||||
for (UIView *child in self.subviews) {
|
||||
if (child.isHidden) {
|
||||
continue;
|
||||
@@ -403,7 +429,9 @@ - (void)layoutSelf:(CGSize)targetSize {
|
||||
childConfig = [DoricLayoutConfig new];
|
||||
}
|
||||
|
||||
CGSize size = [child measureSize:CGSizeMake(targetSize.width - xStart, targetSize.height)];
|
||||
CGSize size = [child measureSize:CGSizeMake(
|
||||
targetSize.width - xStart - padding.right,
|
||||
targetSize.height - padding.top - padding.bottom)];
|
||||
if (childConfig.weight) {
|
||||
size.width += remain / self.contentWeight * childConfig.weight;
|
||||
}
|
||||
@@ -412,17 +440,17 @@ - (void)layoutSelf:(CGSize)targetSize {
|
||||
|
||||
DoricGravity gravity = childConfig.alignment | self.gravity;
|
||||
if ((gravity & TOP) == TOP) {
|
||||
child.top = 0;
|
||||
child.top = padding.top;
|
||||
} else if ((gravity & BOTTOM) == BOTTOM) {
|
||||
child.bottom = targetSize.height;
|
||||
child.bottom = targetSize.height - padding.bottom;
|
||||
} else if ((gravity & CENTER_Y) == CENTER_Y) {
|
||||
child.centerY = targetSize.height / 2;
|
||||
child.centerY = (targetSize.height - padding.top - padding.bottom) / 2;
|
||||
} else if (childConfig.margin.top) {
|
||||
child.top = childConfig.margin.top + padding.top;
|
||||
} else if (childConfig.margin.bottom) {
|
||||
child.bottom = targetSize.height - childConfig.margin.bottom - padding.bottom;
|
||||
} else {
|
||||
if (childConfig.margin.top) {
|
||||
child.top = childConfig.margin.top;
|
||||
} else if (childConfig.margin.bottom) {
|
||||
child.bottom = targetSize.height - childConfig.margin.bottom;
|
||||
}
|
||||
child.top = padding.top;
|
||||
}
|
||||
|
||||
if (childConfig.margin.left) {
|
||||
|
@@ -235,7 +235,6 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
||||
} else {
|
||||
view.clipsToBounds = YES;
|
||||
}
|
||||
|
||||
} else if ([name isEqualToString:@"translationX"]) {
|
||||
self.translationX = prop;
|
||||
} else if ([name isEqualToString:@"translationY"]) {
|
||||
@@ -250,6 +249,17 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
||||
self.pivotY = prop;
|
||||
} else if ([name isEqualToString:@"rotation"]) {
|
||||
self.rotation = prop;
|
||||
} else if ([name isEqualToString:@"padding"]) {
|
||||
DoricPadding padding;
|
||||
padding.left = padding.right = padding.top = padding.bottom = 0;
|
||||
if ([prop isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *dictionary = prop;
|
||||
padding.left = [dictionary[@"left"] floatValue];
|
||||
padding.right = [dictionary[@"right"] floatValue];
|
||||
padding.top = [dictionary[@"top"] floatValue];
|
||||
padding.bottom = [dictionary[@"bottom"] floatValue];
|
||||
}
|
||||
self.view.padding = padding;
|
||||
} else {
|
||||
DoricLog(@"Blend View error for View Type :%@, prop is %@", self.class, name);
|
||||
}
|
||||
@@ -357,6 +367,8 @@ - (NSDictionary *)transformation {
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
#pragma animations
|
||||
|
||||
- (void)doAnimation:(id)params withPromise:(DoricPromise *)promise {
|
||||
CAAnimation *animation = [self parseAnimation:params];
|
||||
AnimationCallback *originDelegate = animation.delegate;
|
||||
@@ -371,6 +383,7 @@ - (void)doAnimation:(id)params withPromise:(DoricPromise *)promise {
|
||||
if (originDelegate) {
|
||||
originDelegate.endBlock(callback);
|
||||
}
|
||||
[self.view.layer removeAllAnimations];
|
||||
[self transformProperties];
|
||||
[promise resolve:self.transformation];
|
||||
};
|
||||
@@ -379,6 +392,8 @@ - (void)doAnimation:(id)params withPromise:(DoricPromise *)promise {
|
||||
if (params[@"delay"]) {
|
||||
animation.beginTime = CACurrentMediaTime() + [params[@"delay"] floatValue] / 1000;
|
||||
}
|
||||
animation.removedOnCompletion = NO;
|
||||
animation.fillMode = kCAFillModeForwards;
|
||||
[self.view.layer addAnimation:animation forKey:nil];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user