androidx.ui.foundation.selection

Enums

ToggleableState

Enum that represents possible toggleable states.

Top-level functions summary

Unit
MutuallyExclusiveSetItem(selected: Boolean, onClick: () -> Unit, children: () -> Unit)

Component for representing one option out of many in mutually exclusion set, e.

Unit
Toggleable(value: Boolean, onValueChange: (Boolean) -> Unit = null, children: () -> Unit)

Combines PressReleasedGestureDetector and Semantics for the components that need to be toggleable, like Switch.

ToggleableState

Return corresponding ToggleableState based on a Boolean representation

Unit
TriStateToggleable(value: ToggleableState = ToggleableState.On, onToggle: () -> Unit = null, children: () -> Unit)

Combines PressReleasedGestureDetector and Semantics for the components with three states like TriStateCheckbox.

Top-level functions

MutuallyExclusiveSetItem

@Composable fun MutuallyExclusiveSetItem(
    selected: Boolean,
    onClick: () -> Unit,
    children: () -> Unit
): Unit

Component for representing one option out of many in mutually exclusion set, e.g androidx.ui.material.RadioGroup

Provides click handling as well as Semantics for accessibility

Parameters
selected: Boolean whether or not this item is selected in mutually exclusion set
onClick: () -> Unit callback to invoke when this item is clicked

Toggleable

@Composable fun Toggleable(
    value: Boolean,
    onValueChange: (Boolean) -> Unit = null,
    children: () -> Unit
): Unit

Combines PressReleasedGestureDetector and Semantics for the components that need to be toggleable, like Switch.

import androidx.compose.state
import androidx.ui.core.Text
import androidx.ui.foundation.selection.Toggleable

var checked by +state { false }
Toggleable(value = checked, onValueChange = { checked = it }) {
    // content that you want to make toggleable
    Text(text = checked.toString())
}
Parameters
value: Boolean whether Toggleable is on or off
onValueChange: (Boolean) -> Unit = null callback to be invoked when toggleable is being clicked, therefore the change of the state in requested. If null, Toggleable will appear in the value state and remains disabled

ToggleableState

fun ToggleableState(value: Boolean): ToggleableState

Return corresponding ToggleableState based on a Boolean representation

Parameters
value: Boolean whether the ToggleableState is on or off

TriStateToggleable

@Composable fun TriStateToggleable(
    value: ToggleableState = ToggleableState.On,
    onToggle: () -> Unit = null,
    children: () -> Unit
): Unit

Combines PressReleasedGestureDetector and Semantics for the components with three states like TriStateCheckbox.

It supports three states: On, Off and Indeterminate.

TriStateToggleable should be used when there are dependent Toggleables associated to this component and those can have different values.

import androidx.compose.state
import androidx.ui.core.Text
import androidx.ui.foundation.selection.TriStateToggleable

var checked by +state { ToggleableState.Indeterminate }
TriStateToggleable(
    value = checked,
    onToggle = {
        checked =
            if (checked == ToggleableState.On) {
                ToggleableState.Off
            } else {
                ToggleableState.On
            }
    }) {
    // content that you want to make toggleable
    Text(text = checked.toString())
}

See Also

Parameters
value: ToggleableState = ToggleableState.On current value for the component
onToggle: () -> Unit = null will be called when user toggles the toggleable. The children will not be toggleable when it is null.