[go: nahoru, domu]

Replace Container with Box for material components

Bug: 151407926
Test: should pass
Change-Id: I6a30fa9d9786f37a9e67f34bd9181e720aad565c
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt
index 9db6e36..b0b4d5c 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt
@@ -26,10 +26,10 @@
 import androidx.ui.core.globalPosition
 import androidx.ui.core.onChildPositioned
 import androidx.ui.core.onPositioned
+import androidx.ui.foundation.Box
 import androidx.ui.foundation.Icon
 import androidx.ui.graphics.Color
 import androidx.ui.graphics.painter.ColorPainter
-import androidx.ui.layout.Container
 import androidx.ui.test.assertIsDisplayed
 import androidx.ui.test.createComposeRule
 import androidx.ui.test.findByText
@@ -85,7 +85,7 @@
         var titleLastBaselineRelativePosition: Px? = null
         var actionCoords: LayoutCoordinates? = null
         composeTestRule.setMaterialContent {
-            Container(onChildPositioned { appBarCoords = it }) {
+            Box(onChildPositioned { appBarCoords = it }) {
                 TopAppBar(
                     navigationIcon = {
                         FakeIcon(onPositioned { navigationIconCoords = it })
@@ -152,7 +152,7 @@
         var titleCoords: LayoutCoordinates? = null
         var actionCoords: LayoutCoordinates? = null
         composeTestRule.setMaterialContent {
-            Container(onChildPositioned { appBarCoords = it }) {
+            Box(onChildPositioned { appBarCoords = it }) {
                 TopAppBar(
                     title = {
                         Text("title", onPositioned { titleCoords = it })
@@ -183,7 +183,7 @@
         var textStyle: TextStyle? = null
         var h6Style: TextStyle? = null
         composeTestRule.setMaterialContent {
-            Container {
+            Box {
                 TopAppBar(
                     title = {
                         Text("App Bar Title")
@@ -213,7 +213,7 @@
         var appBarCoords: LayoutCoordinates? = null
         var childCoords: LayoutCoordinates? = null
         composeTestRule.setMaterialContent {
-            Container(onChildPositioned { appBarCoords = it }) {
+            Box(onChildPositioned { appBarCoords = it }) {
                 BottomAppBar {
                     FakeIcon(onPositioned { childCoords = it })
                 }
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 beccd9e..9794f24 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
@@ -22,8 +22,9 @@
 import androidx.test.filters.MediumTest
 import androidx.ui.core.TestTag
 import androidx.ui.core.onPositioned
+import androidx.ui.foundation.Box
 import androidx.ui.foundation.Clickable
-import androidx.ui.layout.Container
+import androidx.ui.layout.LayoutSize
 import androidx.ui.semantics.Semantics
 import androidx.ui.test.createComposeRule
 import androidx.ui.test.doGesture
@@ -63,13 +64,9 @@
         var position: PxPosition? = null
         composeTestRule.setMaterialContent {
             ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
-                Container(
-                    onPositioned { coords ->
-                        position = coords.localToGlobal(PxPosition.Origin)
-                    },
-                    expanded = true
-                ) {
-                }
+                Box(LayoutSize.Fill + onPositioned { coords ->
+                    position = coords.localToGlobal(PxPosition.Origin)
+                })
             }, bodyContent = emptyContent())
         }
         composeTestRule.runOnIdleCompose {
@@ -82,13 +79,9 @@
         var position: PxPosition? = null
         composeTestRule.setMaterialContent {
             ModalDrawerLayout(DrawerState.Closed, {}, drawerContent = {
-                Container(
-                    onPositioned { coords ->
-                        position = coords.localToGlobal(PxPosition.Origin)
-                    },
-                    expanded = true
-                ) {
-                }
+                Box(LayoutSize.Fill + onPositioned { coords ->
+                    position = coords.localToGlobal(PxPosition.Origin)
+                })
             }, bodyContent = emptyContent())
         }
         val width = composeTestRule.displayMetrics.widthPixels
@@ -102,13 +95,7 @@
         var size: IntPxSize? = null
         composeTestRule.setMaterialContent {
             ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
-                Container(
-                    onPositioned { coords ->
-                        size = coords.size
-                    },
-                    expanded = true
-                ) {
-                }
+                Box(LayoutSize.Fill + onPositioned { coords -> size = coords.size })
             }, bodyContent = emptyContent())
         }
 
@@ -124,13 +111,9 @@
         var position: PxPosition? = null
         composeTestRule.setMaterialContent {
             BottomDrawerLayout(DrawerState.Opened, {}, drawerContent = {
-                Container(
-                    onPositioned { coords ->
-                        position = coords.localToGlobal(PxPosition.Origin)
-                    },
-                    expanded = true
-                ) {
-                }
+                Box(LayoutSize.Fill + onPositioned { coords ->
+                    position = coords.localToGlobal(PxPosition.Origin)
+                })
             }, bodyContent = emptyContent())
         }
 
@@ -148,13 +131,9 @@
         var position: PxPosition? = null
         composeTestRule.setMaterialContent {
             BottomDrawerLayout(DrawerState.Closed, {}, drawerContent = {
-                Container(
-                    onPositioned { coords ->
-                        position = coords.localToGlobal(PxPosition.Origin)
-                    },
-                    expanded = true
-                ) {
-                }
+                Box(LayoutSize.Fill + onPositioned { coords ->
+                    position = coords.localToGlobal(PxPosition.Origin)
+                })
             }, bodyContent = emptyContent())
         }
         val height = composeTestRule.displayMetrics.heightPixels
@@ -168,7 +147,7 @@
         composeTestRule
             .setMaterialContentAndCollectSizes {
                 StaticDrawer {
-                    Container(expanded = true, children = emptyContent())
+                    Box(LayoutSize.Fill)
                 }
             }
             .assertWidthEqualsTo(256.dp)
@@ -186,10 +165,8 @@
                 Semantics(container = true) {
                     ModalDrawerLayout(drawerState.state, { drawerState.state = it },
                         drawerContent = {
-                            Container(
-                                expanded = true,
-                                children = emptyContent(),
-                                modifier = onPositioned { info ->
+                            Box(
+                                LayoutSize.Fill + onPositioned { info ->
                                     val pos = info.localToGlobal(PxPosition.Origin)
                                     if (pos.x == 0.px) {
                                         // If fully opened, mark the openedLatch if present
@@ -202,11 +179,7 @@
                             )
                         },
                         bodyContent = {
-                            Container(
-                                expanded = true,
-                                children = emptyContent(),
-                                modifier = onPositioned { contentWidth = it.size.width }
-                            )
+                            Box(LayoutSize.Fill + onPositioned { contentWidth = it.size.width })
                         })
                 }
             }
@@ -243,12 +216,12 @@
                     ModalDrawerLayout(drawerState.state, { drawerState.state = it },
                         drawerContent = {
                             Clickable( drawerClicks += 1 }) {
-                                Container(expanded = true, children = emptyContent())
+                                Box(LayoutSize.Fill, children = emptyContent())
                             }
                         },
                         bodyContent = {
                             Clickable( bodyClicks += 1 }) {
-                                Container(expanded = true, children = emptyContent())
+                                Box(LayoutSize.Fill, children = emptyContent())
                             }
                         })
                 }
@@ -292,30 +265,22 @@
                 Semantics(container = true) {
                     BottomDrawerLayout(drawerState.state, { drawerState.state = it },
                         drawerContent = {
-                            Container(
-                                expanded = true,
-                                children = emptyContent(),
-                                modifier = onPositioned { info ->
-                                    val pos = info.localToGlobal(PxPosition.Origin)
-                                    if (pos.y.round() == openedHeight) {
-                                        // If fully opened, mark the openedLatch if present
-                                        openedLatch?.countDown()
-                                    } else if (pos.y.round() == contentHeight) {
-                                        // If fully closed, mark the closedLatch if present
-                                        closedLatch?.countDown()
-                                    }
+                            Box(LayoutSize.Fill + onPositioned { info ->
+                                val pos = info.localToGlobal(PxPosition.Origin)
+                                if (pos.y.round() == openedHeight) {
+                                    // If fully opened, mark the openedLatch if present
+                                    openedLatch?.countDown()
+                                } else if (pos.y.round() == contentHeight) {
+                                    // If fully closed, mark the closedLatch if present
+                                    closedLatch?.countDown()
                                 }
-                            )
+                            })
                         },
                         bodyContent = {
-                            Container(
-                                expanded = true,
-                                children = emptyContent(),
-                                modifier = onPositioned {
-                                    contentHeight = it.size.height
-                                    openedHeight = it.size.height * BottomDrawerOpenFraction
-                                }
-                            )
+                            Box(LayoutSize.Fill + onPositioned {
+                                contentHeight = it.size.height
+                                openedHeight = it.size.height * BottomDrawerOpenFraction
+                            })
                         }
                     )
                 }
@@ -353,12 +318,12 @@
                     BottomDrawerLayout(drawerState.state, { drawerState.state = it },
                         drawerContent = {
                             Clickable( drawerClicks += 1 }) {
-                                Container(expanded = true, children = emptyContent())
+                                Box(LayoutSize.Fill, children = emptyContent())
                             }
                         },
                         bodyContent = {
                             Clickable( bodyClicks += 1 }) {
-                                Container(expanded = true, children = emptyContent())
+                                Box(LayoutSize.Fill, children = emptyContent())
                             }
                         })
                 }
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/ElevationOverlayTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ElevationOverlayTest.kt
index 320b6a4..d003b17 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/ElevationOverlayTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/ElevationOverlayTest.kt
@@ -17,12 +17,12 @@
 package androidx.ui.material
 
 import android.os.Build
-import androidx.compose.emptyContent
 import androidx.test.filters.LargeTest
 import androidx.test.filters.SdkSuppress
 import androidx.ui.core.TestTag
+import androidx.ui.foundation.Box
 import androidx.ui.graphics.Color
-import androidx.ui.layout.Container
+import androidx.ui.layout.LayoutSize
 import androidx.ui.semantics.Semantics
 import androidx.ui.test.assertPixels
 import androidx.ui.test.captureToBitmap
@@ -95,15 +95,16 @@
         with(composeTestRule.density) {
             composeTestRule.setContent {
                 MaterialTheme(colorPalette) {
-                    Container {
+                    Box {
                         Surface(elevation = elevation) {
                             // Make the surface size small so we compare less pixels
                             TestTag(Tag) {
                                 Semantics(container = true) {
-                                    Container(
-                                        width = SurfaceSize.width.toDp(),
-                                        height = SurfaceSize.height.toDp(),
-                                        children = emptyContent()
+                                    Box(
+                                        LayoutSize(
+                                            SurfaceSize.width.toDp(),
+                                            SurfaceSize.height.toDp()
+                                        )
                                     )
                                 }
                             }
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt
index a6d56a7..041e62b 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt
@@ -17,15 +17,14 @@
 package androidx.ui.material
 
 import androidx.test.filters.SmallTest
-import androidx.ui.core.Alignment
 import androidx.ui.core.FirstBaseline
 import androidx.ui.core.Modifier
 import androidx.ui.core.Ref
 import androidx.ui.core.Text
 import androidx.ui.core.onPositioned
+import androidx.ui.foundation.Box
 import androidx.ui.foundation.Image
 import androidx.ui.graphics.ImageAsset
-import androidx.ui.layout.Container
 import androidx.ui.test.createComposeRule
 import androidx.ui.unit.Dp
 import androidx.ui.unit.IntPxSize
@@ -195,7 +194,7 @@
         val trailingPosition = Ref<PxPosition>()
         val trailingSize = Ref<IntPxSize>()
         composeTestRule.setMaterialContent {
-            Container(alignment = Alignment.TopStart) {
+            Box {
                 ListItem(
                     text = { Text("Primary text", saveLayout(textPosition, textSize)) },
                     trailing = {
@@ -231,7 +230,7 @@
         val iconPosition = Ref<PxPosition>()
         val iconSize = Ref<IntPxSize>()
         composeTestRule.setMaterialContent {
-            Container(alignment = Alignment.TopStart) {
+            Box {
                 ListItem(
                     text = { Text("Primary text", saveLayout(textPosition, textSize)) },
                     icon = { Image(icon24x24, saveLayout(iconPosition, iconSize)) }
@@ -270,7 +269,7 @@
         val trailingBaseline = Ref<Px>()
         val trailingSize = Ref<IntPxSize>()
         composeTestRule.setMaterialContent {
-            Container(alignment = Alignment.TopStart) {
+            Box {
                 ListItem(
                     text = {
                         Text("Primary text", saveLayout(textPosition, textSize, textBaseline))
@@ -329,7 +328,7 @@
         val iconPosition = Ref<PxPosition>()
         val iconSize = Ref<IntPxSize>()
         composeTestRule.setMaterialContent {
-            Container(alignment = Alignment.TopStart) {
+            Box {
                 ListItem(
                     text = {
                         Text("Primary text", saveLayout(textPosition, textSize, textBaseline))
@@ -392,7 +391,7 @@
         val trailingPosition = Ref<PxPosition>()
         val trailingSize = Ref<IntPxSize>()
         composeTestRule.setMaterialContent {
-            Container(alignment = Alignment.TopStart) {
+            Box {
                 ListItem(
                     text = {
                         Text("Primary text", saveLayout(textPosition, textSize, textBaseline))
@@ -465,7 +464,7 @@
         val trailingPosition = Ref<PxPosition>()
         val trailingSize = Ref<IntPxSize>()
         composeTestRule.setMaterialContent {
-            Container(alignment = Alignment.TopStart) {
+            Box {
                 ListItem(
                     text = {
                         Text("Primary text", saveLayout(textPosition, textSize, textBaseline))
@@ -544,7 +543,7 @@
         val trailingSize = Ref<IntPxSize>()
         val trailingBaseline = Ref<Px>()
         composeTestRule.setMaterialContent {
-            Container(alignment = Alignment.TopStart) {
+            Box {
                 ListItem(
                     overlineText = {
                         Text(
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/RippleEffectTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/RippleEffectTest.kt
index 5abf5ab..3ca3a92 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/RippleEffectTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/RippleEffectTest.kt
@@ -19,15 +19,15 @@
 import androidx.compose.Composable
 import androidx.compose.Model
 import androidx.compose.Providers
-import androidx.compose.emptyContent
 import androidx.test.filters.MediumTest
 import androidx.ui.core.LayoutCoordinates
 import androidx.ui.core.TestTag
+import androidx.ui.foundation.Box
 import androidx.ui.foundation.Clickable
 import androidx.ui.graphics.Canvas
 import androidx.ui.graphics.Color
-import androidx.ui.layout.Container
 import androidx.ui.layout.LayoutPadding
+import androidx.ui.layout.LayoutSize
 import androidx.ui.layout.Row
 import androidx.ui.layout.Stack
 import androidx.ui.material.ripple.RippleThemeAmbient
@@ -71,7 +71,7 @@
                 latch.countDown()
             }) {
                 Card {
-                    Container(LayoutPadding(padding)) {
+                    Box(LayoutPadding(padding)) {
                         TestTag(tag = "ripple") {
                             RippleButton()
                         }
@@ -268,7 +268,7 @@
     private fun RippleButton(size: Dp? = null, color: Color? = null, enabled: Boolean = true) {
         Ripple(bounded = false, color = color, enabled = enabled) {
             Clickable( {
-                Container(width = size, height = size, children = emptyContent())
+                Box(LayoutSize.Min(size ?: 0.dp))
             }
         }
     }
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/TabTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/TabTest.kt
index b390c03..1af0bc4 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/TabTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/TabTest.kt
@@ -18,15 +18,14 @@
 import androidx.compose.Composable
 import androidx.compose.state
 import androidx.test.filters.LargeTest
-import androidx.ui.core.Alignment
 import androidx.ui.core.LayoutCoordinates
 import androidx.ui.core.Text
 import androidx.ui.core.onChildPositioned
 import androidx.ui.core.onPositioned
+import androidx.ui.foundation.Box
 import androidx.ui.foundation.ColoredRect
 import androidx.ui.foundation.Icon
 import androidx.ui.graphics.Color
-import androidx.ui.layout.Container
 import androidx.ui.material.icons.Icons
 import androidx.ui.material.icons.filled.Favorite
 import androidx.ui.material.samples.ScrollingTextTabs
@@ -63,7 +62,7 @@
     fun textTab_height() {
         composeTestRule
             .setMaterialContentAndCollectSizes {
-                Container {
+                Box {
                     Surface {
                         Tab(text = { Text("Text") }, selected = true, >
                     }
@@ -76,7 +75,7 @@
     fun iconTab_height() {
         composeTestRule
             .setMaterialContentAndCollectSizes {
-                Container {
+                Box {
                     Surface {
                         Tab(icon = { Icon(icon) }, selected = true, >
                     }
@@ -89,7 +88,7 @@
     fun textAndIconTab_height() {
         composeTestRule
             .setMaterialContentAndCollectSizes {
-                Container {
+                Box {
                     Surface {
                         Tab(
                             text = { Text("Text and Icon") },
@@ -110,38 +109,35 @@
         var indicatorCoords: LayoutCoordinates? = null
 
         composeTestRule.setMaterialContent {
-                // TODO: Go back to delegate syntax when b/141741358 is fixed
-                val (state, setState) = state { 0 }
-                val titles = listOf("TAB 1", "TAB 2")
+            // TODO: Go back to delegate syntax when b/141741358 is fixed
+            val (state, setState) = state { 0 }
+            val titles = listOf("TAB 1", "TAB 2")
 
-                val indicatorContainer = @Composable { tabPositions: List<TabRow.TabPosition> ->
-                    TabRow.IndicatorContainer(tabPositions, state) {
-                        ColoredRect(
-                            Color.Red,
-                            onPositioned { indicatorCoords = it },
-                            height = indicatorHeight
-                        )
-                    }
-                }
-
-                Container(
-                    onChildPositioned { tabRowCoords = it },
-                    alignment = Alignment.TopCenter
-                ) {
-                    TabRow(
-                        items = titles,
-                        selectedIndex = state,
-                        indicatorContainer = indicatorContainer
-                    ) { index, text ->
-                        Tab(
-                            text = { Text(text) },
-                            selected = state == index,
-                             setState(index) }
-                        )
-                    }
+            val indicatorContainer = @Composable { tabPositions: List<TabRow.TabPosition> ->
+                TabRow.IndicatorContainer(tabPositions, state) {
+                    ColoredRect(
+                        Color.Red,
+                        onPositioned { indicatorCoords = it },
+                        height = indicatorHeight
+                    )
                 }
             }
 
+            Box(onChildPositioned { tabRowCoords = it }) {
+                TabRow(
+                    items = titles,
+                    selectedIndex = state,
+                    indicatorContainer = indicatorContainer
+                ) { index, text ->
+                    Tab(
+                        text = { Text(text) },
+                        selected = state == index,
+                         setState(index) }
+                    )
+                }
+            }
+        }
+
         val (tabRowWidth, tabRowHeight) = composeTestRule.runOnIdleComposeWithDensity {
             val tabRowWidth = tabRowCoords!!.size.width
             val tabRowHeight = tabRowCoords!!.size.height
@@ -198,7 +194,7 @@
                 }
             }
 
-            Container(onChildPositioned { tabRowCoords = it }, alignment = Alignment.TopCenter) {
+            Box(onChildPositioned { tabRowCoords = it }) {
                 TabRow(
                     items = titles,
                     scrollable = true,