Skip to content

Commit 7f2d5b9

Browse files
committed
misc : add enabled param to ListItemContent.Custom View
1 parent cad746e commit 7f2d5b9

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserSection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private fun PreferenceBlockUser(
7070
isLoading: Boolean,
7171
eventSink: (UserProfileEvents) -> Unit,
7272
) {
73-
val loadingCurrentValue = @Composable {
73+
val loadingCurrentValue = @Composable { _: Boolean ->
7474
CircularProgressIndicator(
7575
modifier = Modifier
7676
.progressSemantics()

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/list/ListItemContent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ sealed interface ListItemContent {
8585
data class Text(val text: String) : ListItemContent
8686

8787
/** Displays any custom content. */
88-
data class Custom(val content: @Composable () -> Unit) : ListItemContent
88+
data class Custom(val content: @Composable (enabled: Boolean) -> Unit) : ListItemContent
8989

9090
/** Displays a badge. */
9191
data object Badge : ListItemContent
@@ -131,7 +131,7 @@ sealed interface ListItemContent {
131131
is Counter -> {
132132
CounterAtom(count = count)
133133
}
134-
is Custom -> content()
134+
is Custom -> content(isItemEnabled)
135135
}
136136
}
137137
}

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/preferences/PreferenceCheckbox.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ fun PreferenceCheckbox(
4343
leadingContent = preferenceIcon(
4444
icon = icon,
4545
iconResourceId = iconResourceId,
46-
enabled = enabled,
4746
showIconAreaIfNoIcon = showIconAreaIfNoIcon,
4847
),
4948
headlineContent = {

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/preferences/PreferenceDropdown.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import io.element.android.libraries.designsystem.theme.components.DropdownMenuIt
4040
import io.element.android.libraries.designsystem.theme.components.Icon
4141
import io.element.android.libraries.designsystem.theme.components.ListItem
4242
import io.element.android.libraries.designsystem.theme.components.Text
43-
import io.element.android.libraries.designsystem.toEnabledColor
43+
import io.element.android.libraries.designsystem.toIconSecondaryEnabledColor
4444
import io.element.android.libraries.designsystem.toSecondaryEnabledColor
4545
import kotlinx.collections.immutable.ImmutableList
4646
import kotlinx.collections.immutable.toImmutableList
@@ -64,38 +64,37 @@ fun <T : DropdownOption> PreferenceDropdown(
6464
leadingContent = preferenceIcon(
6565
icon = icon,
6666
iconResourceId = iconResourceId,
67-
enabled = enabled,
6867
showIconAreaIfNoIcon = showIconAreaIfNoIcon,
6968
),
7069
headlineContent = {
7170
Text(
7271
style = ElementTheme.typography.fontBodyLgRegular,
7372
modifier = Modifier.fillMaxWidth(),
7473
text = title,
75-
color = enabled.toEnabledColor(),
7674
)
7775
},
7876
supportingContent = supportingText?.let {
7977
{
8078
Text(
8179
style = ElementTheme.typography.fontBodyMdRegular,
8280
text = it,
83-
color = enabled.toSecondaryEnabledColor(),
8481
)
8582
}
8683
},
8784
trailingContent = ListItemContent.Custom(
88-
content = {
85+
content = { enabled ->
8986
DropdownTrailingContent(
9087
selectedOption = selectedOption,
9188
options = options,
9289
onSelectOption = onSelectOption,
9390
expanded = isDropdownExpanded,
9491
onExpandedChange = { isDropdownExpanded = it },
92+
enabled = enabled,
9593
modifier = Modifier.fillMaxSize(0.3f)
9694
)
9795
}
9896
),
97+
enabled = enabled,
9998
onClick = { isDropdownExpanded = true }.takeIf { !isDropdownExpanded },
10099
)
101100
}
@@ -118,6 +117,7 @@ private fun <T : DropdownOption> DropdownTrailingContent(
118117
expanded: Boolean,
119118
onExpandedChange: (Boolean) -> Unit,
120119
onSelectOption: (T) -> Unit,
120+
enabled: Boolean,
121121
modifier: Modifier = Modifier,
122122
) {
123123
Row(
@@ -129,15 +129,15 @@ private fun <T : DropdownOption> DropdownTrailingContent(
129129
text = selectedOption?.getText().orEmpty(),
130130
maxLines = 1,
131131
style = ElementTheme.typography.fontBodyMdRegular,
132-
color = ElementTheme.colors.textSecondary,
132+
color = enabled.toSecondaryEnabledColor(),
133133
overflow = TextOverflow.Ellipsis,
134134
textAlign = TextAlign.End,
135135
modifier = Modifier.weight(1f),
136136
)
137137
Icon(
138138
imageVector = CompoundIcons.ChevronDown(),
139139
contentDescription = null,
140-
tint = ElementTheme.colors.iconSecondary,
140+
tint = enabled.toIconSecondaryEnabledColor(),
141141
)
142142
DropdownMenu(
143143
expanded = expanded,
@@ -146,6 +146,7 @@ private fun <T : DropdownOption> DropdownTrailingContent(
146146
) {
147147
options.forEach { option ->
148148
DropdownMenuItem(
149+
enabled = enabled,
149150
text = {
150151
Text(
151152
text = option.getText(),
@@ -206,5 +207,14 @@ internal fun PreferenceDropdownPreview() = ElementThemedPreview {
206207
options = options,
207208
onSelectOption = {},
208209
)
210+
PreferenceDropdown(
211+
title = "Dropdown",
212+
supportingText = "Options for dropdown",
213+
icon = CompoundIcons.Threads(),
214+
selectedOption = options.first(),
215+
options = options,
216+
onSelectOption = {},
217+
enabled = false
218+
)
209219
}
210220
}

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/preferences/PreferenceSlide.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ fun PreferenceSlide(
4444
leadingContent = preferenceIcon(
4545
icon = icon,
4646
iconResourceId = iconResourceId,
47-
enabled = enabled,
4847
showIconAreaIfNoIcon = showIconAreaIfNoIcon,
4948
),
5049
headlineContent = {

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/preferences/PreferenceSwitch.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ fun PreferenceSwitch(
4242
leadingContent = preferenceIcon(
4343
icon = icon,
4444
iconResourceId = iconResourceId,
45-
enabled = enabled,
4645
showIconAreaIfNoIcon = showIconAreaIfNoIcon,
4746
),
4847
headlineContent = {

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/preferences/components/PreferenceIcon.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ fun preferenceIcon(
3434
@DrawableRes iconResourceId: Int? = null,
3535
showIconBadge: Boolean = false,
3636
tintColor: Color? = null,
37-
enabled: Boolean = true,
3837
showIconAreaIfNoIcon: Boolean = false,
3938
): ListItemContent.Custom? {
4039
return if (icon != null || iconResourceId != null || showIconAreaIfNoIcon) {
41-
ListItemContent.Custom {
40+
ListItemContent.Custom { enabled ->
4241
PreferenceIcon(
4342
icon = icon,
4443
iconResourceId = iconResourceId,

0 commit comments

Comments
 (0)