Adds lint check for composable lambda parameters in composable functions
Composable functions with only one composable lambda parameter should use the name `content` and place this parameter at the end, so it can be used as a trailing lambda.
Also updates existing functions that do not follow these guidelines.
Bug: b/172469237
Test: ComposableLambdaParameterDetectorTest
Test: updateApi
Test: lintDebug
Relnote: """Added lint check for composable lambda parameter naming and position, to check for consistency with Compose guidelines.
Also migrated some APIs using `children` as the name for their trailing lambda to `content`, according to the lint check and guidance."""
Change-Id: Iec48e38a2896785b521814d95c9fb624d2807315
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/AppBar.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/AppBar.kt
index bf782bc..e1c3d19 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/AppBar.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/AppBar.kt
@@ -85,7 +85,7 @@
Row(TitleIconModifier, verticalAlignment = Alignment.CenterVertically) {
Providers(
AmbientContentAlpha provides ContentAlpha.high,
- children = navigationIcon
+ content = navigationIcon
)
}
}
@@ -95,7 +95,7 @@
verticalAlignment = Alignment.CenterVertically
) {
ProvideTextStyle(value = MaterialTheme.typography.h6) {
- Providers(AmbientContentAlpha provides ContentAlpha.high, children = title)
+ Providers(AmbientContentAlpha provides ContentAlpha.high, content = title)
}
}
@@ -104,7 +104,7 @@
Modifier.fillMaxHeight(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
- children = actions
+ content = actions
)
}
}
@@ -140,7 +140,7 @@
elevation,
RectangleShape,
modifier = modifier,
- children = content
+ content = content
)
}
@@ -187,7 +187,7 @@
Row(
Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically,
- children = content
+ content = content
)
}
}
@@ -432,7 +432,7 @@
elevation: Dp,
shape: Shape,
modifier: Modifier = Modifier,
- children: @Composable RowScope.() -> Unit
+ content: @Composable RowScope.() -> Unit
) {
Surface(
color = backgroundColor,
@@ -446,7 +446,7 @@
.padding(start = AppBarHorizontalPadding, end = AppBarHorizontalPadding)
.preferredHeight(AppBarHeight),
horizontalArrangement = Arrangement.SpaceBetween,
- children = children
+ content = content
)
}
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomNavigation.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomNavigation.kt
index 064f5ce..c053b07 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomNavigation.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomNavigation.kt
@@ -99,7 +99,7 @@
Row(
Modifier.fillMaxWidth().preferredHeight(BottomNavigationHeight),
horizontalArrangement = Arrangement.SpaceBetween,
- children = content
+ content = content
)
}
}
@@ -148,7 +148,7 @@
) {
val styledLabel = @Composable {
val style = MaterialTheme.typography.caption.copy(textAlign = TextAlign.Center)
- ProvideTextStyle(style, children = label)
+ ProvideTextStyle(style, content = label)
}
// The color of the Ripple should always the selected color, as we want to show the color
// before the item is considered selected, and hence before the new contentColor is
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt
index af35117..ba1e9b6 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/BottomSheetScaffold.kt
@@ -335,7 +335,7 @@
elevation = sheetElevation,
color = sheetBackgroundColor,
contentColor = sheetContentColor,
- content = { Column(children = sheetContent) }
+ content = { Column(content = sheetContent) }
)
},
floatingActionButton = {
@@ -380,7 +380,7 @@
floatingActionButtonPosition: FabPosition
) {
Layout(
- children = {
+ content = {
body()
bottomSheet()
floatingActionButton()
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Button.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Button.kt
index 7c37fb2..cdeff5d 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Button.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Button.kt
@@ -135,7 +135,7 @@
.padding(contentPadding),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
- children = content
+ content = content
)
}
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Drawer.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Drawer.kt
index 02d4f58..f41b4ce 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Drawer.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Drawer.kt
@@ -392,7 +392,7 @@
contentColor = drawerContentColor,
elevation = drawerElevation
) {
- Column(Modifier.fillMaxSize(), children = drawerContent)
+ Column(Modifier.fillMaxSize(), content = drawerContent)
}
}
}
@@ -506,7 +506,7 @@
contentColor = drawerContentColor,
elevation = drawerElevation
) {
- Column(Modifier.fillMaxSize(), children = drawerContent)
+ Column(Modifier.fillMaxSize(), content = drawerContent)
}
}
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Emphasis.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Emphasis.kt
index e4d5097..307565a 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Emphasis.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Emphasis.kt
@@ -111,7 +111,7 @@
@Composable
fun ProvideEmphasis(emphasis: Emphasis, content: @Composable () -> Unit) {
val emphasizedColor = emphasis.applyEmphasis(AmbientContentColor.current)
- Providers(AmbientContentColor provides emphasizedColor, children = content)
+ Providers(AmbientContentColor provides emphasizedColor, content = content)
}
@Deprecated(
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/FloatingActionButton.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/FloatingActionButton.kt
index 6f21a64..0c0c332 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/FloatingActionButton.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/FloatingActionButton.kt
@@ -68,7 +68,7 @@
* @param contentColor The preferred content color for content inside this FAB
* @param elevation [FloatingActionButtonElevation] used to resolve the elevation for this FAB
* in different states. This controls the size of the shadow below the FAB.
- * @param icon the content of this FAB
+ * @param content the content of this FAB - this is typically an [Icon].
*/
@OptIn(ExperimentalMaterialApi::class)
@Composable
@@ -80,7 +80,7 @@
backgroundColor: Color = MaterialTheme.colors.secondary,
contentColor: Color = contentColorFor(backgroundColor),
elevation: FloatingActionButtonElevation = FloatingActionButtonConstants.defaultElevation(),
- icon: @Composable () -> Unit
+ content: @Composable () -> Unit
) {
// TODO(aelias): Avoid manually managing the ripple once http://b/157687898
// is fixed and we have more flexibility to move the clickable modifier
@@ -103,7 +103,7 @@
.defaultMinSizeConstraints(minWidth = FabSize, minHeight = FabSize)
.indication(interactionState, AmbientIndication.current()),
alignment = Alignment.Center
- ) { icon() }
+ ) { content() }
}
}
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/IconButton.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/IconButton.kt
index c862584..3f28ec5 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/IconButton.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/IconButton.kt
@@ -31,13 +31,13 @@
/**
* IconButton is a clickable icon, used to represent actions. An IconButton has an overall minimum
- * touch target size of 48 x 48dp, to meet accessibility guidelines. [icon] is centered
+ * touch target size of 48 x 48dp, to meet accessibility guidelines. [content] is centered
* inside the IconButton.
*
* This component is typically used inside an App Bar for the navigation icon / actions. See App
* Bar documentation for samples of this.
*
- * [icon] should typically be an [Icon], using an icon from
+ * [content] should typically be an [Icon], using an icon from
* [androidx.compose.material.icons.Icons]. If using a custom icon, note that the typical size for the
* internal icon is 24 x 24 dp.
*
@@ -51,7 +51,7 @@
* present on this IconButton. You can create and pass in your own remembered
* [InteractionState] if you want to read the [InteractionState] and customize the appearance /
* behavior of this IconButton in different [Interaction]s.
- * @param icon the content (icon) to be drawn inside the IconButton. This is typically an
+ * @param content the content (icon) to be drawn inside the IconButton. This is typically an
* [Icon].
*/
@Composable
@@ -60,7 +60,7 @@
modifier: Modifier = Modifier,
enabled: Boolean = true,
interactionState: InteractionState = remember { InteractionState() },
- icon: @Composable () -> Unit
+ content: @Composable () -> Unit
) {
Box(
modifier = modifier
@@ -72,7 +72,7 @@
)
.then(IconButtonSizeModifier),
alignment = Alignment.Center
- ) { icon() }
+ ) { content() }
}
/**
@@ -90,7 +90,7 @@
* present on this IconToggleButton. You can create and pass in your own remembered
* [InteractionState] if you want to read the [InteractionState] and customize the appearance /
* behavior of this IconToggleButton in different [Interaction]s.
- * @param icon the content (icon) to be drawn inside the IconToggleButton. This is typically an
+ * @param content the content (icon) to be drawn inside the IconToggleButton. This is typically an
* [Icon].
*/
@Composable
@@ -100,7 +100,7 @@
modifier: Modifier = Modifier,
enabled: Boolean = true,
interactionState: InteractionState = remember { InteractionState() },
- icon: @Composable () -> Unit
+ content: @Composable () -> Unit
) {
Box(
modifier = modifier.toggleable(
@@ -111,7 +111,7 @@
indication = rememberRippleIndication(bounded = false, radius = RippleRadius)
).then(IconButtonSizeModifier),
alignment = Alignment.Center
- ) { icon() }
+ ) { content() }
}
// Default radius of an unbounded ripple in an IconButton
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/MaterialTheme.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/MaterialTheme.kt
index 565e171..8dec339 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/MaterialTheme.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/MaterialTheme.kt
@@ -71,7 +71,7 @@
AmbientShapes provides shapes,
AmbientContentAlpha provides ContentAlpha.high
) {
- ProvideTextStyle(value = typography.body1, children = content)
+ ProvideTextStyle(value = typography.body1, content = content)
}
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt
index 58ac47a..879cd4d 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Menu.kt
@@ -138,7 +138,7 @@
modifier = dropdownModifier
.padding(vertical = DropdownMenuVerticalPadding)
.preferredWidth(IntrinsicSize.Max),
- children = dropdownContent
+ content = dropdownContent
)
}
}
@@ -191,7 +191,7 @@
val typography = MaterialTheme.typography
ProvideTextStyle(typography.subtitle1) {
val contentAlpha = if (enabled) ContentAlpha.high else ContentAlpha.disabled
- Providers(AmbientContentAlpha provides contentAlpha, children = content)
+ Providers(AmbientContentAlpha provides contentAlpha, content = content)
}
}
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt
index f9904cc..2c3383ca 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ModalBottomSheet.kt
@@ -236,7 +236,7 @@
color = sheetBackgroundColor,
contentColor = sheetContentColor
) {
- Column(children = sheetContent)
+ Column(content = sheetContent)
}
},
content = { constraints, sheetHeight ->
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/OutlinedTextField.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/OutlinedTextField.kt
index 0aaa68f..7921145 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/OutlinedTextField.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/OutlinedTextField.kt
@@ -353,12 +353,12 @@
onLabelMeasured: (Int) -> Unit
) {
Layout(
- children = {
+ content = {
if (leading != null) {
Box(Modifier.layoutId("leading").iconPadding(start = HorizontalIconPadding)) {
Decoration(
contentColor = leadingColor,
- children = leading
+ content = leading
)
}
}
@@ -366,7 +366,7 @@
Box(Modifier.layoutId("trailing").iconPadding(end = HorizontalIconPadding)) {
Decoration(
contentColor = trailingColor,
- children = trailing
+ content = trailing
)
}
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Scaffold.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Scaffold.kt
index 3389d2e..1cd441d 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Scaffold.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Scaffold.kt
@@ -280,7 +280,7 @@
val bottomBarPlaceables = subcompose(ScaffoldLayoutContent.BottomBar) {
Providers(
AmbientFabPlacement provides fabPlacement,
- children = bottomBar
+ content = bottomBar
)
}.fastMap { it.measure(looseConstraints) }
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Snackbar.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Snackbar.kt
index 3a59d60..41a9958 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Snackbar.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Snackbar.kt
@@ -226,9 +226,9 @@
}
@Composable
-private fun TextOnlySnackbar(text: @Composable () -> Unit) {
+private fun TextOnlySnackbar(content: @Composable () -> Unit) {
Layout(
- text,
+ content,
modifier = Modifier.padding(
start = HorizontalSpacing,
end = HorizontalSpacing,
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SnackbarHost.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SnackbarHost.kt
index 5811f6b..414f51b 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SnackbarHost.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SnackbarHost.kt
@@ -314,7 +314,7 @@
val transition: FadeInFadeOutTransition
)
-private typealias FadeInFadeOutTransition = @Composable (children: @Composable () -> Unit) -> Unit
+private typealias FadeInFadeOutTransition = @Composable (content: @Composable () -> Unit) -> Unit
@Composable
private fun animatedOpacity(
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Surface.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Surface.kt
index 1213952..9ec0865 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Surface.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Surface.kt
@@ -111,7 +111,7 @@
Providers(
AmbientContentColor provides contentColor,
AmbientAbsoluteElevation provides absoluteElevation,
- children = content
+ content = content
)
}
}
@@ -133,8 +133,8 @@
*/
// TODO("Andrey: Should be replaced with some basic layout implementation when we have it")
@Composable
-private fun SurfaceLayout(modifier: Modifier = Modifier, children: @Composable () -> Unit) {
- Layout(children, modifier) { measurables, constraints ->
+private fun SurfaceLayout(modifier: Modifier = Modifier, content: @Composable () -> Unit) {
+ Layout(content, modifier) { measurables, constraints ->
if (measurables.size > 1) {
throw IllegalStateException("Surface can have only one direct measurable child!")
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SwipeToDismiss.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SwipeToDismiss.kt
index bdcce40..e0e1e56 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SwipeToDismiss.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/SwipeToDismiss.kt
@@ -234,11 +234,11 @@
)
) {
Row(
- children = background,
+ content = background,
modifier = Modifier.matchParentSize()
)
Row(
- children = dismissContent,
+ content = dismissContent,
modifier = Modifier.offsetPx(x = state.offset)
)
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Tab.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Tab.kt
index 949a9f4..63d8945 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Tab.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Tab.kt
@@ -95,7 +95,7 @@
) {
val styledText = @Composable {
val style = MaterialTheme.typography.button.copy(textAlign = TextAlign.Center)
- ProvideTextStyle(style, children = text)
+ ProvideTextStyle(style, content = text)
}
Tab(
selected,
@@ -157,7 +157,7 @@
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
- children = content
+ content = content
)
}
}
@@ -299,7 +299,7 @@
Providers(
AmbientContentColor provides color.copy(alpha = 1f),
AmbientContentAlpha provides color.alpha,
- children = content
+ content = content
)
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Text.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Text.kt
index 3a5b772..d96a672 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Text.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/Text.kt
@@ -236,12 +236,12 @@
/**
* This function is used to set the current value of [AmbientTextStyle], merging the given style
* with the current style values for any missing attributes. Any [Text] components included in
- * this component's [children] will be styled with this style unless styled explicitly.
+ * this component's [content] will be styled with this style unless styled explicitly.
*
* @see AmbientTextStyle
*/
@Composable
-fun ProvideTextStyle(value: TextStyle, children: @Composable () -> Unit) {
+fun ProvideTextStyle(value: TextStyle, content: @Composable () -> Unit) {
val mergedStyle = AmbientTextStyle.current.merge(value)
- Providers(AmbientTextStyle provides mergedStyle, children = children)
+ Providers(AmbientTextStyle provides mergedStyle, content = content)
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextField.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextField.kt
index 20c0cc8..d6ed6d4 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextField.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextField.kt
@@ -379,12 +379,12 @@
animationProgress: Float
) {
Layout(
- children = {
+ content = {
if (leading != null) {
Box(Modifier.layoutId("leading").iconPadding(start = HorizontalIconPadding)) {
Decoration(
contentColor = leadingColor,
- children = leading
+ content = leading
)
}
}
@@ -392,7 +392,7 @@
Box(Modifier.layoutId("trailing").iconPadding(end = HorizontalIconPadding)) {
Decoration(
contentColor = trailingColor,
- children = trailing
+ content = trailing
)
}
}
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldImpl.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldImpl.kt
index 9dbb12d..2971d2a 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldImpl.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldImpl.kt
@@ -191,7 +191,7 @@
Decoration(
contentColor = animatedLabelColor,
typography = labelAnimatedStyle,
- children = label
+ content = label
)
}
} else null
@@ -204,7 +204,7 @@
contentColor = inactiveColor,
typography = MaterialTheme.typography.subtitle1,
contentAlpha = ContentAlpha.medium,
- children = placeholder
+ content = placeholder
)
}
}
@@ -266,26 +266,26 @@
}
/**
- * Set content color, typography and emphasis for [children] composable
+ * Set content color, typography and emphasis for [content] composable
*/
@Composable
internal fun Decoration(
contentColor: Color,
typography: TextStyle? = null,
contentAlpha: Float? = null,
- children: @Composable () -> Unit
+ content: @Composable () -> Unit
) {
val colorAndEmphasis = @Composable {
Providers(AmbientContentColor provides contentColor) {
if (contentAlpha != null) {
Providers(
AmbientContentAlpha provides contentAlpha,
- children = children
+ content = content
)
} else {
Providers(
AmbientContentAlpha provides contentColor.alpha,
- children = children
+ content = content
)
}
}
@@ -341,7 +341,7 @@
activeColor: Color,
labelInactiveColor: Color,
indicatorInactiveColor: Color,
- children: @Composable (
+ content: @Composable (
labelProgress: Float,
labelColor: Color,
indicatorWidth: Dp,
@@ -363,7 +363,7 @@
)
}
val state = transition(definition = definition, toState = inputState)
- children(
+ content(
state[LabelProgressProp],
state[LabelColorProp],
state[IndicatorWidthProp],