mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Fix deprecation warning on androidx.compose.material3.ListItem
This commit is contained in:
committed by
Benoit Marty
parent
d2b4a85453
commit
d1cf1aa09f
+1
-1
@@ -45,7 +45,7 @@ fun AvatarListItem(
|
||||
) {
|
||||
ListItem(
|
||||
modifier = modifier,
|
||||
headlineContent = { Text(headline) },
|
||||
content = { Text(headline) },
|
||||
supportingContent = supportingText?.let { @Composable { Text(it) } },
|
||||
leadingContent = ListItemContent.Custom { _ ->
|
||||
Avatar(
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ fun CheckboxListItem(
|
||||
) {
|
||||
ListItem(
|
||||
modifier = modifier,
|
||||
headlineContent = { Text(headline) },
|
||||
content = { Text(headline) },
|
||||
supportingContent = supportingText?.let { @Composable { Text(it) } },
|
||||
leadingContent = ListItemContent.Checkbox(
|
||||
checked = checked,
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ fun MultipleSelectionListItem(
|
||||
|
||||
ListItem(
|
||||
modifier = modifier,
|
||||
headlineContent = { Text(text = headline) },
|
||||
content = { Text(text = headline) },
|
||||
supportingContent = decoratedSupportedText,
|
||||
leadingContent = leadingContent,
|
||||
trailingContent = trailingContent,
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ fun RadioButtonListItem(
|
||||
) {
|
||||
ListItem(
|
||||
modifier = modifier,
|
||||
headlineContent = { Text(headline) },
|
||||
content = { Text(headline) },
|
||||
supportingContent = supportingText?.let { @Composable { Text(it) } },
|
||||
leadingContent = ListItemContent.RadioButton(
|
||||
selected = selected,
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ fun SingleSelectionListItem(
|
||||
|
||||
ListItem(
|
||||
modifier = modifier,
|
||||
headlineContent = { Text(text = headline) },
|
||||
content = { Text(text = headline) },
|
||||
supportingContent = decoratedSupportedText,
|
||||
leadingContent = leadingContent,
|
||||
trailingContent = trailingContent,
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ fun SwitchListItem(
|
||||
) {
|
||||
ListItem(
|
||||
modifier = modifier,
|
||||
headlineContent = { Text(headline) },
|
||||
content = { Text(headline) },
|
||||
supportingContent = supportingText?.let { @Composable { Text(it) } },
|
||||
leadingContent = leadingContent,
|
||||
trailingContent = ListItemContent.Switch(
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ fun PreferenceCheckbox(
|
||||
iconResourceId = iconResourceId,
|
||||
showIconAreaIfNoIcon = showIconAreaIfNoIcon,
|
||||
),
|
||||
headlineContent = {
|
||||
content = {
|
||||
Text(
|
||||
style = ElementTheme.typography.fontBodyLgRegular,
|
||||
text = title,
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ fun <T : DropdownOption> PreferenceDropdown(
|
||||
iconResourceId = iconResourceId,
|
||||
showIconAreaIfNoIcon = showIconAreaIfNoIcon,
|
||||
),
|
||||
headlineContent = {
|
||||
content = {
|
||||
Text(
|
||||
style = ElementTheme.typography.fontBodyLgRegular,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ fun PreferenceRow(
|
||||
) {
|
||||
ListItem(
|
||||
modifier = modifier,
|
||||
headlineContent = {
|
||||
content = {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ fun PreferenceSlide(
|
||||
iconResourceId = iconResourceId,
|
||||
showIconAreaIfNoIcon = showIconAreaIfNoIcon,
|
||||
),
|
||||
headlineContent = {
|
||||
content = {
|
||||
Column {
|
||||
Text(
|
||||
style = ElementTheme.typography.fontBodyLgRegular,
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ fun PreferenceSwitch(
|
||||
iconResourceId = iconResourceId,
|
||||
showIconAreaIfNoIcon = showIconAreaIfNoIcon,
|
||||
),
|
||||
headlineContent = {
|
||||
content = {
|
||||
Text(
|
||||
style = ElementTheme.typography.fontBodyLgRegular,
|
||||
text = title,
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ fun PreferenceTextField(
|
||||
|
||||
ListItem(
|
||||
modifier = modifier,
|
||||
headlineContent = { Text(headline) },
|
||||
content = { Text(headline) },
|
||||
supportingContent = valueToDisplay?.let { @Composable { Text(it) } },
|
||||
trailingContent = trailingContent,
|
||||
style = style,
|
||||
|
||||
+31
-32
@@ -35,20 +35,19 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
|
||||
/**
|
||||
* A List Item component to be used in lists and menus with simple layouts, matching the Material 3 guidelines.
|
||||
* @param headlineContent The main content of the list item, usually a text.
|
||||
* @param modifier The modifier to be applied to the list item.
|
||||
* @param supportingContent The content to be displayed below the headline content.
|
||||
* @param leadingContent The content to be displayed before the headline content.
|
||||
* @param trailingContent The content to be displayed after the headline content.
|
||||
* @param supportingContent The content to be displayed below the content.
|
||||
* @param leadingContent The content to be displayed before the content.
|
||||
* @param trailingContent The content to be displayed after the content.
|
||||
* @param style The style to use for the list item. This may change the color and text styles of the contents. [ListItemStyle.Default] is used by default.
|
||||
* @param enabled Whether the list item is enabled. When disabled, will change the color of the headline content and the leading content to use disabled tokens.
|
||||
* @param enabled Whether the list item is enabled. When disabled, will change the color of the content and the leading content to use disabled tokens.
|
||||
* @param alwaysClickable Whether the list item should always be clickable, even when disabled.
|
||||
* @param onClick The callback to be called when the list item is clicked.
|
||||
* @param content The main content of the list item, usually a text.
|
||||
*/
|
||||
@Suppress("LongParameterList")
|
||||
@Composable
|
||||
fun ListItem(
|
||||
headlineContent: @Composable () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
supportingContent: @Composable (() -> Unit)? = null,
|
||||
leadingContent: ListItemContent? = null,
|
||||
@@ -57,19 +56,19 @@ fun ListItem(
|
||||
enabled: Boolean = true,
|
||||
alwaysClickable: Boolean = false,
|
||||
onClick: (() -> Unit)? = null,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val colors = ListItemDefaults.colors(
|
||||
containerColor = Color.Transparent,
|
||||
headlineColor = style.headlineColor(),
|
||||
headlineColor = style.contentColor(),
|
||||
leadingIconColor = style.leadingIconColor(),
|
||||
trailingIconColor = style.trailingIconColor(),
|
||||
supportingColor = style.supportingTextColor(),
|
||||
disabledHeadlineColor = ListItemDefaultColors.headlineDisabled,
|
||||
disabledHeadlineColor = ListItemDefaultColors.contentDisabled,
|
||||
disabledLeadingIconColor = ListItemDefaultColors.iconDisabled,
|
||||
disabledTrailingIconColor = ListItemDefaultColors.iconDisabled,
|
||||
)
|
||||
ListItem(
|
||||
headlineContent = headlineContent,
|
||||
modifier = modifier,
|
||||
supportingContent = supportingContent,
|
||||
leadingContent = leadingContent,
|
||||
@@ -78,25 +77,25 @@ fun ListItem(
|
||||
enabled = enabled,
|
||||
alwaysClickable = alwaysClickable,
|
||||
onClick = onClick,
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A List Item component to be used in lists and menus with simple layouts, matching the Material 3 guidelines.
|
||||
* @param headlineContent The main content of the list item, usually a text.
|
||||
* @param colors The colors to use for the list item. You can use [ListItemDefaults.colors] to create this.
|
||||
* @param modifier The modifier to be applied to the list item.
|
||||
* @param supportingContent The content to be displayed below the headline content.
|
||||
* @param leadingContent The content to be displayed before the headline content.
|
||||
* @param trailingContent The content to be displayed after the headline content.
|
||||
* @param enabled Whether the list item is enabled. When disabled, will change the color of the headline content and the leading content to use disabled tokens.
|
||||
* @param supportingContent The content to be displayed below the content.
|
||||
* @param leadingContent The content to be displayed before the content.
|
||||
* @param trailingContent The content to be displayed after the content.
|
||||
* @param enabled Whether the list item is enabled. When disabled, will change the color of the content and the leading content to use disabled tokens.
|
||||
* @param alwaysClickable Whether the list item should always be clickable, even when disabled.
|
||||
* @param onClick The callback to be called when the list item is clicked.
|
||||
* @param content The main content of the list item, usually a text.
|
||||
*/
|
||||
@Suppress("LongParameterList")
|
||||
@Composable
|
||||
fun ListItem(
|
||||
headlineContent: @Composable () -> Unit,
|
||||
colors: ListItemColors,
|
||||
modifier: Modifier = Modifier,
|
||||
supportingContent: @Composable (() -> Unit)? = null,
|
||||
@@ -105,19 +104,20 @@ fun ListItem(
|
||||
enabled: Boolean = true,
|
||||
alwaysClickable: Boolean = false,
|
||||
onClick: (() -> Unit)? = null,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
// We cannot just pass the disabled colors, they must be set manually: https://issuetracker.google.com/issues/280480132
|
||||
val headlineColor = if (enabled) colors.contentColor else colors.disabledContentColor
|
||||
val contentColor = if (enabled) colors.contentColor else colors.disabledContentColor
|
||||
val supportingColor = if (enabled) colors.supportingContentColor else colors.disabledContentColor.copy(alpha = 0.80f)
|
||||
val leadingContentColor = if (enabled) colors.leadingContentColor else colors.disabledLeadingContentColor
|
||||
val trailingContentColor = if (enabled) colors.trailingContentColor else colors.disabledTrailingContentColor
|
||||
|
||||
val decoratedHeadlineContent: @Composable () -> Unit = {
|
||||
val decoratedContent: @Composable () -> Unit = {
|
||||
CompositionLocalProvider(
|
||||
LocalTextStyle provides ElementTheme.typography.fontBodyLgRegular,
|
||||
LocalContentColor provides headlineColor,
|
||||
LocalContentColor provides contentColor,
|
||||
) {
|
||||
headlineContent()
|
||||
content()
|
||||
}
|
||||
}
|
||||
val decoratedSupportingContent: (@Composable () -> Unit)? = supportingContent?.let { content ->
|
||||
@@ -151,7 +151,6 @@ fun ListItem(
|
||||
}
|
||||
|
||||
androidx.compose.material3.ListItem(
|
||||
headlineContent = decoratedHeadlineContent,
|
||||
modifier = if (onClick != null) {
|
||||
Modifier
|
||||
.clickable(enabled = enabled || alwaysClickable, onClick = onClick)
|
||||
@@ -169,8 +168,8 @@ fun ListItem(
|
||||
leadingContent = decoratedLeadingContent,
|
||||
trailingContent = decoratedTrailingContent,
|
||||
colors = colors,
|
||||
tonalElevation = 0.dp,
|
||||
shadowElevation = 0.dp,
|
||||
elevation = ListItemDefaults.elevation(elevation = 0.dp),
|
||||
content = decoratedContent,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -223,8 +222,8 @@ sealed interface ListItemStyle {
|
||||
data object Destructive : ListItemStyle
|
||||
|
||||
@Composable
|
||||
fun headlineColor() = when (this) {
|
||||
Default, Primary -> ListItemDefaultColors.headline
|
||||
fun contentColor() = when (this) {
|
||||
Default, Primary -> ListItemDefaultColors.content
|
||||
Destructive -> ElementTheme.colors.textCriticalPrimary
|
||||
}
|
||||
|
||||
@@ -251,8 +250,8 @@ sealed interface ListItemStyle {
|
||||
}
|
||||
|
||||
object ListItemDefaultColors {
|
||||
val headline: Color @Composable get() = ElementTheme.colors.textPrimary
|
||||
val headlineDisabled: Color @Composable get() = ElementTheme.colors.textDisabled
|
||||
val content: Color @Composable get() = ElementTheme.colors.textPrimary
|
||||
val contentDisabled: Color @Composable get() = ElementTheme.colors.textDisabled
|
||||
val supportingText: Color @Composable get() = ElementTheme.materialColors.onSurfaceVariant
|
||||
val leadingIcon: Color @Composable get() = ElementTheme.colors.iconSecondary
|
||||
val trailingIcon: Color @Composable get() = ElementTheme.colors.iconPrimary
|
||||
@@ -260,11 +259,11 @@ object ListItemDefaultColors {
|
||||
|
||||
val colors: ListItemColors
|
||||
@Composable get() = ListItemDefaults.colors(
|
||||
headlineColor = headline,
|
||||
headlineColor = content,
|
||||
supportingColor = supportingText,
|
||||
leadingIconColor = leadingIcon,
|
||||
trailingIconColor = trailingIcon,
|
||||
disabledHeadlineColor = headlineDisabled,
|
||||
disabledHeadlineColor = contentDisabled,
|
||||
disabledLeadingIconColor = iconDisabled,
|
||||
disabledTrailingIconColor = iconDisabled,
|
||||
)
|
||||
@@ -523,7 +522,7 @@ private object PreviewItems {
|
||||
) {
|
||||
EnabledDisabledElementThemedPreview {
|
||||
ListItem(
|
||||
headlineContent = headline(),
|
||||
content = content(),
|
||||
supportingContent = text(),
|
||||
leadingContent = leadingContent,
|
||||
trailingContent = trailingContent,
|
||||
@@ -543,7 +542,7 @@ private object PreviewItems {
|
||||
) {
|
||||
EnabledDisabledElementThemedPreview {
|
||||
ListItem(
|
||||
headlineContent = headline(),
|
||||
content = content(),
|
||||
supportingContent = textSingleLine(),
|
||||
leadingContent = leadingContent,
|
||||
trailingContent = trailingContent,
|
||||
@@ -563,7 +562,7 @@ private object PreviewItems {
|
||||
) {
|
||||
EnabledDisabledElementThemedPreview {
|
||||
ListItem(
|
||||
headlineContent = headline(),
|
||||
content = content(),
|
||||
leadingContent = leadingContent,
|
||||
trailingContent = trailingContent,
|
||||
enabled = it,
|
||||
@@ -574,7 +573,7 @@ private object PreviewItems {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun headline() = @Composable {
|
||||
fun content() = @Composable {
|
||||
Text("List item")
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -134,7 +134,7 @@ internal fun ListSupportingTextNoPaddingPreview() {
|
||||
internal fun ListSupportingTextDefaultPaddingPreview() {
|
||||
ElementThemedPreview {
|
||||
Column {
|
||||
ListItem(headlineContent = { Text("A title") })
|
||||
ListItem(content = { Text("A title") })
|
||||
ListSupportingText(
|
||||
text = "Supporting line text lorem ipsum dolor sit amet, consectetur. Read more",
|
||||
contentPadding = ListSupportingTextDefaults.Padding.Default,
|
||||
@@ -149,7 +149,7 @@ internal fun ListSupportingTextSmallPaddingPreview() {
|
||||
ElementThemedPreview {
|
||||
Column {
|
||||
ListItem(
|
||||
headlineContent = { Text("A title") },
|
||||
content = { Text("A title") },
|
||||
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.ShareAndroid()))
|
||||
)
|
||||
ListSupportingText(
|
||||
@@ -165,7 +165,7 @@ internal fun ListSupportingTextSmallPaddingPreview() {
|
||||
internal fun ListSupportingTextLargePaddingPreview() {
|
||||
ElementThemedPreview {
|
||||
Column {
|
||||
ListItem(headlineContent = { Text("A title") }, leadingContent = ListItemContent.Switch(checked = true))
|
||||
ListItem(content = { Text("A title") }, leadingContent = ListItemContent.Switch(checked = true))
|
||||
ListSupportingText(
|
||||
text = "Supporting line text lorem ipsum dolor sit amet, consectetur. Read more",
|
||||
contentPadding = ListSupportingTextDefaults.Padding.LargeLeadingContent,
|
||||
@@ -179,7 +179,7 @@ internal fun ListSupportingTextLargePaddingPreview() {
|
||||
internal fun ListSupportingTextCustomPaddingPreview() {
|
||||
ElementThemedPreview {
|
||||
Column {
|
||||
ListItem(headlineContent = { Text("A title") })
|
||||
ListItem(content = { Text("A title") })
|
||||
ListSupportingText(
|
||||
text = "Supporting line text lorem ipsum dolor sit amet, consectetur. Read more",
|
||||
contentPadding = ListSupportingTextDefaults.Padding.Custom(24.dp),
|
||||
|
||||
Reference in New Issue
Block a user