RemoteButtonGroup

Functions summary

Unit
@Composable
@RemoteComposable
RemoteButtonGroup(
    modifier: RemoteModifier,
    spacing: RemoteDp,
    expansionWidth: RemoteDp,
    contentPadding: RemotePaddingValues,
    verticalAlignment: RemoteAlignment.Vertical,
    content: @RemoteComposable @Composable RemoteButtonGroupScope.() -> Unit
)

Layout component to implement an expressive group of buttons in a row.

Functions

@Composable
@RemoteComposable
fun RemoteButtonGroup(
    modifier: RemoteModifier = RemoteModifier,
    spacing: RemoteDp = RemoteButtonGroupDefaults.Spacing,
    expansionWidth: RemoteDp = RemoteButtonGroupDefaults.ExpansionWidth,
    contentPadding: RemotePaddingValues = RemoteButtonGroupDefaults.fullWidthPaddings(),
    verticalAlignment: RemoteAlignment.Vertical = RemoteAlignment.CenterVertically,
    content: @RemoteComposable @Composable RemoteButtonGroupScope.() -> Unit
): Unit

Layout component to implement an expressive group of buttons in a row.

Each button in a RemoteButtonGroup should apply at least one RemoteButtonGroupScope modifier (RemoteButtonGroupScope.weight, RemoteButtonGroupScope.minWidth, or RemoteButtonGroupScope.animateWidth) to participate in width distribution. With RemoteButtonGroupScope.animateWidth, pressing a button expands its width by expansionWidth while its neighboring button(s) shrink accordingly, with the spatial springs of RemoteMaterialTheme.motionScheme. The press animation needs a profile that supports touch actions.

Example of a RemoteButtonGroup with 3 equal-width buttons:

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Call
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.MailOutline
import androidx.compose.remote.creation.compose.action.hostAction
import androidx.compose.remote.creation.compose.capture.toRemoteImageVector
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.fillMaxWidth
import androidx.compose.remote.creation.compose.state.rf
import androidx.compose.remote.creation.compose.state.rs
import androidx.wear.compose.remote.material3.RemoteButtonDefaults
import androidx.wear.compose.remote.material3.RemoteButtonGroup
import androidx.wear.compose.remote.material3.RemoteIcon
import androidx.wear.compose.remote.material3.RemoteIconButton
import androidx.wear.compose.remote.material3.RemoteIconButtonDefaults

val icons = listOf(Icons.Filled.MailOutline, Icons.Filled.Favorite, Icons.Filled.Call)
RemoteButtonGroup(modifier = modifier.fillMaxWidth()) {
    icons.forEach { icon ->
        RemoteIconButton(
            onClick = hostAction("button_click".rs),
            modifier = RemoteModifier.weight(1f.rf),
            colors = RemoteIconButtonDefaults.filledIconButtonColors(),
            shapes = RemoteIconButtonDefaults.shapes(RemoteButtonDefaults.shape),
        ) {
            RemoteIcon(imageVector = icon.toRemoteImageVector(), contentDescription = null)
        }
    }
}

Example of 3 buttons, the middle one bigger, that animate their width on press:

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Call
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.MailOutline
import androidx.compose.remote.creation.compose.action.hostAction
import androidx.compose.remote.creation.compose.capture.toRemoteImageVector
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.fillMaxWidth
import androidx.compose.remote.creation.compose.state.rf
import androidx.compose.remote.creation.compose.state.rs
import androidx.wear.compose.remote.material3.RemoteButtonDefaults
import androidx.wear.compose.remote.material3.RemoteButtonGroup
import androidx.wear.compose.remote.material3.RemoteIcon
import androidx.wear.compose.remote.material3.RemoteIconButton
import androidx.wear.compose.remote.material3.RemoteIconButtonDefaults

val buttons =
    listOf(
        Icons.Filled.MailOutline to 1f.rf,
        Icons.Filled.Favorite to 1.5f.rf,
        Icons.Filled.Call to 1f.rf,
    )
RemoteButtonGroup(modifier = modifier.fillMaxWidth()) {
    buttons.forEach { (icon, weight) ->
        RemoteIconButton(
            onClick = hostAction("button_click".rs),
            modifier = RemoteModifier.weight(weight).animateWidth(),
            colors = RemoteIconButtonDefaults.filledIconButtonColors(),
            shapes = RemoteIconButtonDefaults.shapes(RemoteButtonDefaults.shape),
        ) {
            RemoteIcon(imageVector = icon.toRemoteImageVector(), contentDescription = null)
        }
    }
}
Parameters
modifier: RemoteModifier = RemoteModifier

Modifier to be applied to the button group

spacing: RemoteDp = RemoteButtonGroupDefaults.Spacing

the amount of spacing between buttons

expansionWidth: RemoteDp = RemoteButtonGroupDefaults.ExpansionWidth

the additional width (delta) added to a pressed button's resting width, rather than an absolute target width, while its neighboring button(s) shrink by the same total amount. Non-positive values result in no width expansion when pressed.

contentPadding: RemotePaddingValues = RemoteButtonGroupDefaults.fullWidthPaddings()

The spacing values to apply internally between the container and the content

verticalAlignment: RemoteAlignment.Vertical = RemoteAlignment.CenterVertically

the vertical alignment of the button group's children.

content: @RemoteComposable @Composable RemoteButtonGroupScope.() -> Unit

the content and properties of each button. The UX guidance is to use no more than 3 buttons within a RemoteButtonGroup.