From c7d225138d659cea6f04a4866da4d43dec19c429 Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Thu, 19 Oct 2023 14:31:40 +0300 Subject: [PATCH] Bug 1860274 - Modify SwitchWithLabel behaviour --- .../org/mozilla/fenix/compose/SwitchWithLabel.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/compose/SwitchWithLabel.kt b/app/src/main/java/org/mozilla/fenix/compose/SwitchWithLabel.kt index d2a8ce38a..3462940cf 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/SwitchWithLabel.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/SwitchWithLabel.kt @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.selection.toggleable import androidx.compose.material.SwitchDefaults import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -21,6 +22,8 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.compositeOver +import androidx.compose.ui.semantics.Role +import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.unit.dp import org.mozilla.fenix.compose.annotation.LightDarkPreview import org.mozilla.fenix.theme.FirefoxTheme @@ -47,7 +50,13 @@ fun SwitchWithLabel( enabled: Boolean = true, ) { Row( - modifier = modifier, + modifier = modifier + .toggleable( + value = checked, + enabled = enabled, + role = Role.Switch, + onValueChange = onCheckedChange, + ), horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.CenterVertically, ) { @@ -63,6 +72,7 @@ fun SwitchWithLabel( ) Switch( + modifier = Modifier.clearAndSetSemantics {}, checked = checked, onCheckedChange = onCheckedChange, enabled = enabled,