This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val AnimationDurationMillis = 600 | |
enum class SelectionMode(val index: Int) { | |
Single(0), | |
Multiple(1); | |
companion object { | |
fun fromIndex(index: Int) = entries.firstOrNull { it.index == index } ?: Single | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalLayoutApi::class) | |
@Composable | |
fun ChipsSelector( | |
// 1 | |
state: ChipSelectorState, | |
// 2 | |
modifier: Modifier = Modifier, | |
horizontalArrangement: Arrangement.Horizontal = Arrangement.spacedBy(16.dp), | |
verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(16.dp), | |
) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChipSelectorStateImpl( | |
// 1 | |
override val chips: List<String>, | |
// 2 | |
selectedChips: List<String> = emptyList(), | |
// 3 | |
val mode: SelectionMode = SelectionMode.Single, | |
) : ChipSelectorState { | |
// 4 | |
override var selectedChips by mutableStateOf(selectedChips) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
enum class SelectionMode { | |
Single, | |
Multiple, | |
} | |
// 2 | |
@Stable | |
interface ChipSelectorState { | |
// 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun Chip( | |
label: String, | |
isSelected: Boolean, | |
onClick: () -> Unit, | |
modifier: Modifier = Modifier | |
) { | |
val transition = updateTransition(targetState = isSelected, label = "transition") | |
// 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun Chip( | |
label: String, | |
isSelected: Boolean, | |
onClick: () -> Unit, | |
modifier: Modifier = Modifier | |
) { | |
// omitted for brevity | |
val transition = updateTransition(targetState = isSelected, label = "transition") | |
val pathFraction by transition.animateFloat( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun Chip( | |
label: String, | |
isSelected: Boolean, | |
onClick: () -> Unit, | |
modifier: Modifier = Modifier | |
) { | |
val interactionSource = remember { MutableInteractionSource() } | |
val borderColor = MaterialTheme.colorScheme.onSurface | |
val backgroundColor = if (isSelected) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun Chip( | |
label: String, | |
isSelected: Boolean, | |
onClick: () -> Unit, | |
modifier: Modifier = Modifier | |
) { | |
// 1 | |
val borderColor = MaterialTheme.colorScheme.onSurface | |
val backgroundColor = if (isSelected) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun Chip( | |
// 1 | |
label: String, | |
// 2 | |
isSelected: Boolean, | |
// 3 | |
onClick: () -> Unit, | |
// 4 | |
modifier: Modifier = Modifier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun SampleUi( | |
stable state: State | |
) | |
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun PrimitivesMethod( | |
stable value: Int | |
stable prompt: String | |
stable modifier: Modifier? = @static Companion | |
) | |
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun CollectionsMethod( | |
stable values: Set<Int> |