From 581c732e6d71e4088c0869235685f117fd047864 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Mon, 4 Nov 2024 14:31:30 -0500 Subject: [PATCH] Use Fill instead of orientation --- .../cash/redwood/layout/uiview/YogaUIView.kt | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/YogaUIView.kt b/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/YogaUIView.kt index 9d214c5e9e..0622fa08c9 100644 --- a/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/YogaUIView.kt +++ b/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/YogaUIView.kt @@ -38,8 +38,8 @@ internal class YogaUIView : UIScrollView(cValue { CGRectZero }), UIScrollViewDel var onScroll: ((Px) -> Unit)? = null - private var widthForIntrinsicSize = UIViewNoIntrinsicMetric - private var heightForIntrinsicSize = UIViewNoIntrinsicMetric + private var fillWidth = UIViewNoIntrinsicMetric + private var fillHeight = UIViewNoIntrinsicMetric init { // TODO: Support scroll indicators. @@ -64,16 +64,22 @@ internal class YogaUIView : UIScrollView(cValue { CGRectZero }), UIScrollViewDel override fun setBounds(bounds: CValue) { val newWidth = bounds.useContents { size.width } val newHeight = bounds.useContents { size.height } - if (isColumn()) { - if (widthForIntrinsicSize != newWidth) { - invalidateIntrinsicContentSize() - this.widthForIntrinsicSize = newWidth - } - } else { - if (heightForIntrinsicSize != newHeight) { - invalidateIntrinsicContentSize() - this.heightForIntrinsicSize = newHeight - } + + // Invalidate first because it clears fillWidth and fillHeight. + if ( + (widthConstraint == Constraint.Fill && newWidth != fillWidth) || + (heightConstraint == Constraint.Fill && newHeight != fillHeight) + ) { + invalidateIntrinsicContentSize() + } + + this.fillWidth = when (widthConstraint) { + Constraint.Fill -> newWidth + else -> UIViewNoIntrinsicMetric + } + this.fillHeight = when (heightConstraint) { + Constraint.Fill -> newHeight + else -> UIViewNoIntrinsicMetric } super.setBounds(bounds) @@ -81,14 +87,14 @@ internal class YogaUIView : UIScrollView(cValue { CGRectZero }), UIScrollViewDel override fun invalidateIntrinsicContentSize() { super.invalidateIntrinsicContentSize() - this.widthForIntrinsicSize = UIViewNoIntrinsicMetric - this.heightForIntrinsicSize = UIViewNoIntrinsicMetric + this.fillWidth = UIViewNoIntrinsicMetric + this.fillHeight = UIViewNoIntrinsicMetric } override fun intrinsicContentSize(): CValue { return calculateLayout( - width = widthForIntrinsicSize.toYogaWithWidthConstraint(), - height = heightForIntrinsicSize.toYogaWithWidthConstraint(), + width = fillWidth.toYogaWithWidthConstraint(), + height = fillHeight.toYogaWithWidthConstraint(), ) }