[go: nahoru, domu]

API proposal: Layout prefix for LayoutModifiers

A common report so far is that layout modifiers are difficult to
discover and sometimes remember. They lack a common autocomplete stem
that would permit easier discovery in the IDE. Additionally, as new
layout modifiers have been introduced they've created namespace
confusion at point of use, impairing readability.

This change introduces, "Layout" as a common prefix for LayoutModifier
accessors, mirroring Android's historical use of "layout_" prefixes
in XML attributes that affect layout behavior of a child within
a parent. This is phase one of a series of intended changes that will
also change the organization of some of these modifiers to allow for
closer grouping and discoverability of related modifiers, especially
around size, with a leaning to familiar Android constructs.

Also rename Spacing to LayoutPadding under the new convention,
as Spacing never really stuck. (Though it did prevent confusion with
Android's historical layout_padding.)

Test: all existing tests
Change-Id: I2fad064aab900081859efac52cf7ad663abfd30e
diff --git a/ui/ui-layout/src/androidTest/java/androidx/ui/layout/test/AspectRatioModifierTest.kt b/ui/ui-layout/src/androidTest/java/androidx/ui/layout/test/AspectRatioModifierTest.kt
index e1a5d43..ef08953 100644
--- a/ui/ui-layout/src/androidTest/java/androidx/ui/layout/test/AspectRatioModifierTest.kt
+++ b/ui/ui-layout/src/androidTest/java/androidx/ui/layout/test/AspectRatioModifierTest.kt
@@ -29,7 +29,7 @@
 import androidx.ui.core.px
 import androidx.ui.core.withDensity
 import androidx.ui.layout.Container
-import androidx.ui.layout.AspectRatio
+import androidx.ui.layout.LayoutAspectRatio
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.junit.runners.JUnit4
@@ -43,7 +43,7 @@
     @Test
     fun testAspectRatioModifier_intrinsicDimensions() = withDensity(density) {
         testIntrinsics(@Composable {
-            Container(modifier = AspectRatio(2f), width = 30.dp, height = 40.dp) { }
+            Container(modifier = LayoutAspectRatio(2f), width = 30.dp, height = 40.dp) { }
         }) { minIntrinsicWidth, minIntrinsicHeight, maxIntrinsicWidth, maxIntrinsicHeight ->
             assertEquals(40.ipx, minIntrinsicWidth(20.ipx))
             assertEquals(40.ipx, maxIntrinsicWidth(20.ipx))
@@ -60,14 +60,14 @@
     @Test(expected = IllegalArgumentException::class)
     fun testAspectRatioModifier_zeroRatio() {
         show {
-            Container(AspectRatio(0f)) { }
+            Container(LayoutAspectRatio(0f)) { }
         }
     }
 
     @Test(expected = IllegalArgumentException::class)
     fun testAspectRatioModifier_negativeRatio() {
         show {
-            Container(AspectRatio(-2f)) { }
+            Container(LayoutAspectRatio(-2f)) { }
         }
     }
 
@@ -99,7 +99,7 @@
         val position = Ref<PxPosition>()
         show {
             Layout(@Composable {
-                Container(AspectRatio(aspectRatio)) {
+                Container(LayoutAspectRatio(aspectRatio)) {
                     SaveLayoutInfo(size, position, positionedLatch)
                 }
             }) { measurables, incomingConstraints ->