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/AppBarTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt
index ef31c0b..6f3f62c 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
@@ -85,20 +85,20 @@
var titleLastBaselineRelativePosition: Px? = null
var actionCoords: LayoutCoordinates? = null
composeTestRule.setMaterialContent {
- Box(onChildPositioned { appBarCoords = it }) {
+ Box(Modifier.onChildPositioned { appBarCoords = it }) {
TopAppBar(
navigationIcon = {
- FakeIcon(onPositioned { navigationIconCoords = it })
+ FakeIcon(Modifier.onPositioned { navigationIconCoords = it })
},
title = {
- Text("title", onPositioned { coords ->
+ Text("title", Modifier.onPositioned { coords: LayoutCoordinates ->
titleCoords = coords
titleLastBaselineRelativePosition =
coords[LastBaseline]!!.toPx()
})
},
actions = {
- FakeIcon(onPositioned { actionCoords = it })
+ FakeIcon(Modifier.onPositioned { actionCoords = it })
}
)
}
@@ -152,13 +152,14 @@
var titleCoords: LayoutCoordinates? = null
var actionCoords: LayoutCoordinates? = null
composeTestRule.setMaterialContent {
- Box(onChildPositioned { appBarCoords = it }) {
+ Box(Modifier.onChildPositioned { appBarCoords = it }) {
TopAppBar(
title = {
- Text("title", onPositioned { titleCoords = it })
+ Text("title",
+ Modifier.onPositioned { titleCoords = it })
},
actions = {
- FakeIcon(onPositioned { actionCoords = it })
+ FakeIcon(Modifier.onPositioned { actionCoords = it })
}
)
}
@@ -213,9 +214,9 @@
var appBarCoords: LayoutCoordinates? = null
var childCoords: LayoutCoordinates? = null
composeTestRule.setMaterialContent {
- Box(onChildPositioned { appBarCoords = it }) {
+ Box(Modifier.onChildPositioned { appBarCoords = it }) {
BottomAppBar {
- FakeIcon(onPositioned { childCoords = it })
+ FakeIcon(Modifier.onPositioned { childCoords = it })
}
}
}
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 510a510..9671718 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
@@ -18,6 +18,7 @@
import androidx.test.filters.LargeTest
import androidx.ui.core.LastBaseline
import androidx.ui.core.LayoutCoordinates
+import androidx.ui.core.Modifier
import androidx.ui.core.globalPosition
import androidx.ui.core.onPositioned
import androidx.ui.foundation.Box
@@ -57,14 +58,13 @@
fun bottomNavigation_size() {
lateinit var parentCoords: LayoutCoordinates
val height = 56.dp
- composeTestRule
- .setMaterialContentAndCollectSizes(modifier =
- onPositioned { coords ->
- parentCoords = coords
- }
- ) {
- BottomNavigationSample()
+ composeTestRule.setMaterialContentAndCollectSizes(
+ modifier = Modifier.onPositioned { coords: LayoutCoordinates ->
+ parentCoords = coords
}
+ ) {
+ BottomNavigationSample()
+ }
.assertWidthEqualsTo { parentCoords.size.width }
.assertHeightEqualsTo(height)
}
@@ -73,7 +73,7 @@
fun bottomNavigationItem_sizeAndPositions() {
lateinit var parentCoords: LayoutCoordinates
val itemCoords = mutableMapOf<Int, LayoutCoordinates>()
- composeTestRule.setMaterialContent(modifier = onPositioned { coords ->
+ composeTestRule.setMaterialContent(Modifier.onPositioned { coords: LayoutCoordinates ->
parentCoords = coords
}) {
Box {
@@ -84,7 +84,9 @@
text = { Text("Item $index") },
selected = index == 0,
>
- modifier = onPositioned { coords -> itemCoords[index] = coords }
+ modifier = Modifier.onPositioned { coords: LayoutCoordinates ->
+ itemCoords[index] = coords
+ }
)
}
}
@@ -117,12 +119,18 @@
Box {
BottomNavigation {
BottomNavigationItem(
- modifier = onPositioned { coords -> itemCoords = coords },
+ modifier = Modifier.onPositioned { coords: LayoutCoordinates ->
+ itemCoords = coords
+ },
icon = {
- Icon(Icons.Filled.Favorite, onPositioned { iconCoords = it })
+ Icon(Icons.Filled.Favorite,
+ Modifier.onPositioned { iconCoords = it }
+ )
},
text = {
- Text("Item", onPositioned { textCoords = it })
+ Text("Item",
+ Modifier.onPositioned { textCoords = it }
+ )
},
selected = true,
>
@@ -164,9 +172,13 @@
Box {
BottomNavigation {
BottomNavigationItem(
- modifier = onPositioned { coords -> itemCoords = coords },
+ modifier = Modifier.onPositioned { coords: LayoutCoordinates ->
+ itemCoords = coords
+ },
icon = {
- Icon(Icons.Filled.Favorite, onPositioned { iconCoords = it })
+ Icon(Icons.Filled.Favorite,
+ Modifier.onPositioned { iconCoords = it }
+ )
},
text = {
// TODO: b/149477576 we need a boundary here so that we don't
@@ -207,9 +219,13 @@
Box {
BottomNavigation {
BottomNavigationItem(
- modifier = onPositioned { coords -> itemCoords = coords },
+ modifier = Modifier.onPositioned { coords: LayoutCoordinates ->
+ itemCoords = coords
+ },
icon = {
- Icon(Icons.Filled.Favorite, onPositioned { iconCoords = it })
+ Icon(Icons.Filled.Favorite,
+ Modifier.onPositioned { iconCoords = it }
+ )
},
text = {},
selected = false,
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 00b1508..a301e16 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,6 +20,7 @@
import androidx.compose.state
import androidx.test.filters.MediumTest
import androidx.ui.core.LayoutCoordinates
+import androidx.ui.core.Modifier
import androidx.ui.core.TestTag
import androidx.ui.core.onChildPositioned
import androidx.ui.core.onPositioned
@@ -290,9 +291,11 @@
var parentCoordinates: LayoutCoordinates? = null
var childCoordinates: LayoutCoordinates? = null
composeTestRule.setMaterialContent {
- Stack(onChildPositioned { parentCoordinates = it }) {
+ Stack(Modifier.onChildPositioned { parentCoordinates = it }) {
button {
- Text("Test button", onPositioned { childCoordinates = it })
+ Text("Test button",
+ Modifier.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 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())
}
})
}
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 d003b17..ba4eeb7 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
@@ -19,10 +19,11 @@
import android.os.Build
import androidx.test.filters.LargeTest
import androidx.test.filters.SdkSuppress
+import androidx.ui.core.Modifier
import androidx.ui.core.TestTag
import androidx.ui.foundation.Box
import androidx.ui.graphics.Color
-import androidx.ui.layout.LayoutSize
+import androidx.ui.layout.preferredSize
import androidx.ui.semantics.Semantics
import androidx.ui.test.assertPixels
import androidx.ui.test.captureToBitmap
@@ -101,7 +102,7 @@
TestTag(Tag) {
Semantics(container = true) {
Box(
- LayoutSize(
+ Modifier.preferredSize(
SurfaceSize.width.toDp(),
SurfaceSize.height.toDp()
)
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/IconButtonTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/IconButtonTest.kt
index 85613ed..c6ce9f2 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/IconButtonTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/IconButtonTest.kt
@@ -18,11 +18,10 @@
import androidx.compose.emptyContent
import androidx.test.filters.LargeTest
import androidx.ui.core.LayoutCoordinates
+import androidx.ui.core.Modifier
import androidx.ui.core.onPositioned
import androidx.ui.foundation.Box
-import androidx.ui.layout.LayoutHeight
-import androidx.ui.layout.LayoutSize
-import androidx.ui.layout.LayoutWidth
+import androidx.ui.layout.preferredSize
import androidx.ui.material.samples.IconButtonSample
import androidx.ui.material.samples.IconToggleButtonSample
import androidx.ui.test.assertIsOff
@@ -69,7 +68,7 @@
Box {
IconButton( {
Box(
- LayoutSize(diameter) + onPositioned { iconCoords = it },
+ Modifier.preferredSize(diameter).onPositioned { iconCoords = it },
children = emptyContent()
)
}
@@ -94,8 +93,7 @@
Box {
IconButton( {
Box(
- LayoutWidth(width) + LayoutHeight(height) +
- onPositioned { iconCoords = it },
+ Modifier.preferredSize(width, height).onPositioned { iconCoords = it },
children = emptyContent()
)
}
@@ -134,7 +132,7 @@
Box {
IconToggleButton(checked = false, {
Box(
- LayoutSize(diameter) + onPositioned { iconCoords = it },
+ Modifier.preferredSize(diameter).onPositioned { iconCoords = it },
children = emptyContent()
)
}
@@ -159,8 +157,7 @@
Box {
IconToggleButton(checked = false, {
Box(
- LayoutWidth(width) + LayoutHeight(height) +
- onPositioned { iconCoords = it },
+ Modifier.preferredSize(width, height).onPositioned { iconCoords = it },
children = emptyContent())
}
}
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 d40e108..892480f 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
@@ -18,6 +18,7 @@
import androidx.test.filters.SmallTest
import androidx.ui.core.FirstBaseline
+import androidx.ui.core.LayoutCoordinates
import androidx.ui.core.Modifier
import androidx.ui.core.Ref
import androidx.ui.core.onPositioned
@@ -633,7 +634,7 @@
coords: Ref<PxPosition>,
size: Ref<IntPxSize>,
baseline: Ref<Px> = Ref()
- ): Modifier = onPositioned { coordinates ->
+ ): Modifier = Modifier.onPositioned { coordinates: LayoutCoordinates ->
coords.value = coordinates.localToGlobal(PxPosition.Origin)
baseline.value = coordinates[FirstBaseline]?.toPx()?.let {
it + coords.value!!.y
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/RippleTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/RippleTest.kt
index 440f8ab..a5bc064 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/RippleTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/RippleTest.kt
@@ -23,23 +23,24 @@
import androidx.compose.mutableStateOf
import androidx.test.filters.MediumTest
import androidx.test.filters.SdkSuppress
+import androidx.ui.core.Modifier
import androidx.ui.core.TestTag
import androidx.ui.foundation.Box
import androidx.ui.foundation.Clickable
import androidx.ui.foundation.ContentGravity
-import androidx.ui.foundation.DrawBackground
+import androidx.ui.foundation.drawBackground
import androidx.ui.foundation.shape.RectangleShape
import androidx.ui.geometry.Rect
import androidx.ui.graphics.Canvas
import androidx.ui.graphics.Color
import androidx.ui.graphics.Paint
-import androidx.ui.layout.LayoutPadding
-import androidx.ui.layout.LayoutSize
import androidx.ui.layout.Row
-import androidx.ui.material.ripple.RippleThemeAmbient
+import androidx.ui.layout.padding
+import androidx.ui.layout.preferredSize
import androidx.ui.material.ripple.RippleEffect
import androidx.ui.material.ripple.RippleEffectFactory
import androidx.ui.material.ripple.RippleTheme
+import androidx.ui.material.ripple.RippleThemeAmbient
import androidx.ui.material.ripple.ripple
import androidx.ui.test.assertShape
import androidx.ui.test.captureToBitmap
@@ -80,10 +81,10 @@
DrawRectRippleCallback {
TestTag(contentTag) {
Box(
- modifier = DrawBackground(Color.Blue),
+ modifier = Modifier.drawBackground(Color.Blue),
gravity = ContentGravity.Center
) {
- Box(LayoutSize(10.dp) + ripple())
+ Box(Modifier.preferredSize(10.dp) + ripple())
}
}
}
@@ -112,15 +113,15 @@
DrawRectRippleCallback {
TestTag(contentTag) {
Box(
- modifier = DrawBackground(Color.Blue),
+ modifier = Modifier.drawBackground(Color.Blue),
gravity = ContentGravity.Center
) {
Box(
- LayoutSize(30.dp) +
- LayoutPadding(5.dp) +
- ripple() +
- // this padding should not affect the size of the ripple
- LayoutPadding(5.dp)
+ Modifier.preferredSize(30.dp)
+ .padding(5.dp)
+ .plus(ripple())
+ // this padding should not affect the size of the ripple
+ .padding(5.dp)
)
}
}
@@ -150,10 +151,10 @@
DrawRectRippleCallback {
TestTag(contentTag) {
Box(
- modifier = DrawBackground(Color.Blue),
+ modifier = Modifier.drawBackground(Color.Blue),
gravity = ContentGravity.Center
) {
- Box(LayoutSize(10.dp) + ripple(bounded = false))
+ Box(Modifier.preferredSize(10.dp) + ripple(bounded = false))
}
}
}
@@ -180,10 +181,14 @@
DrawRectRippleCallback {
TestTag(contentTag) {
Box(
- modifier = DrawBackground(Color.Blue),
+ modifier = Modifier.drawBackground(Color.Blue),
gravity = ContentGravity.Center
) {
- Box(LayoutSize(10.dp) + ripple() + DrawBackground(Color.Blue))
+ Box(
+ Modifier.preferredSize(10.dp)
+ .plus(ripple())
+ .drawBackground(Color.Blue)
+ )
}
}
}
@@ -360,7 +365,7 @@
>
modifier = ripple(bounded = false, color = color, enabled = enabled)
) {
- Box(LayoutSize(size))
+ Box(Modifier.preferredSize(size))
}
}
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt
index b38d1bb..ece5919 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt
@@ -17,6 +17,8 @@
package androidx.ui.material
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.ColoredRect
@@ -72,8 +74,12 @@
lateinit var child2: PxPosition
composeTestRule.setMaterialContent {
Scaffold {
- Text("One", onPositioned { child1 = it.positionInParent })
- Text("Two", onPositioned { child2 = it.positionInParent })
+ Text("One",
+ Modifier.onPositioned { child1 = it.positionInParent }
+ )
+ Text("Two",
+ Modifier.onPositioned { child2 = it.positionInParent }
+ )
}
}
assertThat(child1.y).isEqualTo(child2.y)
@@ -90,7 +96,7 @@
topAppBar = {
ColoredRect(
Color.Red,
- onPositioned { positioned ->
+ Modifier.onPositioned { positioned: LayoutCoordinates ->
appbarPosition = positioned.localToGlobal(PxPosition.Origin)
appbarSize = positioned.size
},
@@ -100,7 +106,7 @@
) {
ColoredRect(
Color.Blue,
- onPositioned { contentPosition = it.localToGlobal(PxPosition.Origin) },
+ Modifier.onPositioned { contentPosition = it.localToGlobal(PxPosition.Origin) },
height = 50.dp)
}
}
@@ -118,7 +124,7 @@
bottomAppBar = {
ColoredRect(
Color.Red,
- onPositioned { positioned ->
+ Modifier.onPositioned { positioned: LayoutCoordinates ->
appbarPosition = positioned.positionInParent
appbarSize = positioned.size
},
@@ -128,7 +134,7 @@
) {
ColoredRect(
Color.Blue,
- onPositioned { positioned ->
+ Modifier.onPositioned { positioned: LayoutCoordinates ->
contentPosition = positioned.positionInParent
contentSize = positioned.size
},
@@ -154,7 +160,7 @@
drawerContent = {
ColoredRect(
Color.Blue,
- onPositioned { positioned ->
+ Modifier.onPositioned { positioned: LayoutCoordinates ->
drawerChildPosition = positioned.positionInParent
},
height = 50.dp
@@ -203,7 +209,7 @@
drawerContent = {
ColoredRect(
Color.Blue,
- onPositioned { positioned ->
+ Modifier.onPositioned { positioned: LayoutCoordinates ->
drawerChildPosition = positioned.positionInParent
},
height = 50.dp
@@ -267,7 +273,7 @@
Scaffold(
floatingActionButton = {
FloatingActionButton(
- modifier = onPositioned { positioned ->
+ modifier = Modifier.onPositioned { positioned: LayoutCoordinates ->
fabSize = positioned.size
fabPosition = positioned.localToGlobal(positioned.positionInParent)
},
@@ -279,7 +285,7 @@
bottomAppBar = {
ColoredRect(
Color.Red,
- onPositioned { positioned ->
+ Modifier.onPositioned { positioned: LayoutCoordinates ->
bottomBarPosition =
positioned.localToGlobal(positioned.positionInParent)
},
@@ -303,7 +309,7 @@
Scaffold(
floatingActionButton = {
FloatingActionButton(
- modifier = onPositioned { positioned ->
+ modifier = Modifier.onPositioned { positioned: LayoutCoordinates ->
fabSize = positioned.size
fabPosition = positioned.localToGlobal(positioned.positionInParent)
},
@@ -316,7 +322,7 @@
bottomAppBar = {
ColoredRect(
Color.Red,
- onPositioned { positioned ->
+ Modifier.onPositioned { positioned: LayoutCoordinates ->
bottomBarPosition =
positioned.localToGlobal(positioned.positionInParent)
},
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt
index 71655f6..de41ad5 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt
@@ -20,6 +20,7 @@
import androidx.ui.core.FirstBaseline
import androidx.ui.core.LastBaseline
import androidx.ui.core.LayoutCoordinates
+import androidx.ui.core.Modifier
import androidx.ui.core.globalPosition
import androidx.ui.core.onPositioned
import androidx.ui.foundation.Text
@@ -82,7 +83,9 @@
) {
Snackbar(
text = {
- Text("Message", onPositioned { textCoords = it })
+ Text("Message",
+ Modifier.onPositioned { textCoords = it }
+ )
}
)
}
@@ -111,13 +114,20 @@
parentConstraints = DpConstraints(maxWidth = 300.dp)
) {
Snackbar(
- modifier = onPositioned { snackCoords = it },
+ modifier = Modifier.onPositioned { snackCoords = it },
text = {
- Text("Message", onPositioned { textCoords = it })
+ Text("Message",
+ Modifier.onPositioned { textCoords = it }
+ )
},
action = {
- TextButton( modifier = onPositioned { buttonCoords = it }) {
- Text("Undo", onPositioned { buttonTextCoords = it })
+ TextButton(
+ >
+ modifier = Modifier.onPositioned { buttonCoords = it }
+ ) {
+ Text("Undo",
+ Modifier.onPositioned { buttonTextCoords = it }
+ )
}
}
)
@@ -163,7 +173,8 @@
) {
Snackbar(
text = {
- Text(longText, onPositioned { textCoords = it }, maxLines = 2)
+ Text(longText,
+ Modifier.onPositioned { textCoords = it }, maxLines = 2)
}
)
}
@@ -192,12 +203,16 @@
parentConstraints = DpConstraints(maxWidth = 300.dp)
) {
Snackbar(
- modifier = onPositioned { snackCoords = it },
+ modifier = Modifier.onPositioned { snackCoords = it },
text = {
- Text(longText, onPositioned { textCoords = it }, maxLines = 2)
+ Text(longText,
+ Modifier.onPositioned { textCoords = it }, maxLines = 2)
},
action = {
- TextButton(modifier = onPositioned { buttonCoords = it }, {
+ TextButton(
+ modifier = Modifier.onPositioned { buttonCoords = it },
+ >
+ ) {
Text("Undo")
}
}
@@ -243,12 +258,17 @@
parentConstraints = DpConstraints(maxWidth = 300.dp)
) {
Snackbar(
- modifier = onPositioned { snackCoords = it },
+ modifier = Modifier.onPositioned { snackCoords = it },
text = {
- Text("Message", onPositioned { textCoords = it })
+ Text("Message",
+ Modifier.onPositioned { textCoords = it }
+ )
},
action = {
- TextButton( modifier = onPositioned { buttonCoords = it }) {
+ TextButton(
+ >
+ modifier = Modifier.onPositioned { buttonCoords = it }
+ ) {
Text("Undo")
}
},
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 f59fb2a..c34c259 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
@@ -20,6 +20,7 @@
import androidx.test.filters.LargeTest
import androidx.ui.core.LastBaseline
import androidx.ui.core.LayoutCoordinates
+import androidx.ui.core.Modifier
import androidx.ui.core.onChildPositioned
import androidx.ui.core.onPositioned
import androidx.ui.foundation.Box
@@ -27,7 +28,7 @@
import androidx.ui.foundation.Icon
import androidx.ui.foundation.Text
import androidx.ui.graphics.Color
-import androidx.ui.layout.LayoutWidth
+import androidx.ui.layout.preferredWidth
import androidx.ui.material.icons.Icons
import androidx.ui.material.icons.filled.Favorite
import androidx.ui.material.samples.ScrollingTextTabs
@@ -115,13 +116,13 @@
TabRow.IndicatorContainer(tabPositions, state) {
ColoredRect(
Color.Red,
- onPositioned { indicatorCoords = it },
+ Modifier.onPositioned { indicatorCoords = it },
height = indicatorHeight
)
}
}
- Box(onChildPositioned { tabRowCoords = it }) {
+ Box(Modifier.onChildPositioned { tabRowCoords = it }) {
TabRow(
items = titles,
selectedIndex = state,
@@ -181,13 +182,13 @@
Box {
TabRow(
- modifier = onPositioned { tabRowCoords = it },
+ modifier = Modifier.onPositioned { tabRowCoords = it },
items = titles,
selectedIndex = state
) { index, text ->
Tab(
text = {
- Text(text, onPositioned { coords ->
+ Text(text, Modifier.onPositioned { coords: LayoutCoordinates ->
textCoords = coords
textBaseline = coords[LastBaseline]!!.toPx()
})
@@ -226,13 +227,13 @@
Box {
TabRow(
- modifier = onPositioned { tabRowCoords = it },
+ modifier = Modifier.onPositioned { tabRowCoords = it },
items = titles,
selectedIndex = state
) { index, text ->
Tab(
text = {
- Text(text, onPositioned { coords ->
+ Text(text, Modifier.onPositioned { coords: LayoutCoordinates ->
textCoords = coords
textBaseline = coords[LastBaseline]!!.toPx()
})
@@ -272,13 +273,13 @@
Box {
TabRow(
- modifier = onPositioned { tabRowCoords = it },
+ modifier = Modifier.onPositioned { tabRowCoords = it },
items = titles,
selectedIndex = state
) { index, text ->
Tab(
text = {
- Text(text, LayoutWidth(100.dp) + onPositioned { coords ->
+ Text(text, Modifier.preferredWidth(100.dp).onPositioned { coords ->
textCoords = coords
textBaseline = coords[LastBaseline]!!.toPx()
}, maxLines = 2)
@@ -321,7 +322,7 @@
TabRow.IndicatorContainer(tabPositions, state) {
ColoredRect(
Color.Red,
- onPositioned { indicatorCoords = it },
+ Modifier.onPositioned { indicatorCoords = it },
height = indicatorHeight
)
}
@@ -329,7 +330,7 @@
Box {
TabRow(
- modifier = onPositioned { tabRowCoords = it },
+ modifier = Modifier.onPositioned { tabRowCoords = it },
items = titles,
scrollable = true,
selectedIndex = state,