diff --git a/CHANGELOG.md b/CHANGELOG.md index a68f87d777..ad6918103d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ New: - Nothing yet! Changed: -- Nothing yet! +- Drop support for non-incremental layouts in `Row` and `Column`. Fixed: - Fix a layout bug where children of fixed-with `Row` containers were assigned the wrong width. diff --git a/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt index 8bf7d0a418..1ac4a93e76 100644 --- a/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt +++ b/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt @@ -40,13 +40,6 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue abstract class AbstractFlexContainerTest { - /** - * Returns true if the FlexContainer implementation implements incremental layouts. This is - * currently opt-in, but will soon be the only supported mode. - */ - open val incremental: Boolean - get() = true - abstract val widgetFactory: TestWidgetFactory abstract fun flexContainer( @@ -683,23 +676,21 @@ abstract class AbstractFlexContainerTest { val aMeasureCountV2 = a.measureCount val bMeasureCountV2 = b.measureCount val cMeasureCountV2 = c.measureCount - if (incremental) { - // Only 'b' is measured again. - assertEquals(aMeasureCountV1, aMeasureCountV2) - assertTrue(bMeasureCountV1 <= bMeasureCountV2) - assertEquals(cMeasureCountV1, cMeasureCountV2) - } + + // Only 'b' is measured again. + assertEquals(aMeasureCountV1, aMeasureCountV2) + assertTrue(bMeasureCountV1 <= bMeasureCountV2) + assertEquals(cMeasureCountV1, cMeasureCountV2) snapshotter.snapshot("v3") val aMeasureCountV3 = a.measureCount val bMeasureCountV3 = b.measureCount val cMeasureCountV3 = c.measureCount - if (incremental) { - // Nothing is measured again. - assertEquals(aMeasureCountV2, aMeasureCountV3) - assertEquals(bMeasureCountV2, bMeasureCountV3) - assertEquals(cMeasureCountV2, cMeasureCountV3) - } + + // Nothing is measured again. + assertEquals(aMeasureCountV2, aMeasureCountV3) + assertEquals(bMeasureCountV2, bMeasureCountV3) + assertEquals(cMeasureCountV2, cMeasureCountV3) } @Test fun testRecursiveLayoutIsIncremental() { @@ -747,23 +738,21 @@ abstract class AbstractFlexContainerTest { val aMeasureCountV2 = a.measureCount val bMeasureCountV2 = b.measureCount val cMeasureCountV2 = c.measureCount - if (incremental) { - // Only 'b' is measured again. - assertEquals(aMeasureCountV1, aMeasureCountV2) - assertTrue(bMeasureCountV1 <= bMeasureCountV2) - assertEquals(cMeasureCountV1, cMeasureCountV2) - } + + // Only 'b' is measured again. + assertEquals(aMeasureCountV1, aMeasureCountV2) + assertTrue(bMeasureCountV1 <= bMeasureCountV2) + assertEquals(cMeasureCountV1, cMeasureCountV2) snapshotter.snapshot("v3") val aMeasureCountV3 = a.measureCount val bMeasureCountV3 = b.measureCount val cMeasureCountV3 = c.measureCount - if (incremental) { - // Nothing is measured again. - assertEquals(aMeasureCountV2, aMeasureCountV3) - assertEquals(bMeasureCountV2, bMeasureCountV3) - assertEquals(cMeasureCountV2, cMeasureCountV3) - } + + // Nothing is measured again. + assertEquals(aMeasureCountV2, aMeasureCountV3) + assertEquals(bMeasureCountV2, bMeasureCountV3) + assertEquals(cMeasureCountV2, cMeasureCountV3) } /** Confirm that child element size changes propagate up the view hierarchy. */ diff --git a/redwood-layout-uiview/api/redwood-layout-uiview.klib.api b/redwood-layout-uiview/api/redwood-layout-uiview.klib.api index 638aa2f3e9..0eb3f24604 100644 --- a/redwood-layout-uiview/api/redwood-layout-uiview.klib.api +++ b/redwood-layout-uiview/api/redwood-layout-uiview.klib.api @@ -8,7 +8,6 @@ // Library unique name: final class app.cash.redwood.layout.uiview/UIViewRedwoodLayoutWidgetFactory : app.cash.redwood.layout.widget/RedwoodLayoutWidgetFactory { // app.cash.redwood.layout.uiview/UIViewRedwoodLayoutWidgetFactory|null[0] constructor () // app.cash.redwood.layout.uiview/UIViewRedwoodLayoutWidgetFactory.|(){}[0] - constructor (kotlin/Boolean) // app.cash.redwood.layout.uiview/UIViewRedwoodLayoutWidgetFactory.|(kotlin.Boolean){}[0] final fun Box(): app.cash.redwood.layout.widget/Box // app.cash.redwood.layout.uiview/UIViewRedwoodLayoutWidgetFactory.Box|Box(){}[0] final fun Column(): app.cash.redwood.layout.widget/Column // app.cash.redwood.layout.uiview/UIViewRedwoodLayoutWidgetFactory.Column|Column(){}[0] diff --git a/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainer.kt b/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainer.kt index a1aff937b0..ee96a734ee 100644 --- a/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainer.kt +++ b/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewFlexContainer.kt @@ -33,7 +33,6 @@ import platform.darwin.NSInteger internal class UIViewFlexContainer( direction: FlexDirection, - private val incremental: Boolean, ) : YogaFlexContainer, ResizableWidget, ChangeListener { @@ -41,7 +40,6 @@ internal class UIViewFlexContainer( applyModifier = { node, _ -> node.applyModifier(node.context as Modifier, Density.Default) }, - incremental = incremental, ) override val rootNode: Node get() = yogaView.rootNode override val density: Density get() = Density.Default @@ -96,21 +94,16 @@ internal class UIViewFlexContainer( } internal fun invalidateSize() { - if (incremental) { - if (rootNode.markDirty()) { - // The node was newly-dirty. Propagate that up the tree. - val sizeListener = this.sizeListener - if (sizeListener != null) { - value.setNeedsLayout() - sizeListener.invalidateSize() - } else { - value.invalidateIntrinsicContentSize() // Tell the enclosing view that our size changed. - value.setNeedsLayout() // Update layout of subviews. - } + if (rootNode.markDirty()) { + // The node was newly-dirty. Propagate that up the tree. + val sizeListener = this.sizeListener + if (sizeListener != null) { + value.setNeedsLayout() + sizeListener.invalidateSize() + } else { + value.invalidateIntrinsicContentSize() // Tell the enclosing view that our size changed. + value.setNeedsLayout() // Update layout of subviews. } - } else { - value.invalidateIntrinsicContentSize() // Tell the enclosing view that our size changed. - value.setNeedsLayout() // Update layout of subviews. } } } diff --git a/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewRedwoodLayoutWidgetFactory.kt b/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewRedwoodLayoutWidgetFactory.kt index a3e5dda960..1cbb7651ff 100644 --- a/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewRedwoodLayoutWidgetFactory.kt +++ b/redwood-layout-uiview/src/commonMain/kotlin/app/cash/redwood/layout/uiview/UIViewRedwoodLayoutWidgetFactory.kt @@ -24,13 +24,9 @@ import app.cash.redwood.yoga.FlexDirection import platform.UIKit.UIView @ObjCName("UIViewRedwoodLayoutWidgetFactory", exact = true) -public class UIViewRedwoodLayoutWidgetFactory( - private val incremental: Boolean, -) : RedwoodLayoutWidgetFactory { - public constructor() : this(false) - +public class UIViewRedwoodLayoutWidgetFactory : RedwoodLayoutWidgetFactory { override fun Box(): Box = UIViewBox() - override fun Column(): Column = UIViewFlexContainer(FlexDirection.Column, incremental) - override fun Row(): Row = UIViewFlexContainer(FlexDirection.Row, incremental) + override fun Column(): Column = UIViewFlexContainer(FlexDirection.Column) + override fun Row(): Row = UIViewFlexContainer(FlexDirection.Row) override fun Spacer(): Spacer = UIViewSpacer() } 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 51a4554a28..8ba4e27659 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 @@ -27,7 +27,6 @@ import platform.UIKit.UIViewNoIntrinsicMetric internal class YogaUIView( private val applyModifier: (Node, Int) -> Unit, - private val incremental: Boolean, ) : UIScrollView(cValue { CGRectZero }), UIScrollViewDelegateProtocol { val rootNode = Node() @@ -106,10 +105,6 @@ internal class YogaUIView( applyModifier(node, index) } - if (!incremental) { - rootNode.markEverythingDirty() - } - rootNode.measureOnly(Size.UNDEFINED, Size.UNDEFINED) return CGSizeMake(rootNode.width.toDouble(), rootNode.height.toDouble()) 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 6317796700..53f51ec323 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 @@ -52,7 +52,7 @@ class UIViewFlexContainerTest( direction: FlexDirection, backgroundColor: Int, ): UIViewTestFlexContainer { - return UIViewTestFlexContainer(UIViewFlexContainer(direction, incremental)).apply { + return UIViewTestFlexContainer(UIViewFlexContainer(direction)).apply { value.backgroundColor = backgroundColor.toUIColor() // Install a default SizeListener that doesn't do anything. Otherwise the test subject diff --git a/redwood-layout-view/api/redwood-layout-view.api b/redwood-layout-view/api/redwood-layout-view.api index 3c7fdc97d0..3ffac14cdf 100644 --- a/redwood-layout-view/api/redwood-layout-view.api +++ b/redwood-layout-view/api/redwood-layout-view.api @@ -1,6 +1,5 @@ public final class app/cash/redwood/layout/view/ViewRedwoodLayoutWidgetFactory : app/cash/redwood/layout/widget/RedwoodLayoutWidgetFactory { - public fun (Landroid/content/Context;Z)V - public synthetic fun (Landroid/content/Context;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Landroid/content/Context;)V public fun Box ()Lapp/cash/redwood/layout/widget/Box; public fun Column ()Lapp/cash/redwood/layout/widget/Column; public fun Row ()Lapp/cash/redwood/layout/widget/Row; diff --git a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewFlexContainer.kt b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewFlexContainer.kt index a8bcfd3c4b..6a461f155b 100644 --- a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewFlexContainer.kt +++ b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewFlexContainer.kt @@ -43,7 +43,6 @@ import app.cash.redwood.yoga.isHorizontal internal class ViewFlexContainer( private val context: Context, private val direction: FlexDirection, - incremental: Boolean = false, ) : YogaFlexContainer, ChangeListener { private val yogaLayout: YogaLayout = YogaLayout( @@ -51,7 +50,6 @@ internal class ViewFlexContainer( applyModifier = { node, index -> node.applyModifier(children.widgets[index].modifier, density) }, - incremental = incremental, ) override val rootNode: Node get() = yogaLayout.rootNode override val density = Density(context.resources) diff --git a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewRedwoodLayoutWidgetFactory.kt b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewRedwoodLayoutWidgetFactory.kt index 2425ce4e73..6f79e11866 100644 --- a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewRedwoodLayoutWidgetFactory.kt +++ b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/ViewRedwoodLayoutWidgetFactory.kt @@ -26,13 +26,12 @@ import app.cash.redwood.yoga.FlexDirection public class ViewRedwoodLayoutWidgetFactory( private val context: Context, - private val incremental: Boolean = true, ) : RedwoodLayoutWidgetFactory { override fun Box(): Box = ViewBox(context) - override fun Column(): Column = - ViewFlexContainer(context, FlexDirection.Column, incremental) + override fun Column(): Column = ViewFlexContainer(context, FlexDirection.Column) + + override fun Row(): Row = ViewFlexContainer(context, FlexDirection.Row) - override fun Row(): Row = ViewFlexContainer(context, FlexDirection.Row, incremental) override fun Spacer(): Spacer = ViewSpacer(context) } diff --git a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/YogaLayout.kt b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/YogaLayout.kt index 2505bb2c71..cb95114814 100644 --- a/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/YogaLayout.kt +++ b/redwood-layout-view/src/main/kotlin/app/cash/redwood/layout/view/YogaLayout.kt @@ -18,7 +18,6 @@ import kotlin.math.roundToInt internal class YogaLayout( context: Context, private val applyModifier: (Node, Int) -> Unit, - private val incremental: Boolean, ) : ViewGroup(context) { val rootNode = Node() @@ -92,14 +91,10 @@ internal class YogaLayout( } // Sync widget layout requests to the Yoga node tree. - if (incremental) { - for (node in rootNode.children) { - if (node.view?.isLayoutRequested == true) { - node.markDirty() - } + for (node in rootNode.children) { + if (node.view?.isLayoutRequested == true) { + node.markDirty() } - } else { - rootNode.markEverythingDirty() } rootNode.measureOnly(Size.UNDEFINED, Size.UNDEFINED) 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 199309cc98..050caa17e5 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 @@ -53,7 +53,7 @@ class ViewFlexContainerTest( direction: FlexDirection, backgroundColor: Int, ): ViewTestFlexContainer { - val delegate = ViewFlexContainer(paparazzi.context, direction, incremental).apply { + val delegate = ViewFlexContainer(paparazzi.context, direction).apply { value.setBackgroundColor(backgroundColor) } return ViewTestFlexContainer(delegate)