iOS:keep iOS behavior align to android

This commit is contained in:
pengfei.zhou 2020-04-10 11:37:48 +08:00 committed by osborn
parent fb23a11aa9
commit 89333e2252
3 changed files with 35 additions and 10 deletions

View File

@ -27,14 +27,14 @@ @interface DoricFlexView : UIView
@implementation DoricFlexView
- (CGSize)sizeThatFits:(CGSize)size {
return [self.yoga calculateLayoutWithSize:size];
return [self.yoga intrinsicSize];
}
@end
@implementation DoricFlexNode
- (UIView *)build {
return [[DoricFlexView new] also:^(DoricFlexView *it) {
[it configureLayoutWithBlock:^(YGLayout * _Nonnull layout) {
[it configureLayoutWithBlock:^(YGLayout *_Nonnull layout) {
layout.isEnabled = YES;
}];
}];
@ -49,7 +49,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
}
- (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexConfig {
[subNode.view configureLayoutWithBlock:^(YGLayout * _Nonnull layout) {
[subNode.view configureLayoutWithBlock:^(YGLayout *_Nonnull layout) {
layout.isEnabled = YES;
}];
[self blendYoga:subNode.view.yoga from:flexConfig];
@ -195,8 +195,33 @@ - (YGValue)translateYGValueFromProperty:(id)prop {
- (void)requestLayout {
[super requestLayout];
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[DoricFlexView class]]) {
continue;
}
[view.doricLayout apply];
}
if (self.view.doricLayout.widthSpec != DoricLayoutFit) {
self.view.yoga.width = YGPointValue(self.view.width);
}
if (self.view.doricLayout.heightSpec != DoricLayoutFit) {
self.view.yoga.height = YGPointValue(self.view.height);
}
[self.view.yoga applyLayoutPreservingOrigin:YES];
/// Need layout again.
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[DoricFlexView class]]) {
continue;
}
if (view.doricLayout.measuredWidth == view.width && view.doricLayout.measuredHeight == view.height) {
continue;
}
view.doricLayout.widthSpec = DoricLayoutJust;
view.doricLayout.heightSpec = DoricLayoutJust;
view.doricLayout.width = view.width;
view.doricLayout.height = view.height;
view.doricLayout.measuredX = view.left;
view.doricLayout.measuredY = view.top;
[view.doricLayout apply];
}
[self.view.yoga applyLayoutPreservingOrigin:NO];
}
@end

View File

@ -92,6 +92,11 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
@property(nonatomic, assign) BOOL resolved;
@property(nonatomic, assign) CGFloat measuredWidth;
@property(nonatomic, assign) CGFloat measuredHeight;
@property(nonatomic, assign) CGFloat measuredX;
@property(nonatomic, assign) CGFloat measuredY;
- (instancetype)init;
- (void)apply;

View File

@ -48,11 +48,6 @@ - (DoricLayout *)doricLayout {
@interface DoricLayout ()
@property(nonatomic, assign) CGFloat contentWidth;
@property(nonatomic, assign) CGFloat contentHeight;
@property(nonatomic, assign) CGFloat measuredWidth;
@property(nonatomic, assign) CGFloat measuredHeight;
@property(nonatomic, assign) CGFloat measuredX;
@property(nonatomic, assign) CGFloat measuredY;
@end
@implementation DoricLayout