Scott Kruse
04/27/2023, 4:55 PMLouis Pullen-Freilich [G]
04/27/2023, 9:58 PMFocusInteraction.Focus
as its latest interaction
There’s a few ways you can do this, either just create a MutableInteractionSource() and emit that interaction, or you can create a fake implementation of InteractionSource that returns a flow that contains that interaction, whatever works for your code base / other usages I guess is fineScott Kruse
04/28/2023, 3:49 AMScott Kruse
04/28/2023, 4:58 AMclass PreviewInteractionSource : MutableInteractionSource {
override val interactions: Flow<Interaction>
get() = MutableStateFlow(FocusInteraction.Focus())
override suspend fun emit(interaction: Interaction) {
TODO("Not yet implemented")
}
override fun tryEmit(interaction: Interaction): Boolean {
TODO("Not yet implemented")
}
}
@Composable
@Preview
fun FocusedPrimaryButtonPreview() {
Button(
text = "Focused",
interactionSource = remember {
PreviewInteractionSource()
}
)
}
@Composable
fun Button(
text: String,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }
) {
val isFocused = interactionSource.collectIsFocusedAsState().value
androidx.compose.material3.Button(
colors = resolveButtonColors(
isFocused = isFocused,
),
interactionSource = interactionSource,
) {
Text(
text = text,
color = if (isFocused) Color.Black else Color.White
)
}
}
Hmmm not seeing the expected result w/ this snippet above..Louis Pullen-Freilich [G]
04/28/2023, 1:27 PMScott Kruse
04/28/2023, 6:21 PM