mirror of
https://github.com/bitwarden/android.git
synced 2025-02-17 12:30:00 +03:00
Improve switch toggle semantics (#140)
This commit is contained in:
parent
f5619d1710
commit
3f742cc6df
3 changed files with 14 additions and 5 deletions
|
@ -16,6 +16,8 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.semantics.semantics
|
import androidx.compose.ui.semantics.semantics
|
||||||
|
import androidx.compose.ui.semantics.toggleableState
|
||||||
|
import androidx.compose.ui.state.ToggleableState
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@ -43,7 +45,9 @@ fun BitwardenSwitch(
|
||||||
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
|
indication = rememberRipple(color = MaterialTheme.colorScheme.primary),
|
||||||
onClick = { onCheckedChange?.invoke(!isChecked) },
|
onClick = { onCheckedChange?.invoke(!isChecked) },
|
||||||
)
|
)
|
||||||
.semantics(mergeDescendants = true) { }
|
.semantics(mergeDescendants = true) {
|
||||||
|
toggleableState = ToggleableState(isChecked)
|
||||||
|
}
|
||||||
.then(modifier),
|
.then(modifier),
|
||||||
) {
|
) {
|
||||||
Switch(
|
Switch(
|
||||||
|
|
|
@ -17,6 +17,8 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.semantics.contentDescription
|
import androidx.compose.ui.semantics.contentDescription
|
||||||
import androidx.compose.ui.semantics.semantics
|
import androidx.compose.ui.semantics.semantics
|
||||||
|
import androidx.compose.ui.semantics.toggleableState
|
||||||
|
import androidx.compose.ui.state.ToggleableState
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
|
||||||
|
@ -50,6 +52,7 @@ fun BitwardenWideSwitch(
|
||||||
onClick = { onCheckedChange?.invoke(!isChecked) },
|
onClick = { onCheckedChange?.invoke(!isChecked) },
|
||||||
)
|
)
|
||||||
.semantics(mergeDescendants = true) {
|
.semantics(mergeDescendants = true) {
|
||||||
|
toggleableState = ToggleableState(isChecked)
|
||||||
if (contentDescription != null) {
|
if (contentDescription != null) {
|
||||||
this.contentDescription = contentDescription
|
this.contentDescription = contentDescription
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import androidx.compose.ui.semantics.ProgressBarRangeInfo
|
||||||
import androidx.compose.ui.semantics.SemanticsProperties
|
import androidx.compose.ui.semantics.SemanticsProperties
|
||||||
import androidx.compose.ui.test.SemanticsMatcher.Companion.expectValue
|
import androidx.compose.ui.test.SemanticsMatcher.Companion.expectValue
|
||||||
import androidx.compose.ui.test.assertIsDisplayed
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.assertIsOff
|
||||||
|
import androidx.compose.ui.test.assertIsOn
|
||||||
import androidx.compose.ui.test.filterToOne
|
import androidx.compose.ui.test.filterToOne
|
||||||
import androidx.compose.ui.test.hasContentDescription
|
import androidx.compose.ui.test.hasContentDescription
|
||||||
import androidx.compose.ui.test.hasProgressBarRangeInfo
|
import androidx.compose.ui.test.hasProgressBarRangeInfo
|
||||||
|
@ -156,22 +158,22 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||||
composeTestRule
|
composeTestRule
|
||||||
.onNodeWithText("A—Z")
|
.onNodeWithText("A—Z")
|
||||||
.performScrollTo()
|
.performScrollTo()
|
||||||
.assertIsDisplayed()
|
.assertIsOn()
|
||||||
|
|
||||||
composeTestRule
|
composeTestRule
|
||||||
.onNodeWithText("a—z")
|
.onNodeWithText("a—z")
|
||||||
.performScrollTo()
|
.performScrollTo()
|
||||||
.assertIsDisplayed()
|
.assertIsOn()
|
||||||
|
|
||||||
composeTestRule
|
composeTestRule
|
||||||
.onNodeWithText("0-9")
|
.onNodeWithText("0-9")
|
||||||
.performScrollTo()
|
.performScrollTo()
|
||||||
.assertIsDisplayed()
|
.assertIsOn()
|
||||||
|
|
||||||
composeTestRule
|
composeTestRule
|
||||||
.onNodeWithText("!@#$%^&*")
|
.onNodeWithText("!@#$%^&*")
|
||||||
.performScrollTo()
|
.performScrollTo()
|
||||||
.assertIsDisplayed()
|
.assertIsOff()
|
||||||
|
|
||||||
composeTestRule
|
composeTestRule
|
||||||
.onNodeWithContentDescription("Minimum numbers, 1")
|
.onNodeWithContentDescription("Minimum numbers, 1")
|
||||||
|
|
Loading…
Add table
Reference in a new issue