Replace some usages of OnPositioned with onPositioned
OnPositioned and OnChildPositioned will be replaced with
onPositioned and onChildPositioned modifiers. This CL changes
some of our usages of both of them.
Test: ui-framework, ui-material, ui-test, ui-animation, ui-foundation
Change-Id: I7f6a2bc5aaf4f7e9c3a5d1c648d9611ac3897d96
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/BottomNavigationTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/BottomNavigationTest.kt
index 3685b3b..ade1767 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/BottomNavigationTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/BottomNavigationTest.kt
@@ -19,9 +19,9 @@
import androidx.ui.core.LastBaseline
import androidx.ui.core.LayoutCoordinates
import androidx.ui.core.OnChildPositioned
-import androidx.ui.core.OnPositioned
import androidx.ui.core.Text
import androidx.ui.core.globalPosition
+import androidx.ui.core.onPositioned
import androidx.ui.foundation.Box
import androidx.ui.foundation.Icon
import androidx.ui.material.icons.Icons
@@ -59,10 +59,11 @@
lateinit var parentCoords: LayoutCoordinates
val height = 56.dp
composeTestRule
- .setMaterialContentAndCollectSizes {
- OnPositioned { coords ->
+ .setMaterialContentAndCollectSizes(modifier =
+ onPositioned { coords ->
parentCoords = coords
}
+ ) {
BottomNavigationSample()
}
.assertWidthEqualsTo { parentCoords.size.width }
@@ -73,10 +74,9 @@
fun bottomNavigationItem_sizeAndPositions() {
lateinit var parentCoords: LayoutCoordinates
val itemCoords = mutableMapOf<Int, LayoutCoordinates>()
- composeTestRule.setMaterialContent {
- OnPositioned { coords ->
- parentCoords = coords
- }
+ composeTestRule.setMaterialContent(modifier = onPositioned { coords ->
+ parentCoords = coords
+ }) {
Box {
BottomNavigation {
repeat(4) { index ->
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt
index fef24de..b0cf66c 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt
@@ -20,11 +20,11 @@
import androidx.compose.state
import androidx.test.filters.MediumTest
import androidx.ui.core.LayoutCoordinates
-import androidx.ui.core.OnChildPositioned
-import androidx.ui.core.OnPositioned
import androidx.ui.core.TestTag
import androidx.ui.core.Text
import androidx.ui.core.currentTextStyle
+import androidx.ui.core.onChildPositioned
+import androidx.ui.core.onPositioned
import androidx.ui.layout.Center
import androidx.ui.layout.Column
import androidx.ui.layout.Stack
@@ -291,16 +291,9 @@
var parentCoordinates: LayoutCoordinates? = null
var childCoordinates: LayoutCoordinates? = null
composeTestRule.setMaterialContent {
- Stack {
+ Stack(onChildPositioned { parentCoordinates = it }) {
button {
- OnPositioned {
- parentCoordinates = it
- }
- OnChildPositioned(>
- childCoordinates = it
- }) {
- Text("Test button")
- }
+ Text("Test button", onPositioned { childCoordinates = 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 bef16f7..7bf194e 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
@@ -21,8 +21,8 @@
import androidx.compose.emptyContent
import androidx.test.filters.MediumTest
import androidx.ui.core.OnChildPositioned
-import androidx.ui.core.OnPositioned
import androidx.ui.core.TestTag
+import androidx.ui.core.onPositioned
import androidx.ui.foundation.Clickable
import androidx.ui.layout.Container
import androidx.ui.semantics.Semantics
@@ -64,10 +64,9 @@
var position: PxPosition? = null
composeTestRule.setMaterialContent {
ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
- Container(expanded = true) {
- OnPositioned { coords ->
- position = coords.localToGlobal(PxPosition.Origin)
- }
+ Container(onPositioned { coords ->
+ position = coords.localToGlobal(PxPosition.Origin)
+ }, expanded = true) {
}
}, bodyContent = emptyContent())
}
@@ -81,10 +80,9 @@
var position: PxPosition? = null
composeTestRule.setMaterialContent {
ModalDrawerLayout(DrawerState.Closed, {}, drawerContent = {
- Container(expanded = true) {
- OnPositioned { coords ->
- position = coords.localToGlobal(PxPosition.Origin)
- }
+ Container(onPositioned { coords ->
+ position = coords.localToGlobal(PxPosition.Origin)
+ }, expanded = true) {
}
}, bodyContent = emptyContent())
}
@@ -99,10 +97,9 @@
var size: IntPxSize? = null
composeTestRule.setMaterialContent {
ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
- Container(expanded = true) {
- OnPositioned { coords ->
- size = coords.size
- }
+ Container(onPositioned { coords ->
+ size = coords.size
+ }, expanded = true) {
}
}, bodyContent = emptyContent())
}
@@ -119,10 +116,9 @@
var position: PxPosition? = null
composeTestRule.setMaterialContent {
BottomDrawerLayout(DrawerState.Opened, {}, drawerContent = {
- Container(expanded = true) {
- OnPositioned { coords ->
- position = coords.localToGlobal(PxPosition.Origin)
- }
+ Container(onPositioned { coords ->
+ position = coords.localToGlobal(PxPosition.Origin)
+ }, expanded = true) {
}
}, bodyContent = emptyContent())
}
@@ -141,10 +137,9 @@
var position: PxPosition? = null
composeTestRule.setMaterialContent {
BottomDrawerLayout(DrawerState.Closed, {}, drawerContent = {
- Container(expanded = true) {
- OnPositioned { coords ->
- position = coords.localToGlobal(PxPosition.Origin)
- }
+ Container(onPositioned { coords ->
+ position = coords.localToGlobal(PxPosition.Origin)
+ }, expanded = true) {
}
}, bodyContent = emptyContent())
}
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/MaterialTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/MaterialTest.kt
index 07bf5f7..1f0cf5d 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/MaterialTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/MaterialTest.kt
@@ -17,6 +17,7 @@
package androidx.ui.material
import androidx.compose.Composable
+import androidx.ui.core.Modifier
import androidx.ui.layout.DpConstraints
import androidx.ui.test.BigTestConstraints
import androidx.ui.test.CollectedSizes
@@ -25,10 +26,13 @@
import androidx.ui.unit.Density
import androidx.ui.unit.PxSize
-fun ComposeTestRule.setMaterialContent(composable: @Composable() () -> Unit) {
+fun ComposeTestRule.setMaterialContent(
+ modifier: Modifier = Modifier.None,
+ composable: @Composable() () -> Unit
+) {
setContent {
MaterialTheme {
- Surface(children = composable)
+ Surface(modifier = modifier, children = composable)
}
}
}
@@ -38,21 +42,23 @@
}
}
fun ComposeTestRule.setMaterialContentAndCollectSizes(
+ modifier: Modifier = Modifier.None,
parentConstraints: DpConstraints = BigTestConstraints,
children: @Composable() () -> Unit
): CollectedSizes {
- val sizes = setMaterialContentAndGetPixelSize(parentConstraints, children)
+ val sizes = setMaterialContentAndGetPixelSize(modifier, parentConstraints, children)
return CollectedSizes(sizes, density)
}
fun ComposeTestRule.setMaterialContentAndGetPixelSize(
+ modifier: Modifier = Modifier.None,
parentConstraints: DpConstraints = BigTestConstraints,
children: @Composable() () -> Unit
): PxSize = setContentAndGetPixelSize(
parentConstraints,
- { setMaterialContent(it) }
+ { setMaterialContent(composable = it) }
) {
MaterialTheme {
- Surface(children = children)
+ Surface(modifier = modifier, children = children)
}
}
\ No newline at end of file
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/SliderTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/SliderTest.kt
index 813992e..70d9631 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/SliderTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/SliderTest.kt
@@ -107,7 +107,7 @@
composeTestRule
.setMaterialContentAndCollectSizes(
- DpConstraints(maxWidth = 100.dp, maxHeight = 100.dp)
+ parentConstraints = DpConstraints(maxWidth = 100.dp, maxHeight = 100.dp)
) { Slider(position) }
.assertHeightEqualsTo(48.dp)
.assertWidthEqualsTo(100.dp)