From 10a016a2f78a978def6264db689ff08530ddaddf Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Sat, 30 Mar 2024 13:49:13 -0400 Subject: [PATCH] Use background color unscoped modifier in box test (#1895) --- .../cash/redwood/layout/view/ViewSpacer.kt | 31 +++- .../host/EmptyExampleSchemaWidgetFactory.kt | 2 - .../views/AndroidTestSchemaWidgetFactory.kt | 4 +- .../testing/android/views/TestAppActivity.kt | 5 +- .../testing/android/views/ViewRectangle.kt | 47 ----- .../redwood/testing/browser/widgetFactory.kt | 2 - .../TestApp.xcodeproj/project.pbxproj | 4 - .../TestApp/IosTestSchemaWidgetFactory.swift | 4 - .../redwood/testing/treehouse/serializers.kt} | 25 +-- .../redwood/testing/treehouse/presentersJs.kt | 2 +- .../redwood/testing/presenter/BoxSandbox.kt | 161 ++++++------------ .../testing/presenter/UnscopedModifiers.kt | 5 +- .../com/example/redwood/testing/schema.kt | 13 +- 13 files changed, 93 insertions(+), 212 deletions(-) delete mode 100644 test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/ViewRectangle.kt rename test-app/{ios-uikit/TestApp/RectangleBinding.swift => presenter-treehouse/src/commonMain/kotlin/com/example/redwood/testing/treehouse/serializers.kt} (55%) 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 fabc71ee91..252a1974b8 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 @@ -17,33 +17,48 @@ package app.cash.redwood.layout.view import android.content.Context import android.view.View -import android.widget.Space +import android.view.View.MeasureSpec.AT_MOST +import android.view.View.MeasureSpec.EXACTLY import app.cash.redwood.Modifier import app.cash.redwood.layout.widget.Spacer import app.cash.redwood.ui.Density import app.cash.redwood.ui.Dp +import kotlin.math.min internal class ViewSpacer( context: Context, -) : Spacer { +) : View(context), Spacer { private val density = Density(context.resources) - override val value = Space(context) + override val value get() = this override var modifier: Modifier = Modifier override fun width(width: Dp) { value.minimumWidth = with(density) { width.toPxInt() } - invalidate() + value.requestLayout() } override fun height(height: Dp) { value.minimumHeight = with(density) { height.toPxInt() } - invalidate() + value.requestLayout() } - private fun invalidate() { - value.invalidate() - value.requestLayout() + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + setMeasuredDimension( + getDefaultSizeSpace(suggestedMinimumWidth, widthMeasureSpec), + getDefaultSizeSpace(suggestedMinimumHeight, heightMeasureSpec), + ) + } + + /** Replicates the behavior of [android.widget.Space]. */ + private fun getDefaultSizeSpace(size: Int, measureSpec: Int): Int { + val specMode = MeasureSpec.getMode(measureSpec) + val specSize = MeasureSpec.getSize(measureSpec) + return when (specMode) { + AT_MOST -> min(size, specSize) + EXACTLY -> specSize + else -> size + } } } diff --git a/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/EmptyExampleSchemaWidgetFactory.kt b/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/EmptyExampleSchemaWidgetFactory.kt index 0790aaeea0..b48728966f 100644 --- a/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/EmptyExampleSchemaWidgetFactory.kt +++ b/redwood-protocol-host/src/commonTest/kotlin/app/cash/redwood/protocol/host/EmptyExampleSchemaWidgetFactory.kt @@ -20,7 +20,6 @@ import com.example.redwood.testing.modifier.BackgroundColor import com.example.redwood.testing.modifier.Reuse import com.example.redwood.testing.widget.Button import com.example.redwood.testing.widget.Button2 -import com.example.redwood.testing.widget.Rectangle import com.example.redwood.testing.widget.ScopedTestRow import com.example.redwood.testing.widget.Split import com.example.redwood.testing.widget.TestRow @@ -41,7 +40,6 @@ open class EmptyTestSchemaWidgetFactory : TestSchemaWidgetFactory { } override fun Button2(): Button2 = TODO() override fun TextInput(): TextInput = TODO() - override fun Rectangle(): Rectangle = TODO() override fun BackgroundColor(value: Unit, modifier: BackgroundColor) { } override fun Split(): Split = TODO() diff --git a/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/AndroidTestSchemaWidgetFactory.kt b/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/AndroidTestSchemaWidgetFactory.kt index 00aafeb264..778e1ff40e 100644 --- a/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/AndroidTestSchemaWidgetFactory.kt +++ b/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/AndroidTestSchemaWidgetFactory.kt @@ -22,7 +22,6 @@ import android.widget.TextView import com.example.redwood.testing.modifier.BackgroundColor import com.example.redwood.testing.modifier.Reuse import com.example.redwood.testing.widget.Button -import com.example.redwood.testing.widget.Rectangle import com.example.redwood.testing.widget.Split import com.example.redwood.testing.widget.TestSchemaWidgetFactory import com.example.redwood.testing.widget.Text @@ -36,9 +35,8 @@ class AndroidTestSchemaWidgetFactory( override fun Button(): Button = ViewButton(ButtonWidget(context)) override fun Button2() = TODO() override fun TextInput() = TODO() - override fun Rectangle(): Rectangle = ViewRectangle(context) override fun BackgroundColor(value: View, modifier: BackgroundColor) { - value.setBackgroundColor(modifier.color) + value.setBackgroundColor(modifier.color.toInt()) } override fun Split(): Split = TODO() override fun Reuse(value: View, modifier: Reuse) { diff --git a/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/TestAppActivity.kt b/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/TestAppActivity.kt index 17bc9081fc..aa2e7298ce 100644 --- a/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/TestAppActivity.kt +++ b/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/TestAppActivity.kt @@ -38,6 +38,7 @@ import app.cash.zipline.loader.withDevelopmentServerPush import com.example.redwood.testing.launcher.TestAppSpec import com.example.redwood.testing.protocol.host.TestSchemaProtocolFactory import com.example.redwood.testing.treehouse.TestAppPresenter +import com.example.redwood.testing.treehouse.testAppSerializersModule import com.example.redwood.testing.widget.TestSchemaWidgetSystem import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar.LENGTH_INDEFINITE @@ -128,7 +129,9 @@ class TestAppActivity : ComponentActivity() { embeddedDir = "/".toPath(), embeddedFileSystem = applicationContext.assets.asFileSystem(), stateStore = FileStateStore( - json = Json, + json = Json { + serializersModule = testAppSerializersModule + }, fileSystem = FileSystem.SYSTEM, directory = applicationContext.getDir("TreehouseState", MODE_PRIVATE).toOkioPath(), ), diff --git a/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/ViewRectangle.kt b/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/ViewRectangle.kt deleted file mode 100644 index 276c9c7ef2..0000000000 --- a/test-app/android-views/src/main/kotlin/com/example/redwood/testing/android/views/ViewRectangle.kt +++ /dev/null @@ -1,47 +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 com.example.redwood.testing.android.views - -import android.content.Context -import android.graphics.drawable.GradientDrawable -import android.view.View -import app.cash.redwood.Modifier -import app.cash.redwood.ui.Density -import app.cash.redwood.ui.Dp -import com.example.redwood.testing.widget.Rectangle - -internal class ViewRectangle( - context: Context, -) : Rectangle { - - private val density = Density(context.resources) - - val background = GradientDrawable() - - override val value = View(context) - - override var modifier: Modifier = Modifier - init { - value.background = background - } - override fun backgroundColor(backgroundColor: UInt) { - background.setColor(backgroundColor.toInt()) - } - - override fun cornerRadius(cornerRadius: Float) { - background.cornerRadius = with(density) { Dp(cornerRadius.toDouble()).toPx() }.toFloat() - } -} diff --git a/test-app/browser/src/commonMain/kotlin/com/example/redwood/testing/browser/widgetFactory.kt b/test-app/browser/src/commonMain/kotlin/com/example/redwood/testing/browser/widgetFactory.kt index 24c01d1daf..8b755dcc86 100644 --- a/test-app/browser/src/commonMain/kotlin/com/example/redwood/testing/browser/widgetFactory.kt +++ b/test-app/browser/src/commonMain/kotlin/com/example/redwood/testing/browser/widgetFactory.kt @@ -40,8 +40,6 @@ class HtmlWidgetFactory( override fun TextInput() = TODO() - override fun Rectangle() = TODO() - override fun Button2() = TODO() override fun ScopedTestRow() = throw UnsupportedOperationException() diff --git a/test-app/ios-uikit/TestApp.xcodeproj/project.pbxproj b/test-app/ios-uikit/TestApp.xcodeproj/project.pbxproj index 67aeaedfc7..47135d3742 100644 --- a/test-app/ios-uikit/TestApp.xcodeproj/project.pbxproj +++ b/test-app/ios-uikit/TestApp.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 635661DA21F12B7E00DD7240 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 635661D821F12B7E00DD7240 /* Main.storyboard */; }; 635661DC21F12B8000DD7240 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 635661DB21F12B8000DD7240 /* Assets.xcassets */; }; 635661DF21F12B8000DD7240 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 635661DD21F12B8000DD7240 /* LaunchScreen.storyboard */; }; - 96C741A32ACCAB13007C41FE /* RectangleBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C741A22ACCAB13007C41FE /* RectangleBinding.swift */; }; CB85C0B725AFE61A007A2CC7 /* TestAppViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB85C0B625AFE61A007A2CC7 /* TestAppViewController.swift */; }; CB9E3E822AB379C4007A87CD /* ButtonBinding.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB9E3E812AB379C4007A87CD /* ButtonBinding.swift */; }; CB9F76562810A8A8008CF457 /* IosHostApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB9F76552810A8A8008CF457 /* IosHostApi.swift */; }; @@ -29,7 +28,6 @@ 635661DE21F12B8000DD7240 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 635661E021F12B8000DD7240 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 63E90CF521FEBBB700449E04 /* main.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = main.framework; path = "../ios-shared/build/xcode-frameworks/main.framework"; sourceTree = ""; }; - 96C741A22ACCAB13007C41FE /* RectangleBinding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RectangleBinding.swift; sourceTree = ""; }; CB85C0B625AFE61A007A2CC7 /* TestAppViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestAppViewController.swift; sourceTree = ""; }; CB9E3E812AB379C4007A87CD /* ButtonBinding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonBinding.swift; sourceTree = ""; }; CB9F76552810A8A8008CF457 /* IosHostApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosHostApi.swift; sourceTree = ""; }; @@ -76,7 +74,6 @@ 10AA3D4B28C03D32006F125E /* IosTestSchemaWidgetFactory.swift */, 10AA3D4D28C0EA40006F125E /* TextBinding.swift */, CB9E3E812AB379C4007A87CD /* ButtonBinding.swift */, - 96C741A22ACCAB13007C41FE /* RectangleBinding.swift */, ); path = TestApp; sourceTree = ""; @@ -176,7 +173,6 @@ files = ( 10AA3D4C28C03D32006F125E /* IosTestSchemaWidgetFactory.swift in Sources */, CB9E3E822AB379C4007A87CD /* ButtonBinding.swift in Sources */, - 96C741A32ACCAB13007C41FE /* RectangleBinding.swift in Sources */, CB85C0B725AFE61A007A2CC7 /* TestAppViewController.swift in Sources */, 10AA3D4E28C0EA40006F125E /* TextBinding.swift in Sources */, 635661D521F12B7E00DD7240 /* AppDelegate.swift in Sources */, diff --git a/test-app/ios-uikit/TestApp/IosTestSchemaWidgetFactory.swift b/test-app/ios-uikit/TestApp/IosTestSchemaWidgetFactory.swift index ce1afceeb4..c19b114cf1 100644 --- a/test-app/ios-uikit/TestApp/IosTestSchemaWidgetFactory.swift +++ b/test-app/ios-uikit/TestApp/IosTestSchemaWidgetFactory.swift @@ -36,10 +36,6 @@ class IosTestSchemaWidgetFactory: TestSchemaWidgetFactory { fatalError() } - func Rectangle() -> Rectangle { - return RectangleBinding() - } - func ScopedTestRow() -> ScopedTestRow { fatalError() } diff --git a/test-app/ios-uikit/TestApp/RectangleBinding.swift b/test-app/presenter-treehouse/src/commonMain/kotlin/com/example/redwood/testing/treehouse/serializers.kt similarity index 55% rename from test-app/ios-uikit/TestApp/RectangleBinding.swift rename to test-app/presenter-treehouse/src/commonMain/kotlin/com/example/redwood/testing/treehouse/serializers.kt index ef087334d6..23d9e64c6d 100644 --- a/test-app/ios-uikit/TestApp/RectangleBinding.swift +++ b/test-app/presenter-treehouse/src/commonMain/kotlin/com/example/redwood/testing/treehouse/serializers.kt @@ -13,26 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package com.example.redwood.testing.treehouse -import Foundation -import TestAppKt -import UIKit +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.modules.SerializersModule -class RectangleBinding: Rectangle { - - private let root: UIView = { - let view = UIView() - return view - }() - - var modifier: Modifier = ExposedKt.modifier() - var value: Any { root } - - func backgroundColor(backgroundColor: UInt32) { - root.backgroundColor = UIColor(argb: UInt(backgroundColor)) - } - - func cornerRadius(cornerRadius: Float) { - root.layer.cornerRadius = CGFloat(cornerRadius) - } +val testAppSerializersModule = SerializersModule { + contextual(UInt::class, UInt.serializer()) } diff --git a/test-app/presenter-treehouse/src/jsMain/kotlin/com/example/redwood/testing/treehouse/presentersJs.kt b/test-app/presenter-treehouse/src/jsMain/kotlin/com/example/redwood/testing/treehouse/presentersJs.kt index d92893d07e..363158387e 100644 --- a/test-app/presenter-treehouse/src/jsMain/kotlin/com/example/redwood/testing/treehouse/presentersJs.kt +++ b/test-app/presenter-treehouse/src/jsMain/kotlin/com/example/redwood/testing/treehouse/presentersJs.kt @@ -17,7 +17,7 @@ package com.example.redwood.testing.treehouse import app.cash.zipline.Zipline -private val zipline by lazy { Zipline.get() } +private val zipline by lazy { Zipline.get(testAppSerializersModule) } @OptIn(ExperimentalJsExport::class) @JsExport diff --git a/test-app/presenter/src/commonMain/kotlin/com/example/redwood/testing/presenter/BoxSandbox.kt b/test-app/presenter/src/commonMain/kotlin/com/example/redwood/testing/presenter/BoxSandbox.kt index 70ce31fc50..55f3d694c2 100644 --- a/test-app/presenter/src/commonMain/kotlin/com/example/redwood/testing/presenter/BoxSandbox.kt +++ b/test-app/presenter/src/commonMain/kotlin/com/example/redwood/testing/presenter/BoxSandbox.kt @@ -26,7 +26,6 @@ import app.cash.redwood.layout.api.CrossAxisAlignment.Companion.End import app.cash.redwood.layout.api.CrossAxisAlignment.Companion.Start import app.cash.redwood.layout.api.CrossAxisAlignment.Companion.Stretch import app.cash.redwood.layout.api.MainAxisAlignment -import app.cash.redwood.layout.api.MainAxisAlignment.Companion.SpaceBetween import app.cash.redwood.layout.api.Overflow import app.cash.redwood.layout.compose.Box import app.cash.redwood.layout.compose.Column @@ -35,18 +34,15 @@ import app.cash.redwood.layout.compose.Row import app.cash.redwood.layout.compose.Spacer import app.cash.redwood.ui.Margin import app.cash.redwood.ui.dp -import com.example.redwood.testing.compose.Rectangle import com.example.redwood.testing.compose.Text +import com.example.redwood.testing.compose.backgroundColor private val accentColor = 0xFFDDDDDDu -private val rowColor = 0xFFDDDDDDu private val boxColor = 0xFFFFFF66u private val backColor = 0x88FF0000u private val middleColor = 0x8800FF00u private val frontColor = 0x880000FFu -private val rowHeight = 80.dp - @Composable fun BoxSandbox(modifier: Modifier = Modifier) { Column( @@ -54,7 +50,6 @@ fun BoxSandbox(modifier: Modifier = Modifier) { height = Fill, overflow = Overflow.Scroll, horizontalAlignment = Stretch, - verticalAlignment = MainAxisAlignment.Start, modifier = modifier, ) { val crossAxisAlignments = listOf( @@ -90,7 +85,6 @@ fun BoxSandbox(modifier: Modifier = Modifier) { height = heightConstraint, horizontalAlignment = horizontalAlignment, verticalAlignment = verticalAlignment, - modifier = Modifier.height(rowHeight), ) } } @@ -103,60 +97,25 @@ fun BoxSandbox(modifier: Modifier = Modifier) { private fun ColumnScope.Legend() { Text( "Legend", - modifier = Modifier.horizontalAlignment(Center).height(40.dp), + modifier = Modifier.horizontalAlignment(Center).margin(Margin(bottom = 20.dp)), ) - Box( - width = Fill, - height = Wrap, - horizontalAlignment = Stretch, - verticalAlignment = Start, - modifier = Modifier.height(80.dp).margin(Margin(horizontal = 20.dp)), - ) { - Rectangle( - backgroundColor = accentColor, - cornerRadius = 12f, - modifier = Modifier.horizontalAlignment(Stretch).verticalAlignment(Stretch), + Column(modifier = Modifier.backgroundColor(accentColor).margin(Margin(horizontal = 20.dp))) { + Text( + "Constraints [x y] | Alignments [x y]", + modifier = Modifier.horizontalAlignment(Center).margin(Margin(vertical = 10.dp)), ) - Column( - width = Fill, - horizontalAlignment = Center, + Row( + horizontalAlignment = MainAxisAlignment.Center, + modifier = Modifier.horizontalAlignment(Stretch).margin(Margin(vertical = 10.dp)), ) { - Text( - "Constraints [x y] | Alignments [x y]", - modifier = Modifier.horizontalAlignment(Center).height(40.dp), - ) - Row( - horizontalAlignment = SpaceBetween, - verticalAlignment = Center, - ) { - Rectangle( - backgroundColor = boxColor, - cornerRadius = 4f, - modifier = Modifier.width(20.dp).height(20.dp), - ) - Text(" Box") - Spacer(width = 12.dp) - Rectangle( - backgroundColor = backColor, - cornerRadius = 4f, - modifier = Modifier.width(20.dp).height(20.dp), - ) - Text(" Back") - Spacer(width = 12.dp) - Rectangle( - backgroundColor = middleColor, - cornerRadius = 4f, - modifier = Modifier.width(20.dp).height(20.dp), - ) - Text(" Middle") - Spacer(width = 12.dp) - Rectangle( - backgroundColor = frontColor, - cornerRadius = 4f, - modifier = Modifier.width(20.dp).height(20.dp), - ) - Text(" Front") - } + Spacer(modifier = Modifier.backgroundColor(boxColor).height(20.dp).width(20.dp)) + Text("Box", modifier = Modifier.margin(Margin(start = 4.dp, end = 12.dp))) + Spacer(modifier = Modifier.backgroundColor(backColor).height(20.dp).width(20.dp)) + Text("Back", modifier = Modifier.margin(Margin(start = 4.dp, end = 12.dp))) + Spacer(modifier = Modifier.backgroundColor(middleColor).height(20.dp).width(20.dp)) + Text("Middle", modifier = Modifier.margin(Margin(start = 4.dp, end = 12.dp))) + Spacer(modifier = Modifier.backgroundColor(frontColor).height(20.dp).width(20.dp)) + Text("Front", modifier = Modifier.margin(Margin(start = 4.dp))) } } } @@ -167,63 +126,51 @@ private fun ColumnScope.BoxRow( height: Constraint, horizontalAlignment: CrossAxisAlignment, verticalAlignment: CrossAxisAlignment, - modifier: Modifier = Modifier, ) { // Divider - Rectangle(accentColor, modifier = Modifier.height(1.dp).horizontalAlignment(Stretch).margin(Margin(top = 20.dp))) + Spacer( + modifier = Modifier + .backgroundColor(accentColor) + .height(1.dp) + .horizontalAlignment(Stretch) + .margin(Margin(top = 20.dp)), + ) Text( "$width $height | $horizontalAlignment $verticalAlignment", - modifier = Modifier.horizontalAlignment(Center).height(40.dp), + modifier = Modifier.horizontalAlignment(Center).margin(Margin(bottom = 8.dp)), ) - Column( - width = Fill, - height = Fill, - horizontalAlignment = Start, - margin = Margin(horizontal = 20.dp, vertical = 0.dp), - modifier = modifier, + Row( + margin = Margin(horizontal = 20.dp), + modifier = Modifier.height(80.dp), ) { Box( - width = Fill, - height = Fill, - horizontalAlignment = Stretch, - verticalAlignment = Stretch, + width = width, + height = height, + horizontalAlignment = horizontalAlignment, + verticalAlignment = verticalAlignment, + modifier = Modifier.backgroundColor(boxColor), ) { - Rectangle(backgroundColor = rowColor) - Row( - width = Fill, - height = Fill, - ) { - // This is the box we're measuring. - Box( - width = width, - height = height, - horizontalAlignment = horizontalAlignment, - verticalAlignment = verticalAlignment, - // TODO: Add backgroundColor = boxColor once the modifiers are available. - ) { - Rectangle( - backgroundColor = backColor, - cornerRadius = 12f, - modifier = Modifier.width((rowHeight.value * 1.4).dp) - .height((rowHeight.value * 0.8).dp) - .margin(Margin(5.dp)), - ) - Rectangle( - backgroundColor = middleColor, - cornerRadius = 12f, - modifier = Modifier.width((rowHeight.value * 1.2).dp) - .height((rowHeight.value * 0.6).dp) - .margin(Margin(10.dp)), - ) - Rectangle( - backgroundColor = frontColor, - cornerRadius = 12f, - modifier = Modifier.width((rowHeight.value).dp) - .height((rowHeight.value * 0.4).dp) - .margin(Margin(15.dp)), - ) - } - } + Spacer( + modifier = Modifier + .backgroundColor(backColor) + .width(100.dp) + .height(40.dp) + .margin(Margin(10.dp)), + ) + Spacer( + modifier = Modifier + .backgroundColor(middleColor) + .width(80.dp) + .height(30.dp) + .margin(Margin(10.dp)), + ) + Spacer( + modifier = Modifier + .backgroundColor(frontColor) + .width(60.dp) + .height(20.dp) + .margin(Margin(10.dp)), + ) } } } diff --git a/test-app/presenter/src/commonMain/kotlin/com/example/redwood/testing/presenter/UnscopedModifiers.kt b/test-app/presenter/src/commonMain/kotlin/com/example/redwood/testing/presenter/UnscopedModifiers.kt index c72b65d221..f323d69f97 100644 --- a/test-app/presenter/src/commonMain/kotlin/com/example/redwood/testing/presenter/UnscopedModifiers.kt +++ b/test-app/presenter/src/commonMain/kotlin/com/example/redwood/testing/presenter/UnscopedModifiers.kt @@ -27,6 +27,7 @@ import app.cash.redwood.layout.compose.Row import com.example.redwood.testing.compose.Button import com.example.redwood.testing.compose.backgroundColor import kotlin.random.Random +import kotlin.random.nextUInt import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.delay @@ -38,14 +39,14 @@ private const val COLS = 3 fun UnscopedModifiers(modifier: Modifier = Modifier) { val colors = remember { // https://issuetracker.google.com/issues/330350695 - List(ROWS * COLS) { Random.nextInt() }.toMutableStateList() + List(ROWS * COLS) { Random.nextUInt() }.toMutableStateList() } LaunchedEffect(Unit) { while (true) { delay(1.seconds) val randomIndex = Random.nextInt(colors.size) - colors[randomIndex] = Random.nextInt() + colors[randomIndex] = Random.nextUInt() } } diff --git a/test-app/schema/src/main/kotlin/com/example/redwood/testing/schema.kt b/test-app/schema/src/main/kotlin/com/example/redwood/testing/schema.kt index 97ff141161..d85f5f9554 100644 --- a/test-app/schema/src/main/kotlin/com/example/redwood/testing/schema.kt +++ b/test-app/schema/src/main/kotlin/com/example/redwood/testing/schema.kt @@ -41,7 +41,6 @@ import kotlin.time.Duration Button::class, Button2::class, TextInput::class, - Rectangle::class, BackgroundColor::class, Split::class, Reuse::class, @@ -100,15 +99,6 @@ public data class TextInput( @Property(5) val maxLength: Int, ) -@Widget(8) -public data class Rectangle( - /** expects argb format: 0xAARRGGBBu*/ - @Property(1) val backgroundColor: UInt, - - @Default("0f") - @Property(2) val cornerRadius: Float, -) - @Widget(9) public data class Split( @Children(1) val left: () -> Unit, @@ -152,7 +142,8 @@ public data object CustomTypeDataObject @Modifier(8) public data class BackgroundColor( - val color: Int, + /** Expects argb format: `0xAARRGGBBu`. */ + val color: UInt, ) @Modifier(-4_543_827) // -4_543_827 is a reserved tag.