{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

State

public interface State<T extends Object>

Known direct subclasses
AnimationState

AnimationState contains the necessary information to indicate the state of an animation.

DoubleState

A value holder where reads to the doubleValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

FloatState

A value holder where reads to the floatValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

InfiniteTransition.TransitionAnimationState

Each animation created using InfiniteTransition.animateColor, InfiniteTransition.animateFloat, or InfiniteTransition.animateValue is represented as a TransitionAnimationState in InfiniteTransition.

IntState

A value holder where reads to the intValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

LongState

A value holder where reads to the longValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

MutableState

A mutable value holder where reads to the value property during the execution of a Composable function, the current RecomposeScope will be subscribed to changes of that value.

ToolingState

Tooling can override mutableStateOf in Composable with ToolingState.

Transition.TransitionAnimationState

Each animation created using animateFloat, animateDp, etc is represented as a TransitionAnimationState in Transition.

Known indirect subclasses
MutableDoubleState

A value holder where reads to the doubleValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

MutableFloatState

A value holder where reads to the floatValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

MutableIntState

A value holder where reads to the intValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

MutableLongState

A value holder where reads to the longValue property during the execution of a Composable function cause the current RecomposeScope to subscribe to changes of that value.

ProduceStateScope

Receiver scope for use with produceState.

SnapshotMutableState

A mutable value holder where reads to the value property during the execution of a Composable function, the current RecomposeScope will be subscribed to changes of that value.


A value holder where reads to the value property during the execution of a Composable function, the current RecomposeScope will be subscribed to changes of that value.

See also
MutableState
mutableStateOf

Summary

Public methods

abstract @NonNull T

Extension functions

default final @NonNull DoubleState

Converts a State<Double> (as in, a State of boxed Doubles) into a primitive-backed Double.

default final @NonNull FloatState

Converts a State<Float> (as in, a State of boxed Floats) into a primitive-backed Float.

default final @NonNull IntState

Converts a State<Int> (as in, a State of boxed Ints) into a primitive-backed IntState.

default final @NonNull LongState

Converts a State<Long> (as in, a State of boxed Longs) into a primitive-backed LongState.

default final @NonNull T
<T extends Object> SnapshotStateKt.getValue(
    @NonNull State<@NonNull T> receiver,
    Object thisObj,
    @NonNull KProperty<@NonNull ?> property
)

Permits property delegation of vals using by for State.

Public methods

getValue

abstract @NonNullgetValue()

Extension functions

SnapshotStateExtensionsKt.asDoubleState

default final @NonNull DoubleState SnapshotStateExtensionsKt.asDoubleState(
    @NonNull State<@NonNull Double> receiver
)

Converts a State<Double> (as in, a State of boxed Doubles) into a primitive-backed Double. The state will be automatically unboxed to the required primitive type. The returned state is read-only. The returned state will mirror the values of the base state and apply updates in the same way as the receiver defines.

On the JVM, this conversion does not avoid the autoboxing that Double attempts to escape, but instead is intended to allow interoperability between components that use either representation of a state of type Double.

SnapshotStateExtensionsKt.asFloatState

default final @NonNull FloatState SnapshotStateExtensionsKt.asFloatState(
    @NonNull State<@NonNull Float> receiver
)

Converts a State<Float> (as in, a State of boxed Floats) into a primitive-backed Float. The state will be automatically unboxed to the required primitive type. The returned state is read-only. The returned state will mirror the values of the base state and apply updates in the same way as the receiver defines.

On the JVM, this conversion does not avoid the autoboxing that Float attempts to escape, but instead is intended to allow interoperability between components that use either representation of a state of type Float.

SnapshotStateExtensionsKt.asIntState

default final @NonNull IntState SnapshotStateExtensionsKt.asIntState(
    @NonNull State<@NonNull Integer> receiver
)

Converts a State<Int> (as in, a State of boxed Ints) into a primitive-backed IntState. The state will be automatically unboxed to the required primitive type. The returned state is read-only. The returned state will mirror the values of the base state and apply updates in the same way as the receiver defines.

On the JVM, this conversion does not avoid the autoboxing that IntState attempts to escape, but instead is intended to allow interoperability between components that use either representation of a state of type Int.

SnapshotStateExtensionsKt.asLongState

default final @NonNull LongState SnapshotStateExtensionsKt.asLongState(
    @NonNull State<@NonNull Long> receiver
)

Converts a State<Long> (as in, a State of boxed Longs) into a primitive-backed LongState. The state will be automatically unboxed to the required primitive type. The returned state is read-only. The returned state will mirror the values of the base state and apply updates in the same way as the receiver defines.

On the JVM, this conversion does not avoid the autoboxing that LongState attempts to escape, but instead is intended to allow interoperability between components that use either representation of a state of type Long.

SnapshotStateKt.getValue

default final @NonNull T <T extends Object> SnapshotStateKt.getValue(
    @NonNull State<@NonNull T> receiver,
    Object thisObj,
    @NonNull KProperty<@NonNull ?> property
)

Permits property delegation of vals using by for State.

import androidx.compose.foundation.layout.Row
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State

// Composable function that manages a subscription to a data source, returning it as State
@Composable
fun observeSampleData(): State<String> = TODO()

// Subscription is managed here, but currentValue is not read yet
val currentValue by observeSampleData()

Row {
    // This scope will recompose when currentValue changes
    Text("Data: $currentValue")
}