ListItem: allow list item to be clickable even when disabled.

This commit is contained in:
Benoit Marty 2024-10-29 11:32:01 +01:00 committed by Benoit Marty
parent c56e9604bf
commit e26802d8d3

View file

@ -42,6 +42,7 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
* @param trailingContent The content to be displayed after the headline content. * @param trailingContent The content to be displayed after the headline 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 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 headline 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 onClick The callback to be called when the list item is clicked.
*/ */
@Suppress("LongParameterList") @Suppress("LongParameterList")
@ -54,6 +55,7 @@ fun ListItem(
trailingContent: ListItemContent? = null, trailingContent: ListItemContent? = null,
style: ListItemStyle = ListItemStyle.Default, style: ListItemStyle = ListItemStyle.Default,
enabled: Boolean = true, enabled: Boolean = true,
alwaysClickable: Boolean = false,
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
) { ) {
val colors = ListItemDefaults.colors( val colors = ListItemDefaults.colors(
@ -74,6 +76,7 @@ fun ListItem(
trailingContent = trailingContent, trailingContent = trailingContent,
colors = colors, colors = colors,
enabled = enabled, enabled = enabled,
alwaysClickable = alwaysClickable,
onClick = onClick, onClick = onClick,
) )
} }
@ -87,6 +90,7 @@ fun ListItem(
* @param leadingContent The content to be displayed before 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 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 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 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 onClick The callback to be called when the list item is clicked.
*/ */
@Suppress("LongParameterList") @Suppress("LongParameterList")
@ -99,6 +103,7 @@ fun ListItem(
leadingContent: ListItemContent? = null, leadingContent: ListItemContent? = null,
trailingContent: ListItemContent? = null, trailingContent: ListItemContent? = null,
enabled: Boolean = true, enabled: Boolean = true,
alwaysClickable: Boolean = false,
onClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null,
) { ) {
// We cannot just pass the disabled colors, they must be set manually: https://issuetracker.google.com/issues/280480132 // We cannot just pass the disabled colors, they must be set manually: https://issuetracker.google.com/issues/280480132
@ -149,7 +154,7 @@ fun ListItem(
headlineContent = decoratedHeadlineContent, headlineContent = decoratedHeadlineContent,
modifier = if (onClick != null) { modifier = if (onClick != null) {
Modifier Modifier
.clickable(enabled = enabled, onClick = onClick) .clickable(enabled = enabled || alwaysClickable, onClick = onClick)
.then(modifier) .then(modifier)
} else { } else {
modifier modifier