From dc56d9706f57b32b62f04d6850d2945c3df72d54 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 22 Oct 2024 12:31:24 -0400 Subject: [PATCH] Remove public FlexContainer type This only serves internal abstractions which are soon changing in a way that's incompatible with it. --- .../redwood/buildsupport/flexboxHelpers.kt | 27 ++++++++++-- .../HTMLElementRedwoodLayoutWidgetFactory.kt | 24 +++++++++-- .../layout/uiview/UIViewFlexContainerTest.kt | 3 +- .../api/redwood-layout-widget.api | 9 ---- .../api/redwood-layout-widget.klib.api | 9 ---- .../redwood/layout/widget/FlexContainer.kt | 43 ------------------- 6 files changed, 44 insertions(+), 71 deletions(-) delete mode 100644 redwood-layout-widget/src/commonMain/kotlin/app/cash/redwood/layout/widget/FlexContainer.kt diff --git a/build-support/src/main/resources/app/cash/redwood/buildsupport/flexboxHelpers.kt b/build-support/src/main/resources/app/cash/redwood/buildsupport/flexboxHelpers.kt index 57f7b4922e..b09f8ceff1 100644 --- a/build-support/src/main/resources/app/cash/redwood/buildsupport/flexboxHelpers.kt +++ b/build-support/src/main/resources/app/cash/redwood/buildsupport/flexboxHelpers.kt @@ -27,7 +27,8 @@ import app.cash.redwood.layout.modifier.Shrink as ShrinkModifier import app.cash.redwood.layout.modifier.Size as SizeModifier import app.cash.redwood.layout.modifier.VerticalAlignment as VerticalAlignmentModifier import app.cash.redwood.layout.modifier.Width as WidthModifier -import app.cash.redwood.layout.widget.FlexContainer +import app.cash.redwood.layout.widget.Column +import app.cash.redwood.layout.widget.Row import app.cash.redwood.ui.Density import app.cash.redwood.ui.Margin import app.cash.redwood.yoga.AlignItems @@ -35,7 +36,9 @@ import app.cash.redwood.yoga.AlignSelf import app.cash.redwood.yoga.JustifyContent import app.cash.redwood.yoga.Node -internal interface YogaFlexContainer : FlexContainer { +internal interface YogaFlexContainer : + Column, + Row { val rootNode: Node val density: Density @@ -50,11 +53,27 @@ internal interface YogaFlexContainer : FlexContainer { } } - override fun crossAxisAlignment(crossAxisAlignment: CrossAxisAlignment) { + override fun horizontalAlignment(horizontalAlignment: MainAxisAlignment) { + mainAxisAlignment(horizontalAlignment) + } + + override fun horizontalAlignment(horizontalAlignment: CrossAxisAlignment) { + crossAxisAlignment(horizontalAlignment) + } + + override fun verticalAlignment(verticalAlignment: MainAxisAlignment) { + mainAxisAlignment(verticalAlignment) + } + + override fun verticalAlignment(verticalAlignment: CrossAxisAlignment) { + crossAxisAlignment(verticalAlignment) + } + + fun crossAxisAlignment(crossAxisAlignment: CrossAxisAlignment) { rootNode.alignItems = crossAxisAlignment.toAlignItems() } - override fun mainAxisAlignment(mainAxisAlignment: MainAxisAlignment) { + fun mainAxisAlignment(mainAxisAlignment: MainAxisAlignment) { rootNode.justifyContent = mainAxisAlignment.toJustifyContent() } } diff --git a/redwood-layout-dom/src/commonMain/kotlin/app/cash/redwood/layout/dom/HTMLElementRedwoodLayoutWidgetFactory.kt b/redwood-layout-dom/src/commonMain/kotlin/app/cash/redwood/layout/dom/HTMLElementRedwoodLayoutWidgetFactory.kt index 71d0f9bd3e..0b3250d29e 100644 --- a/redwood-layout-dom/src/commonMain/kotlin/app/cash/redwood/layout/dom/HTMLElementRedwoodLayoutWidgetFactory.kt +++ b/redwood-layout-dom/src/commonMain/kotlin/app/cash/redwood/layout/dom/HTMLElementRedwoodLayoutWidgetFactory.kt @@ -29,7 +29,6 @@ import app.cash.redwood.layout.modifier.Size import app.cash.redwood.layout.modifier.Width import app.cash.redwood.layout.widget.Box import app.cash.redwood.layout.widget.Column -import app.cash.redwood.layout.widget.FlexContainer import app.cash.redwood.layout.widget.RedwoodLayoutWidgetFactory import app.cash.redwood.layout.widget.Row import app.cash.redwood.layout.widget.Spacer @@ -75,7 +74,8 @@ private class HTMLFlexContainer( override val value: HTMLDivElement, direction: String, private val overflowSetter: HTMLDivElement.(String) -> Unit, -) : FlexContainer { +) : Column, + Row { init { value.style.display = "flex" value.style.flexDirection = direction @@ -127,11 +127,27 @@ private class HTMLFlexContainer( } } - override fun crossAxisAlignment(crossAxisAlignment: CrossAxisAlignment) { + override fun horizontalAlignment(horizontalAlignment: MainAxisAlignment) { + mainAxisAlignment(horizontalAlignment) + } + + override fun horizontalAlignment(horizontalAlignment: CrossAxisAlignment) { + crossAxisAlignment(horizontalAlignment) + } + + override fun verticalAlignment(verticalAlignment: MainAxisAlignment) { + mainAxisAlignment(verticalAlignment) + } + + override fun verticalAlignment(verticalAlignment: CrossAxisAlignment) { + crossAxisAlignment(verticalAlignment) + } + + private fun crossAxisAlignment(crossAxisAlignment: CrossAxisAlignment) { value.style.alignItems = crossAxisAlignment.toCss() } - override fun mainAxisAlignment(mainAxisAlignment: MainAxisAlignment) { + private fun mainAxisAlignment(mainAxisAlignment: MainAxisAlignment) { value.style.justifyContent = mainAxisAlignment.toCss() } diff --git a/redwood-layout-uiview/src/commonTest/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainerTest.kt b/redwood-layout-uiview/src/commonTest/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainerTest.kt index 2406bdf8cf..342636c4c4 100644 --- a/redwood-layout-uiview/src/commonTest/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainerTest.kt +++ b/redwood-layout-uiview/src/commonTest/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainerTest.kt @@ -20,7 +20,6 @@ import app.cash.redwood.layout.AbstractFlexContainerTest import app.cash.redwood.layout.TestFlexContainer import app.cash.redwood.layout.api.Constraint import app.cash.redwood.layout.api.CrossAxisAlignment -import app.cash.redwood.layout.widget.FlexContainer import app.cash.redwood.layout.widget.Spacer import app.cash.redwood.snapshot.testing.UIViewSnapshotCallback import app.cash.redwood.snapshot.testing.UIViewSnapshotter @@ -82,7 +81,7 @@ class UIViewFlexContainerTest( private val delegate: UIViewFlexContainer, ) : TestFlexContainer, ResizableWidget, - FlexContainer by delegate, + YogaFlexContainer by delegate, ChangeListener by delegate { private var childCount = 0 diff --git a/redwood-layout-widget/api/redwood-layout-widget.api b/redwood-layout-widget/api/redwood-layout-widget.api index 4d3193dc81..bda37ffeb0 100644 --- a/redwood-layout-widget/api/redwood-layout-widget.api +++ b/redwood-layout-widget/api/redwood-layout-widget.api @@ -18,15 +18,6 @@ public abstract interface class app/cash/redwood/layout/widget/Column : app/cash public abstract fun width-DyLkt4w (I)V } -public abstract interface class app/cash/redwood/layout/widget/FlexContainer : app/cash/redwood/layout/widget/Column, app/cash/redwood/layout/widget/Row { - public abstract fun crossAxisAlignment-njEs0f8 (I)V - public fun horizontalAlignment-6exqka8 (I)V - public fun horizontalAlignment-njEs0f8 (I)V - public abstract fun mainAxisAlignment-6exqka8 (I)V - public fun verticalAlignment-6exqka8 (I)V - public fun verticalAlignment-njEs0f8 (I)V -} - public abstract interface class app/cash/redwood/layout/widget/RedwoodLayoutWidgetFactory { public abstract fun Box ()Lapp/cash/redwood/layout/widget/Box; public abstract fun Column ()Lapp/cash/redwood/layout/widget/Column; diff --git a/redwood-layout-widget/api/redwood-layout-widget.klib.api b/redwood-layout-widget/api/redwood-layout-widget.klib.api index 2cc99c2ac5..fd18a4d62d 100644 --- a/redwood-layout-widget/api/redwood-layout-widget.klib.api +++ b/redwood-layout-widget/api/redwood-layout-widget.klib.api @@ -30,15 +30,6 @@ abstract interface <#A: kotlin/Any> app.cash.redwood.layout.widget/Column : app. abstract fun width(app.cash.redwood.layout.api/Constraint) // app.cash.redwood.layout.widget/Column.width|width(app.cash.redwood.layout.api.Constraint){}[0] } -abstract interface <#A: kotlin/Any> app.cash.redwood.layout.widget/FlexContainer : app.cash.redwood.layout.widget/Column<#A>, app.cash.redwood.layout.widget/Row<#A> { // app.cash.redwood.layout.widget/FlexContainer|null[0] - abstract fun crossAxisAlignment(app.cash.redwood.layout.api/CrossAxisAlignment) // app.cash.redwood.layout.widget/FlexContainer.crossAxisAlignment|crossAxisAlignment(app.cash.redwood.layout.api.CrossAxisAlignment){}[0] - abstract fun mainAxisAlignment(app.cash.redwood.layout.api/MainAxisAlignment) // app.cash.redwood.layout.widget/FlexContainer.mainAxisAlignment|mainAxisAlignment(app.cash.redwood.layout.api.MainAxisAlignment){}[0] - open fun horizontalAlignment(app.cash.redwood.layout.api/CrossAxisAlignment) // app.cash.redwood.layout.widget/FlexContainer.horizontalAlignment|horizontalAlignment(app.cash.redwood.layout.api.CrossAxisAlignment){}[0] - open fun horizontalAlignment(app.cash.redwood.layout.api/MainAxisAlignment) // app.cash.redwood.layout.widget/FlexContainer.horizontalAlignment|horizontalAlignment(app.cash.redwood.layout.api.MainAxisAlignment){}[0] - open fun verticalAlignment(app.cash.redwood.layout.api/CrossAxisAlignment) // app.cash.redwood.layout.widget/FlexContainer.verticalAlignment|verticalAlignment(app.cash.redwood.layout.api.CrossAxisAlignment){}[0] - open fun verticalAlignment(app.cash.redwood.layout.api/MainAxisAlignment) // app.cash.redwood.layout.widget/FlexContainer.verticalAlignment|verticalAlignment(app.cash.redwood.layout.api.MainAxisAlignment){}[0] -} - abstract interface <#A: kotlin/Any> app.cash.redwood.layout.widget/RedwoodLayoutWidgetFactory { // app.cash.redwood.layout.widget/RedwoodLayoutWidgetFactory|null[0] abstract fun Box(): app.cash.redwood.layout.widget/Box<#A> // app.cash.redwood.layout.widget/RedwoodLayoutWidgetFactory.Box|Box(){}[0] abstract fun Column(): app.cash.redwood.layout.widget/Column<#A> // app.cash.redwood.layout.widget/RedwoodLayoutWidgetFactory.Column|Column(){}[0] diff --git a/redwood-layout-widget/src/commonMain/kotlin/app/cash/redwood/layout/widget/FlexContainer.kt b/redwood-layout-widget/src/commonMain/kotlin/app/cash/redwood/layout/widget/FlexContainer.kt deleted file mode 100644 index ff6d34ea30..0000000000 --- a/redwood-layout-widget/src/commonMain/kotlin/app/cash/redwood/layout/widget/FlexContainer.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2023 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package app.cash.redwood.layout.widget - -import app.cash.redwood.layout.api.CrossAxisAlignment -import app.cash.redwood.layout.api.MainAxisAlignment - -public interface FlexContainer : - Row, - Column { - override fun horizontalAlignment(horizontalAlignment: MainAxisAlignment) { - mainAxisAlignment(horizontalAlignment) - } - - override fun horizontalAlignment(horizontalAlignment: CrossAxisAlignment) { - crossAxisAlignment(horizontalAlignment) - } - - override fun verticalAlignment(verticalAlignment: MainAxisAlignment) { - mainAxisAlignment(verticalAlignment) - } - - override fun verticalAlignment(verticalAlignment: CrossAxisAlignment) { - crossAxisAlignment(verticalAlignment) - } - - public fun crossAxisAlignment(crossAxisAlignment: CrossAxisAlignment) - - public fun mainAxisAlignment(mainAxisAlignment: MainAxisAlignment) -}