misc : add enabled param to ListItemContent.Custom View

This commit is contained in:
ganfra 2025-12-22 15:25:54 +01:00
parent 7de4b7d3af
commit a12c37d6d9
7 changed files with 21 additions and 15 deletions

View file

@ -70,7 +70,7 @@ private fun PreferenceBlockUser(
isLoading: Boolean, isLoading: Boolean,
eventSink: (UserProfileEvents) -> Unit, eventSink: (UserProfileEvents) -> Unit,
) { ) {
val loadingCurrentValue = @Composable { val loadingCurrentValue = @Composable { _: Boolean ->
CircularProgressIndicator( CircularProgressIndicator(
modifier = Modifier modifier = Modifier
.progressSemantics() .progressSemantics()

View file

@ -85,7 +85,7 @@ sealed interface ListItemContent {
data class Text(val text: String) : ListItemContent data class Text(val text: String) : ListItemContent
/** Displays any custom content. */ /** Displays any custom content. */
data class Custom(val content: @Composable () -> Unit) : ListItemContent data class Custom(val content: @Composable (enabled: Boolean) -> Unit) : ListItemContent
/** Displays a badge. */ /** Displays a badge. */
data object Badge : ListItemContent data object Badge : ListItemContent
@ -131,7 +131,7 @@ sealed interface ListItemContent {
is Counter -> { is Counter -> {
CounterAtom(count = count) CounterAtom(count = count)
} }
is Custom -> content() is Custom -> content(isItemEnabled)
} }
} }
} }

View file

@ -43,7 +43,6 @@ fun PreferenceCheckbox(
leadingContent = preferenceIcon( leadingContent = preferenceIcon(
icon = icon, icon = icon,
iconResourceId = iconResourceId, iconResourceId = iconResourceId,
enabled = enabled,
showIconAreaIfNoIcon = showIconAreaIfNoIcon, showIconAreaIfNoIcon = showIconAreaIfNoIcon,
), ),
headlineContent = { headlineContent = {

View file

@ -40,7 +40,7 @@ import io.element.android.libraries.designsystem.theme.components.DropdownMenuIt
import io.element.android.libraries.designsystem.theme.components.Icon import io.element.android.libraries.designsystem.theme.components.Icon
import io.element.android.libraries.designsystem.theme.components.ListItem import io.element.android.libraries.designsystem.theme.components.ListItem
import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.toEnabledColor import io.element.android.libraries.designsystem.toIconSecondaryEnabledColor
import io.element.android.libraries.designsystem.toSecondaryEnabledColor import io.element.android.libraries.designsystem.toSecondaryEnabledColor
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
@ -64,7 +64,6 @@ fun <T : DropdownOption> PreferenceDropdown(
leadingContent = preferenceIcon( leadingContent = preferenceIcon(
icon = icon, icon = icon,
iconResourceId = iconResourceId, iconResourceId = iconResourceId,
enabled = enabled,
showIconAreaIfNoIcon = showIconAreaIfNoIcon, showIconAreaIfNoIcon = showIconAreaIfNoIcon,
), ),
headlineContent = { headlineContent = {
@ -72,7 +71,6 @@ fun <T : DropdownOption> PreferenceDropdown(
style = ElementTheme.typography.fontBodyLgRegular, style = ElementTheme.typography.fontBodyLgRegular,
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
text = title, text = title,
color = enabled.toEnabledColor(),
) )
}, },
supportingContent = supportingText?.let { supportingContent = supportingText?.let {
@ -80,22 +78,23 @@ fun <T : DropdownOption> PreferenceDropdown(
Text( Text(
style = ElementTheme.typography.fontBodyMdRegular, style = ElementTheme.typography.fontBodyMdRegular,
text = it, text = it,
color = enabled.toSecondaryEnabledColor(),
) )
} }
}, },
trailingContent = ListItemContent.Custom( trailingContent = ListItemContent.Custom(
content = { content = { enabled ->
DropdownTrailingContent( DropdownTrailingContent(
selectedOption = selectedOption, selectedOption = selectedOption,
options = options, options = options,
onSelectOption = onSelectOption, onSelectOption = onSelectOption,
expanded = isDropdownExpanded, expanded = isDropdownExpanded,
onExpandedChange = { isDropdownExpanded = it }, onExpandedChange = { isDropdownExpanded = it },
enabled = enabled,
modifier = Modifier.fillMaxSize(0.3f) modifier = Modifier.fillMaxSize(0.3f)
) )
} }
), ),
enabled = enabled,
onClick = { isDropdownExpanded = true }.takeIf { !isDropdownExpanded }, onClick = { isDropdownExpanded = true }.takeIf { !isDropdownExpanded },
) )
} }
@ -118,6 +117,7 @@ private fun <T : DropdownOption> DropdownTrailingContent(
expanded: Boolean, expanded: Boolean,
onExpandedChange: (Boolean) -> Unit, onExpandedChange: (Boolean) -> Unit,
onSelectOption: (T) -> Unit, onSelectOption: (T) -> Unit,
enabled: Boolean,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
Row( Row(
@ -129,7 +129,7 @@ private fun <T : DropdownOption> DropdownTrailingContent(
text = selectedOption?.getText().orEmpty(), text = selectedOption?.getText().orEmpty(),
maxLines = 1, maxLines = 1,
style = ElementTheme.typography.fontBodyMdRegular, style = ElementTheme.typography.fontBodyMdRegular,
color = ElementTheme.colors.textSecondary, color = enabled.toSecondaryEnabledColor(),
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.End, textAlign = TextAlign.End,
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
@ -137,7 +137,7 @@ private fun <T : DropdownOption> DropdownTrailingContent(
Icon( Icon(
imageVector = CompoundIcons.ChevronDown(), imageVector = CompoundIcons.ChevronDown(),
contentDescription = null, contentDescription = null,
tint = ElementTheme.colors.iconSecondary, tint = enabled.toIconSecondaryEnabledColor(),
) )
DropdownMenu( DropdownMenu(
expanded = expanded, expanded = expanded,
@ -146,6 +146,7 @@ private fun <T : DropdownOption> DropdownTrailingContent(
) { ) {
options.forEach { option -> options.forEach { option ->
DropdownMenuItem( DropdownMenuItem(
enabled = enabled,
text = { text = {
Text( Text(
text = option.getText(), text = option.getText(),
@ -206,5 +207,14 @@ internal fun PreferenceDropdownPreview() = ElementThemedPreview {
options = options, options = options,
onSelectOption = {}, onSelectOption = {},
) )
PreferenceDropdown(
title = "Dropdown",
supportingText = "Options for dropdown",
icon = CompoundIcons.Threads(),
selectedOption = options.first(),
options = options,
onSelectOption = {},
enabled = false
)
} }
} }

View file

@ -44,7 +44,6 @@ fun PreferenceSlide(
leadingContent = preferenceIcon( leadingContent = preferenceIcon(
icon = icon, icon = icon,
iconResourceId = iconResourceId, iconResourceId = iconResourceId,
enabled = enabled,
showIconAreaIfNoIcon = showIconAreaIfNoIcon, showIconAreaIfNoIcon = showIconAreaIfNoIcon,
), ),
headlineContent = { headlineContent = {

View file

@ -42,7 +42,6 @@ fun PreferenceSwitch(
leadingContent = preferenceIcon( leadingContent = preferenceIcon(
icon = icon, icon = icon,
iconResourceId = iconResourceId, iconResourceId = iconResourceId,
enabled = enabled,
showIconAreaIfNoIcon = showIconAreaIfNoIcon, showIconAreaIfNoIcon = showIconAreaIfNoIcon,
), ),
headlineContent = { headlineContent = {

View file

@ -34,11 +34,10 @@ fun preferenceIcon(
@DrawableRes iconResourceId: Int? = null, @DrawableRes iconResourceId: Int? = null,
showIconBadge: Boolean = false, showIconBadge: Boolean = false,
tintColor: Color? = null, tintColor: Color? = null,
enabled: Boolean = true,
showIconAreaIfNoIcon: Boolean = false, showIconAreaIfNoIcon: Boolean = false,
): ListItemContent.Custom? { ): ListItemContent.Custom? {
return if (icon != null || iconResourceId != null || showIconAreaIfNoIcon) { return if (icon != null || iconResourceId != null || showIconAreaIfNoIcon) {
ListItemContent.Custom { ListItemContent.Custom { enabled ->
PreferenceIcon( PreferenceIcon(
icon = icon, icon = icon,
iconResourceId = iconResourceId, iconResourceId = iconResourceId,