Disable inline autofill toggle when autofill is disabled (#674)

This commit is contained in:
Brian Yencho
2024-01-18 22:00:28 -06:00
committed by Álison Fernandes
parent b77de7ba4d
commit cb306a8377
4 changed files with 60 additions and 3 deletions

View File

@@ -36,6 +36,8 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
* @param description An optional description label to be displayed below the [label].
* @param contentDescription A description of the switch's UI for accessibility purposes.
* @param readOnly Disables the click functionality without modifying the other UI characteristics.
* @param enabled Whether or not this switch is enabled. This is similar to setting [readOnly] but
* comes with some additional visual changes.
*/
@Composable
fun BitwardenWideSwitch(
@@ -46,6 +48,7 @@ fun BitwardenWideSwitch(
description: String? = null,
contentDescription: String? = null,
readOnly: Boolean = false,
enabled: Boolean = true,
) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
@@ -56,7 +59,7 @@ fun BitwardenWideSwitch(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
onClick = { onCheckedChange?.invoke(!isChecked) },
enabled = !readOnly,
enabled = !readOnly && enabled,
)
.semantics(mergeDescendants = true) {
toggleableState = ToggleableState(isChecked)
@@ -72,13 +75,21 @@ fun BitwardenWideSwitch(
Text(
text = label,
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
color = if (enabled) {
MaterialTheme.colorScheme.onSurface
} else {
MaterialTheme.colorScheme.outline
},
)
description?.let {
Text(
text = it,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
color = if (enabled) {
MaterialTheme.colorScheme.onSurfaceVariant
} else {
MaterialTheme.colorScheme.outline
},
)
}
}

View File

@@ -135,6 +135,7 @@ fun AutoFillScreen(
onCheckedChange = remember(viewModel) {
{ viewModel.trySendAction(AutoFillAction.UseInlineAutofillClick(it)) }
},
enabled = state.canInteractWithInlineAutofillToggle,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),

View File

@@ -127,6 +127,14 @@ data class AutoFillState(
val isUseInlineAutoFillEnabled: Boolean,
val uriDetectionMethod: UriDetectionMethod,
) : Parcelable {
/**
* Whether or not the toggle controlling the [isUseInlineAutoFillEnabled] value can be
* interacted with.
*/
val canInteractWithInlineAutofillToggle: Boolean
get() = isAutoFillServicesEnabled
/**
* A representation of the URI detection methods.
*/