Tweak TriStateItem view to match in earlier app version (#8898)

* Tweak `TriStateItem` view to match in earlier app version

* Apply to disabled state too
This commit is contained in:
zbue 2023-01-13 06:46:24 +08:00 committed by GitHub
parent 7329f03bc5
commit db4ae134aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.material.ContentAlpha
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDownward import androidx.compose.material.icons.filled.ArrowDownward
import androidx.compose.material.icons.filled.ArrowUpward import androidx.compose.material.icons.filled.ArrowUpward
@ -46,6 +47,8 @@ fun TriStateItem(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(24.dp), horizontalArrangement = Arrangement.spacedBy(24.dp),
) { ) {
val stateAlpha = if (onClick != null) 1f else ContentAlpha.disabled
Icon( Icon(
imageVector = when (state) { imageVector = when (state) {
TriStateFilter.DISABLED -> Icons.Rounded.CheckBoxOutlineBlank TriStateFilter.DISABLED -> Icons.Rounded.CheckBoxOutlineBlank
@ -54,13 +57,17 @@ fun TriStateItem(
}, },
contentDescription = null, contentDescription = null,
tint = if (state == TriStateFilter.DISABLED) { tint = if (state == TriStateFilter.DISABLED) {
MaterialTheme.colorScheme.onSurfaceVariant MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = stateAlpha)
} else { } else {
MaterialTheme.colorScheme.primary when (onClick) {
null -> MaterialTheme.colorScheme.onSurface.copy(alpha = ContentAlpha.disabled)
else -> MaterialTheme.colorScheme.primary
}
}, },
) )
Text( Text(
text = label, text = label,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = stateAlpha),
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
) )
} }