iOS:Fix nested use of FlexLayout

This commit is contained in:
pengfei.zhou 2020-04-13 11:57:31 +08:00 committed by osborn
parent d29ff4991d
commit 5a8a855f89
3 changed files with 16 additions and 9 deletions

View File

@ -28,14 +28,16 @@ @interface DoricFlexView : UIView
@implementation DoricFlexView
- (CGSize)sizeThatFits:(CGSize)size {
for (UIView *view in self.subviews) {
if (!view.doricLayout.disabled) {
[view.doricLayout apply];
[view configureLayoutWithBlock:^(YGLayout *layout) {
layout.isEnabled = YES;
[view.doricLayout measure:size];
[view configureLayoutWithBlock:^(YGLayout *layout) {
layout.isEnabled = YES;
if (layout.width.unit == YGUnitUndefined || layout.width.unit == YGUnitAuto) {
layout.width = YGPointValue(view.doricLayout.measuredWidth);
}
if (layout.height.unit == YGUnitUndefined || layout.height.unit == YGUnitAuto) {
layout.height = YGPointValue(view.doricLayout.measuredHeight);
}];
}
}
}];
}
return [self.yoga intrinsicSize];
}
@ -205,8 +207,6 @@ - (YGValue)translateYGValueFromProperty:(id)prop {
}
- (void)requestLayout {
[super requestLayout];
if (self.view.doricLayout.widthSpec != DoricLayoutFit) {
self.view.yoga.width = YGPointValue(self.view.width);
}
@ -230,5 +230,6 @@ - (void)requestLayout {
view.doricLayout.measuredY = view.top;
[view.doricLayout apply];
}
[super requestLayout];
}
@end

View File

@ -103,6 +103,8 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
- (instancetype)init;
- (void)measure:(CGSize)targetSize;
- (void)apply;
- (void)apply:(CGSize)frameSize;

View File

@ -66,7 +66,6 @@ - (instancetype)init {
- (void)apply:(CGSize)frameSize {
self.resolved = NO;
[self measure:frameSize];
[self layout];
[self setFrame];
self.resolved = YES;
}
@ -76,6 +75,11 @@ - (void)apply {
}
- (void)measure:(CGSize)targetSize {
[self measureSelf:targetSize];
[self layout];
}
- (void)measureSelf:(CGSize)targetSize {
CGFloat width;
CGFloat height;
if (self.widthSpec == DoricLayoutMost) {