OneUi7Switch

fun UiTreeBuilder.OneUi7Switch(text: String, checked: Boolean, onCheckedChange: (Boolean) -> Unit, enabled: Boolean = true, key: Any? = null, modifier: Modifier = Modifier)(source)

Emits a One UI 7 alpha labeled switch as a design-system-owned composite.

The caller owns checked and must publish the replacement value from onCheckedChange. The complete 48dp-high row is one Switch-semantic target. Clicking any enabled part invokes the callback synchronously with !checked; horizontal dragging follows the pointer and settles by position or velocity without also firing the click action. Release settlement continues from the last follow-finger position instead of restarting from a stale endpoint. Visual geometry and drag anchors are renderer-neutral and follow layout direction, while Android retains focus and accessibility action ownership.

Receiver

active builder inside OneUi7Theme

Parameters

text

localized label merged into the switch accessibility node

checked

current caller-owned selection state

onCheckedChange

callback receiving the requested replacement state

enabled

whether input and enabled semantics are active

key

optional stable root identity

modifier

caller configuration appended to the complete target

Throws

Samples

val checked = rememberSaveable(key = "one-ui-switch") { mutableStateOf(true) }
val selected = rememberSaveable(key = "one-ui-navigation") { mutableStateOf(0) }
val accountName = rememberTextFieldState("Galaxy")
val destinations = listOf(
    OneUi7NavigationItem(key = "home", label = "Home"),
    OneUi7NavigationItem(key = "search", label = "Search"),
    OneUi7NavigationItem(key = "profile", label = "Profile"),
)

OneUi7Theme {
    Column(spacing = 16.dp) {
        OneUi7Button(text = "Continue", onClick = {})
        OneUi7Button(
            text = "Later",
            onClick = {},
            variant = OneUi7ButtonVariant.Neutral,
        )
        OneUi7Button(
            text = "Flat action",
            onClick = {},
            variant = OneUi7ButtonVariant.Flat,
        )
        OneUi7Surface(modifier = Modifier.fillMaxWidth()) {
            Text(
                text = "One UI 7 alpha surface",
                color = Theme.colors.onSurface,
                style = Theme.typography.bodyMedium,
            )
        }
        OneUi7Switch(
            text = "Sync devices",
            checked = checked.value,
            onCheckedChange = { checked.value = it },
            modifier = Modifier.fillMaxWidth(),
        )
        OneUi7TextField(
            state = accountName,
            label = "Account name",
            placeholder = "Name",
            supportingText = "Uses the native Android editing core.",
            modifier = Modifier.fillMaxWidth(),
        )
        OneUi7NavigationBar(
            items = destinations,
            selectedIndex = selected.value,
            onItemSelected = { selected.value = it },
        )
    }
}