Composables UI is out: our new component library for Compose Multiplatform ->
Compose Component

ButtonContent

Lays out the content of a Button with support for an icon, a label, and a secondary label.

ButtonContentWithOneHandedGestureSample

@Composable
fun ButtonContentWithOneHandedGestureSample() {
    var label by remember { mutableStateOf("Filled Button") }
    val onClick = remember { { label = "Gestured" } }
    val interactionSource = remember { MutableInteractionSource() }
    Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
        Button(
            onClick = onClick,
            interactionSource = interactionSource,
            modifier =
                Modifier.oneHandedGesture(
                    action = GestureAction.Primary,
                    interactionSource = interactionSource,
                    onGesture = onClick,
                ),
        ) {
            OneHandedGestureIndicator(
                interactionSource = interactionSource,
                gestureIndicatorTint = MaterialTheme.colorScheme.onPrimary,
            ) {
                ButtonContent(
                    secondaryLabel = { Text("Secondary Label") },
                    icon = {
                        Icon(
                            painter = painterResource(R.drawable.ic_favorite_rounded),
                            contentDescription = "Favorite icon",
                            modifier = Modifier.size(ButtonDefaults.IconSize),
                        )
                    },
                    colors = ButtonDefaults.buttonColors(),
                    label = { Text(label) },
                )
            }
        }
    }
}

Last updated: