From 814a4db151ea600eacdb3c98c54723bb92f61474 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Wed, 23 Oct 2024 14:09:06 -0400 Subject: [PATCH] Migrate Spacer implementations away from subtypes When widgets switch to abstract classes, this will no longer be allowed. --- .../cash/redwood/layout/uiview/UIViewSpacer.kt | 18 +++++++++--------- .../app/cash/redwood/layout/view/ViewSpacer.kt | 7 ++++--- .../layout/view/ViewFlexContainerTest.kt | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewSpacer.kt b/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewSpacer.kt index 89c07bdebe..40ceb9685f 100644 --- a/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewSpacer.kt +++ b/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewSpacer.kt @@ -45,17 +45,17 @@ internal class UIViewSpacer : Spacer { private fun invalidate() { value.setNeedsLayout() } +} - private inner class SpacerUIView : UIView(cValue { CGRectZero }) { - var width = 0.0 - var height = 0.0 +private class SpacerUIView : UIView(cValue { CGRectZero }) { + var width = 0.0 + var height = 0.0 - override fun intrinsicContentSize(): CValue { - return CGSizeMake(width, height) - } + override fun intrinsicContentSize(): CValue { + return CGSizeMake(width, height) + } - override fun sizeThatFits(size: CValue): CValue { - return CGSizeMake(width, height) - } + override fun sizeThatFits(size: CValue): CValue { + return CGSizeMake(width, height) } } diff --git a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewSpacer.kt b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewSpacer.kt index 5046ee23cf..e3fc496b8c 100644 --- a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewSpacer.kt +++ b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewSpacer.kt @@ -27,11 +27,10 @@ import kotlin.math.min internal class ViewSpacer( context: Context, -) : View(context), - Spacer { +) : Spacer { private val density = Density(context.resources) - override val value get() = this + override val value: View = SpacerView(context) override var modifier: Modifier = Modifier @@ -44,7 +43,9 @@ internal class ViewSpacer( value.minimumHeight = with(density) { height.toPxInt() } value.requestLayout() } +} +private class SpacerView(context: Context) : View(context) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { setMeasuredDimension( getDefaultSizeSpace(suggestedMinimumWidth, widthMeasureSpec), diff --git a/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt b/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt index 46dbd57a80..1bdea017b8 100644 --- a/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt +++ b/redwood-layout-view/src/test/kotlin/app/cash/redwood/layout/view/ViewFlexContainerTest.kt @@ -65,7 +65,7 @@ class ViewFlexContainerTest( override fun spacer(backgroundColor: Int): Spacer { return ViewSpacer(paparazzi.context) .apply { - setBackgroundColor(backgroundColor) + value.setBackgroundColor(backgroundColor) } }