[go: nahoru, domu]

Fluent modifiers

Address feedback from UX research study on Compose UI Modifiers.
This change explores moving the preferred modifier construction
mechanism to fluent extension functions acting as factories, downplaying
the use of the overloaded operator plus outside of the implementation of
these extension factories. This makes modifiers more discoverable via
autocomplete and helps emphasize the significance of modifier ordering.

Relnote: Replaced Modifier plus operator with factory extension functions
Test: existing tests refactored to use new API

Change-Id: I225e444f50956d84e15ca4f1378b7f805d54e0ca
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
index 9794f24..acc6cfd 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
@@ -20,11 +20,13 @@
 import androidx.compose.Model
 import androidx.compose.emptyContent
 import androidx.test.filters.MediumTest
+import androidx.ui.core.LayoutCoordinates
+import androidx.ui.core.Modifier
 import androidx.ui.core.TestTag
 import androidx.ui.core.onPositioned
 import androidx.ui.foundation.Box
 import androidx.ui.foundation.Clickable
-import androidx.ui.layout.LayoutSize
+import androidx.ui.layout.fillMaxSize
 import androidx.ui.semantics.Semantics
 import androidx.ui.test.createComposeRule
 import androidx.ui.test.doGesture
@@ -64,7 +66,7 @@
         var position: PxPosition? = null
         composeTestRule.setMaterialContent {
             ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
-                Box(LayoutSize.Fill + onPositioned { coords ->
+                Box(Modifier.fillMaxSize().onPositioned { coords: LayoutCoordinates ->
                     position = coords.localToGlobal(PxPosition.Origin)
                 })
             }, bodyContent = emptyContent())
@@ -79,7 +81,7 @@
         var position: PxPosition? = null
         composeTestRule.setMaterialContent {
             ModalDrawerLayout(DrawerState.Closed, {}, drawerContent = {
-                Box(LayoutSize.Fill + onPositioned { coords ->
+                Box(Modifier.fillMaxSize().onPositioned { coords: LayoutCoordinates ->
                     position = coords.localToGlobal(PxPosition.Origin)
                 })
             }, bodyContent = emptyContent())
@@ -95,7 +97,9 @@
         var size: IntPxSize? = null
         composeTestRule.setMaterialContent {
             ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
-                Box(LayoutSize.Fill + onPositioned { coords -> size = coords.size })
+                Box(Modifier.fillMaxSize().onPositioned { coords: LayoutCoordinates ->
+                    size = coords.size
+                })
             }, bodyContent = emptyContent())
         }
 
@@ -111,7 +115,7 @@
         var position: PxPosition? = null
         composeTestRule.setMaterialContent {
             BottomDrawerLayout(DrawerState.Opened, {}, drawerContent = {
-                Box(LayoutSize.Fill + onPositioned { coords ->
+                Box(Modifier.fillMaxSize().onPositioned { coords: LayoutCoordinates ->
                     position = coords.localToGlobal(PxPosition.Origin)
                 })
             }, bodyContent = emptyContent())
@@ -131,7 +135,7 @@
         var position: PxPosition? = null
         composeTestRule.setMaterialContent {
             BottomDrawerLayout(DrawerState.Closed, {}, drawerContent = {
-                Box(LayoutSize.Fill + onPositioned { coords ->
+                Box(Modifier.fillMaxSize().onPositioned { coords: LayoutCoordinates ->
                     position = coords.localToGlobal(PxPosition.Origin)
                 })
             }, bodyContent = emptyContent())
@@ -147,7 +151,7 @@
         composeTestRule
             .setMaterialContentAndCollectSizes {
                 StaticDrawer {
-                    Box(LayoutSize.Fill)
+                    Box(Modifier.fillMaxSize())
                 }
             }
             .assertWidthEqualsTo(256.dp)
@@ -166,7 +170,7 @@
                     ModalDrawerLayout(drawerState.state, { drawerState.state = it },
                         drawerContent = {
                             Box(
-                                LayoutSize.Fill + onPositioned { info ->
+                                Modifier.fillMaxSize().onPositioned { info: LayoutCoordinates ->
                                     val pos = info.localToGlobal(PxPosition.Origin)
                                     if (pos.x == 0.px) {
                                         // If fully opened, mark the openedLatch if present
@@ -179,7 +183,8 @@
                             )
                         },
                         bodyContent = {
-                            Box(LayoutSize.Fill + onPositioned { contentWidth = it.size.width })
+                            Box(Modifier.fillMaxSize()
+                                .onPositioned { contentWidth = it.size.width })
                         })
                 }
             }
@@ -216,12 +221,12 @@
                     ModalDrawerLayout(drawerState.state, { drawerState.state = it },
                         drawerContent = {
                             Clickable( drawerClicks += 1 }) {
-                                Box(LayoutSize.Fill, children = emptyContent())
+                                Box(Modifier.fillMaxSize(), children = emptyContent())
                             }
                         },
                         bodyContent = {
                             Clickable( bodyClicks += 1 }) {
-                                Box(LayoutSize.Fill, children = emptyContent())
+                                Box(Modifier.fillMaxSize(), children = emptyContent())
                             }
                         })
                 }
@@ -265,7 +270,7 @@
                 Semantics(container = true) {
                     BottomDrawerLayout(drawerState.state, { drawerState.state = it },
                         drawerContent = {
-                            Box(LayoutSize.Fill + onPositioned { info ->
+                            Box(Modifier.fillMaxSize().onPositioned { info: LayoutCoordinates ->
                                 val pos = info.localToGlobal(PxPosition.Origin)
                                 if (pos.y.round() == openedHeight) {
                                     // If fully opened, mark the openedLatch if present
@@ -277,7 +282,7 @@
                             })
                         },
                         bodyContent = {
-                            Box(LayoutSize.Fill + onPositioned {
+                            Box(Modifier.fillMaxSize().onPositioned {
                                 contentHeight = it.size.height
                                 openedHeight = it.size.height * BottomDrawerOpenFraction
                             })
@@ -318,12 +323,12 @@
                     BottomDrawerLayout(drawerState.state, { drawerState.state = it },
                         drawerContent = {
                             Clickable( drawerClicks += 1 }) {
-                                Box(LayoutSize.Fill, children = emptyContent())
+                                Box(Modifier.fillMaxSize(), children = emptyContent())
                             }
                         },
                         bodyContent = {
                             Clickable( bodyClicks += 1 }) {
-                                Box(LayoutSize.Fill, children = emptyContent())
+                                Box(Modifier.fillMaxSize(), children = emptyContent())
                             }
                         })
                 }