mirror of
https://github.com/bitwarden/android.git
synced 2025-02-16 11:59:57 +03:00
Simplify and clean up segmented button (#3977)
This commit is contained in:
parent
80c1c26f5c
commit
aaa541dd19
1 changed files with 8 additions and 9 deletions
|
@ -1,12 +1,13 @@
|
||||||
package com.x8bit.bitwarden.ui.platform.components.segment
|
package com.x8bit.bitwarden.ui.platform.components.segment
|
||||||
|
|
||||||
import androidx.compose.material3.MultiChoiceSegmentedButtonRow
|
|
||||||
import androidx.compose.material3.SegmentedButton
|
import androidx.compose.material3.SegmentedButton
|
||||||
import androidx.compose.material3.SegmentedButtonDefaults
|
import androidx.compose.material3.SegmentedButtonDefaults
|
||||||
|
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.testTag
|
import androidx.compose.ui.semantics.semantics
|
||||||
|
import androidx.compose.ui.semantics.testTag
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,24 +18,22 @@ import kotlinx.collections.immutable.ImmutableList
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun BitwardenSegmentedButton(
|
fun BitwardenSegmentedButton(
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
options: ImmutableList<SegmentedButtonState>,
|
options: ImmutableList<SegmentedButtonState>,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
MultiChoiceSegmentedButtonRow(
|
SingleChoiceSegmentedButtonRow(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
) {
|
) {
|
||||||
options.forEachIndexed { index, option ->
|
options.forEachIndexed { index, option ->
|
||||||
SegmentedButton(
|
SegmentedButton(
|
||||||
checked = option.isChecked,
|
selected = option.isChecked,
|
||||||
onCheckedChange = { option.onClick() },
|
onClick = option.onClick,
|
||||||
shape = SegmentedButtonDefaults.itemShape(
|
shape = SegmentedButtonDefaults.itemShape(
|
||||||
index = index,
|
index = index,
|
||||||
count = options.size,
|
count = options.size,
|
||||||
),
|
),
|
||||||
label = { Text(text = option.text) },
|
label = { Text(text = option.text) },
|
||||||
modifier = Modifier.run {
|
modifier = Modifier.semantics { option.testTag?.let { testTag = it } },
|
||||||
option.testTag?.let { testTag(it) } ?: this
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue