Google is committed to advancing racial equity for Black communities. See how.

androidx.compose

Interfaces

Applier

An Applier is responsible for applying the tree-based operations that get emitted during a composition.

ChoreographerFrameCallback

CommitScope

A CommitScope represents an object that executes some code and has a cleanup in the context of the Composition lifecycle.

ComposerValidator

Composition

A composition object is usually constructed for you, and returned from an API that is used to initially compose a UI.

CompositionFrameClock

Provides a time source for display frames for use in composition.

CompositionLifecycleObserver

Objects implementing this interface are notified when they are initially used in a composition and when they are no longer being used.

EmbeddingContext

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.

ScopeUpdateScope

SnapshotMutationPolicy

A policy to control how the result of mutableStateOf and state report and merge changes to the state object.

State

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.

Classes

AbstractApplier

An abstract Applier implementation that builds the tree "top down".

Ambient

Compose passes data through the composition tree explicitly through means of parameters to composable functions.

Anchor

AndroidEmbeddingContext

BitSet

BuildableMap

Composer

Implementation of a composer for mutable tree.

CompositionCoroutineScope

A CoroutineScope used for launching side effects of a composition that also permits awaiting the next presentation frame of the composition.

CompositionReference

A CompositionReference is an opaque type that is used to logically "link" two compositions together.

KeyInfo

Information about groups and their keys.

ObserverMap

A map from a key to a set of values used for keeping the relation between some entities and a models changes of which this entities are observing.

ProvidableAmbient

A ProvidableAmbient can be used in Providers to provide values.

ProvidedValue

An instance to hold a value provided by Providers and is created by the ProvidableAmbient.provides infixed operator.

Recomposer

The scheduler for performing recomposition and applying updates to one or more Compositions.

Reference

ReferenceQueue

SlotReader

SlotTable

A gap buffer implementation of the composition slot space.

SlotWriter

Updater

WeakHashMap

WeakReference

Annotations

CheckResult

Composable

Composable functions are the fundamental building blocks of an application built with Compose.

ComposableContract

This annotation can be applied to Composable functions and provide metadata to the compiler that imply compose-specific contracts that the author of the function is guaranteeing the function complies with.

ComposeCompilerApi

ExperimentalComposeApi

Immutable

Immutable can be used to mark class as producing immutable instances.

InternalComposeApi

MainThread

NoLiveLiterals

This annotation is used to indicate to the Compose Compiler to not attempt to generate live literals inside the scope of the declaration it is applied to, even when the live literals code generation is turned on.

Stable

Stable is used to communicate some guarantees to the compose compiler about how a certain type or function will behave.

StableMarker

StableMarker marks an annotation as indicating a type is stable.

TestOnly

UnionType

Untracked

When applied to a function expression Untracked will disable lambda optimizations such as tracking execution of composable function expressions or remembering a function expression value based on its capture variables.

Top-level functions summary

actual EmbeddingContext

Unit
Providers(vararg values: ProvidedValue<*>, children: () -> Unit)

Providers binds values to ProvidableAmbient keys.

ProvidableAmbient<T>
ambientOf(policy: SnapshotMutationPolicy<T> = @OptIn(ExperimentalComposeApi::class) referentialEqualityPolicy(), defaultFactory: () -> T = null)

Create an ambient key that can be provided using Providers.

Composition
compositionFor(container: Any, recomposer: Recomposer, parent: CompositionReference? = null, composerFactory: (SlotTable, Recomposer) -> Composer<*>)

This method is the way to initiate a composition.

Composition
compositionFor(key: Any, applier: Applier<*>, recomposer: Recomposer, parent: CompositionReference? = null, onCreated: () -> Unit = {})

This method is the way to initiate a composition.

CompositionReference

An Effect to construct a CompositionReference at the current point of composition.

Unit
emit(noinline ctor: () -> T, update: Updater<T>.() -> Unit)

Emits a node into the composition of type T.

Unit
emit(noinline ctor: () -> T, update: Updater<T>.() -> Unit, children: () -> Unit)

Emits a node into the composition of type T.

() -> Unit

Represents empty content for a Composable function.

T

Boolean

Any?

Any?

T
key(vararg inputs: Any?, block: () -> T)

key is a utility composable that is used to "group" or "key" a block of execution inside of a composition.

actual String?

Unit

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition.

Unit
launchInComposition(key: Any?, block: suspend CompositionCoroutineScope.() -> Unit)

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition.

Unit
launchInComposition(key1: Any?, key2: Any?, block: suspend CompositionCoroutineScope.() -> Unit)

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition.

Unit
launchInComposition(key1: Any?, key2: Any?, key3: Any?, block: suspend CompositionCoroutineScope.() -> Unit)

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition.

Unit
launchInComposition(vararg keys: Any?, block: suspend CompositionCoroutineScope.() -> Unit)

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition.

SnapshotStateList<T>

Create a instance of MutableList that is observable and can be snapshot.

SnapshotStateList<T>
mutableStateListOf(vararg elements: T)

Create an instance of MutableList that is observable and can be snapshot.

SnapshotStateMap<K, V>

Create a instance of MutableSet<K, V> that is observable and can be snapshot.

SnapshotStateMap<K, V>
mutableStateMapOf(vararg pairs: Pair<K, V>)

Create a instance of MutableMap<K, V> that is observable and can be snapshot.

MutableState<T>
mutableStateOf(value: T, policy: SnapshotMutationPolicy<T> = referentialEqualityPolicy())

Return a new MutableState initialized with the passed in value

SnapshotMutationPolicy<T>

A policy never treat values of a MutableState as equivalent.

Unit
onActive(callback: CommitScope.() -> Unit)

An effect used to observe the lifecycle of the composition.

Unit
onCommit(noinline callback: CommitScope.() -> Unit)

The onCommit effect is a lifecycle effect that will execute callback every time the composition commits.

Unit
onCommit(v1: V1, callback: CommitScope.() -> Unit)

The onCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed.

Unit
onCommit(v1: V1, v2: V2, callback: CommitScope.() -> Unit)

The onCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed.

Unit
onCommit(vararg inputs: Any?, callback: CommitScope.() -> Unit)

The onCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed.

Unit
onDispose(callback: () -> Unit)

An effect used to schedule work to be done when the effect leaves the composition.

Unit
onPreCommit(noinline callback: CommitScope.() -> Unit)

The onPreCommit effect is a lifecycle effect that will execute callback every time the composition commits, but before those changes have been reflected on the screen.

Unit
onPreCommit(v1: V1, callback: CommitScope.() -> Unit)

The onPreCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed, but before those changes have been reflected on the screen.

Unit
onPreCommit(v1: V1, v2: V2, callback: CommitScope.() -> Unit)

The onPreCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed, but before those changes have been reflected on the screen.

Unit
onPreCommit(vararg inputs: Any?, callback: CommitScope.() -> Unit)

The onPreCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed, but before those changes have been reflected on the screen.

SnapshotMutationPolicy<T>

A policy to treat values of a MutableState as equivalent if they are referentially (===) equal.

T
remember(calculation: () -> T)

Remember the value produced by calculation.

T
remember(v1: V1, calculation: () -> T)

Remember the value returned by calculation if v1 is equal to the previous composition, otherwise produce and remember a new value by calling calculation.

T
remember(v1: V1, v2: V2, calculation: () -> T)

Remember the value returned by calculation if v1 and v2 are equal to the previous composition, otherwise produce and remember a new value by calling calculation.

T
remember(v1: V1, v2: V2, v3: V3, calculation: () -> T)

Remember the value returned by calculation if v1, v2 and v3 are equal to the previous composition, otherwise produce and remember a new value by calling calculation.

V
remember(vararg inputs: Any?, block: () -> V)

Remember the value returned by block if all values of inputs are equal to the previous composition, otherwise produce and remember a new value by calling block.

CoroutineScope
rememberCoroutineScope(getContext: () -> CoroutineContext = { EmptyCoroutineContext })

Return a CoroutineScope bound to this point in the composition using the optional CoroutineContext provided by getContext.

actual Unit

MutableState<T>
state(policy: SnapshotMutationPolicy<T> = referentialEqualityPolicy(), init: () -> T)

A composable used to introduce a state value of type T into a composition.

MutableState<T>
stateFor(v1: V1, init: () -> T)

An effect to introduce a state value of type T into a composition that will last as long as the input v1 does not change.

MutableState<T>
stateFor(v1: V1, v2: V2, init: () -> T)

An effect to introduce a state value of type T into a composition that will last as long as the inputs v1 and v2 do not change.

MutableState<T>
stateFor(vararg inputs: Any?, init: () -> T)

An effect to introduce a state value of type T into a composition that will last as long as the inputs inputs do not change.

ProvidableAmbient<T>
staticAmbientOf(defaultFactory: () -> T = null)

Create an ambient key that can be provided using Providers.

SnapshotMutationPolicy<T>

A policy to treat values of a MutableState as equivalent if they are structurally (==) equal.

suspend Unit
withRunningRecomposer(block: suspend CoroutineScope.(recomposer: Recomposer) -> Unit)

Runs block with a new, active Recomposer applying changes in the calling CoroutineContext.

Top-level properties summary

(Any?, Any?) -> Boolean

Simple comparison callback that always returns false, for mutable objects that will be compared with the same reference.

(Any?, Any?) -> Boolean

Simple comparison callback using referential === equality

(Any?, Any?) -> Boolean

Simple comparison callback using structural Any.equals equality

Composer<*>

This is here because outdated versions of the compose IDE plugin expect to find it.

Composer<*>

() -> Unit

An Effect to get the nearest invalidation lambda to the current point of composition.

Extension functions summary

For kotlin.Function0
() -> Unit
() -> Unit.orEmpty()

For kotlin.collections.Collection
SnapshotStateList<T>

Create an instance of MutableList from a collection that is observerable and can be snapshot.

For kotlin.collections.Iterable
SnapshotStateMap<K, V>

Create an instance of MutableMap<K, V> from a collection of pairs that is observable and can be snapshot.

For kotlinx.coroutines.flow.Flow
State<R>
Flow<T>.collectAsState(initial: R, context: CoroutineContext = Dispatchers.Main)

Collects values from this Flow and represents its latest value via State.

For kotlinx.coroutines.flow.StateFlow
State<T>
StateFlow<T>.collectAsState(context: CoroutineContext = Dispatchers.Main)

Collects values from this StateFlow and represents its latest value via State.

For CompositionCoroutineScope
suspend Nothing
CompositionCoroutineScope.awaitDispose(onDispose: () -> Unit = {})

Suspends the current coroutine until the effect is disposed and the CompositionCoroutineScope is cancelled, and invokes onDispose before resuming.

For CompositionFrameClock
suspend R
CompositionFrameClock.awaitFrameMillis(crossinline onFrame: (frameTimeMillis: Long) -> R)

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

suspend Long

Suspends until a new frame is requested, returning the frame time in milliseconds.

suspend Long

Suspends until a new frame is requested, returning the frame time in nanoseconds.

suspend R
CompositionFrameClock.withFrameMillis(crossinline onFrame: (frameTimeMillis: Long) -> R)

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

For State
operator T
State<T>.getValue(thisObj: Any?, property: KProperty<*>)

Permits property delegation of vals using by for State.

For MutableState
operator Unit
MutableState<T>.setValue(thisObj: Any?, property: KProperty<*>, value: T)

Permits property delegation of vars using by for MutableState.

Top-level functions

EmbeddingContext

actual fun EmbeddingContext(): EmbeddingContext

Providers

@Composable fun Providers(
    vararg values: ProvidedValue<*>,
    children: () -> Unit
): Unit

Providers binds values to ProvidableAmbient keys. Reading the ambient using Ambient.current will return the value provided in Providers's values parameter for all composable functions called directly or indirectly in the children lambda.

import androidx.compose.Providers

@Composable
fun App(user: User) {
    Providers(ActiveUser provides user) {
        SomeScreen()
    }
}

ambientOf

fun <T> ambientOf(
    policy: SnapshotMutationPolicy<T> = @OptIn(ExperimentalComposeApi::class) referentialEqualityPolicy(),
    defaultFactory: () -> T = null
): ProvidableAmbient<T>

Create an ambient key that can be provided using Providers. Changing the value provided during recomposition will invalidate the children of Providers that read the value using Ambient.current.

Parameters
policy: SnapshotMutationPolicy<T> = @OptIn(ExperimentalComposeApi::class) referentialEqualityPolicy() a policy to determine when an ambient is considered changed. See SnapshotMutationPolicy for details.

compositionFor

fun compositionFor(
    container: Any,
    recomposer: Recomposer,
    parent: CompositionReference? = null,
    composerFactory: (SlotTable, Recomposer) -> Composer<*>
): Composition

Deprecated.

This method is the way to initiate a composition. Optionally, a parent can be provided to make the composition behave as a sub-composition of the parent. The children of container will be updated and maintained by the time this method returns.

It is important to call Composition.dispose whenever this container is no longer needed in order to release resources.

Parameters
container: Any The container whose content is being composed.
recomposer: Recomposer The Recomposer to coordinate scheduling of composition updates.
parent: CompositionReference? = null The parent composition reference, if applicable. Default is null.
composerFactory: (SlotTable, Recomposer) -> Composer<*> The factory used to created a Composer to be used by the composition.

compositionFor

fun compositionFor(
    key: Any,
    applier: Applier<*>,
    recomposer: Recomposer,
    parent: CompositionReference? = null,
    onCreated: () -> Unit = {}
): Composition

This method is the way to initiate a composition. Optionally, a parent can be provided to make the composition behave as a sub-composition of the parent.

It is important to call Composition.dispose whenever this key is no longer needed in order to release resources.

import androidx.compose.compositionFor
import androidx.compose.emit
import androidx.compose.state

// Provided we have a tree with a node base type like the following
abstract class Node {
    val children = mutableListOf<Node>()
}

// We would implement an Applier class like the following, which would teach compose how to
// manage a tree of Nodes.
class NodeApplier(root: Node) : AbstractApplier<Node>(root) {
    override fun insert(index: Int, instance: Node) {
        current.children.add(index, instance)
    }

    override fun remove(index: Int, count: Int) {
        current.children.remove(index, count)
    }

    override fun move(from: Int, to: Int, count: Int) {
        current.children.move(from, to, count)
    }

    override fun onClear() {
        root.children.clear()
    }
}

// A function like the following could be created to create a composition provided a root Node.
fun Node.setContent(content: @Composable () -> Unit): Composition {
    return compositionFor(this, NodeApplier(this), Recomposer.current()).also {
        setContent(content)
    }
}

// assuming we have Node sub-classes like "TextNode" and "GroupNode"
class TextNode : Node() {
    var text: String = ""
    var onClick: () -> Unit = {}
}
class GroupNode : Node()

// Composable equivalents could be created
@Composable fun Text(text: String, onClick: () -> Unit = {}) {
    emit<TextNode, NodeApplier>(::TextNode) {
        set(text) { this.text = it }
        set(onClick) { this.onClick = it }
    }
}

@Composable fun Group(content: @Composable () -> Unit) {
    emit<GroupNode, NodeApplier>(::GroupNode, {}, content)
}

// and then a sample tree could be composed:
fun runApp(root: GroupNode) {
    root.setContent {
        var count by state { 0 }
        Group {
            Text("Count: $count")
            Text("Increment") { count++ }
        }
    }
}
Parameters
key: Any The object this composition will be tied to. Only one Composition will be created for a given key. If the same key is passed in subsequent calls, the same Composition instance will be returned.
applier: Applier<*> The Applier instance to be used in the composition.
recomposer: Recomposer The Recomposer instance to be used for composition.
parent: CompositionReference? = null The parent composition reference, if applicable. Default is null.
onCreated: () -> Unit = {} A function which will be executed only when the Composition is created.

compositionReference

@Composable fun compositionReference(): CompositionReference

An Effect to construct a CompositionReference at the current point of composition. This can be used to run a separate composition in the context of the current one, preserving ambients and propagating invalidations. When this call leaves the composition, the reference is invalidated.

emit

@Composable inline fun <T : Any, reified E : Applier<*>> emit(
    noinline ctor: () -> T,
    update: Updater<T>.() -> Unit
): Unit

Emits a node into the composition of type T.

This function will throw a runtime exception if E is not a subtype of the applier of the currentComposer.

import androidx.compose.compositionFor
import androidx.compose.emit
import androidx.compose.state

// Provided we have a tree with a node base type like the following
abstract class Node {
    val children = mutableListOf<Node>()
}

// We would implement an Applier class like the following, which would teach compose how to
// manage a tree of Nodes.
class NodeApplier(root: Node) : AbstractApplier<Node>(root) {
    override fun insert(index: Int, instance: Node) {
        current.children.add(index, instance)
    }

    override fun remove(index: Int, count: Int) {
        current.children.remove(index, count)
    }

    override fun move(from: Int, to: Int, count: Int) {
        current.children.move(from, to, count)
    }

    override fun onClear() {
        root.children.clear()
    }
}

// A function like the following could be created to create a composition provided a root Node.
fun Node.setContent(content: @Composable () -> Unit): Composition {
    return compositionFor(this, NodeApplier(this), Recomposer.current()).also {
        setContent(content)
    }
}

// assuming we have Node sub-classes like "TextNode" and "GroupNode"
class TextNode : Node() {
    var text: String = ""
    var onClick: () -> Unit = {}
}
class GroupNode : Node()

// Composable equivalents could be created
@Composable fun Text(text: String, onClick: () -> Unit = {}) {
    emit<TextNode, NodeApplier>(::TextNode) {
        set(text) { this.text = it }
        set(onClick) { this.onClick = it }
    }
}

@Composable fun Group(content: @Composable () -> Unit) {
    emit<GroupNode, NodeApplier>(::GroupNode, {}, content)
}

// and then a sample tree could be composed:
fun runApp(root: GroupNode) {
    root.setContent {
        var count by state { 0 }
        Group {
            Text("Count: $count")
            Text("Increment") { count++ }
        }
    }
}
Parameters
ctor: () -> T A function which will create a new instance of T. This function is NOT guaranteed to be called in place.
update: Updater<T>.() -> Unit A function to perform updates on the node. This will run every time emit is executed. This function is called in place and will be inlined.

emit

@Composable inline fun <T : Any, reified E : Applier<*>> emit(
    noinline ctor: () -> T,
    update: Updater<T>.() -> Unit,
    children: () -> Unit
): Unit

Emits a node into the composition of type T. Nodes emitted inside of children will become children of the emitted node.

This function will throw a runtime exception if E is not a subtype of the applier of the currentComposer.

import androidx.compose.compositionFor
import androidx.compose.emit
import androidx.compose.state

// Provided we have a tree with a node base type like the following
abstract class Node {
    val children = mutableListOf<Node>()
}

// We would implement an Applier class like the following, which would teach compose how to
// manage a tree of Nodes.
class NodeApplier(root: Node) : AbstractApplier<Node>(root) {
    override fun insert(index: Int, instance: Node) {
        current.children.add(index, instance)
    }

    override fun remove(index: Int, count: Int) {
        current.children.remove(index, count)
    }

    override fun move(from: Int, to: Int, count: Int) {
        current.children.move(from, to, count)
    }

    override fun onClear() {
        root.children.clear()
    }
}

// A function like the following could be created to create a composition provided a root Node.
fun Node.setContent(content: @Composable () -> Unit): Composition {
    return compositionFor(this, NodeApplier(this), Recomposer.current()).also {
        setContent(content)
    }
}

// assuming we have Node sub-classes like "TextNode" and "GroupNode"
class TextNode : Node() {
    var text: String = ""
    var onClick: () -> Unit = {}
}
class GroupNode : Node()

// Composable equivalents could be created
@Composable fun Text(text: String, onClick: () -> Unit = {}) {
    emit<TextNode, NodeApplier>(::TextNode) {
        set(text) { this.text = it }
        set(onClick) { this.onClick = it }
    }
}

@Composable fun Group(content: @Composable () -> Unit) {
    emit<GroupNode, NodeApplier>(::GroupNode, {}, content)
}

// and then a sample tree could be composed:
fun runApp(root: GroupNode) {
    root.setContent {
        var count by state { 0 }
        Group {
            Text("Count: $count")
            Text("Increment") { count++ }
        }
    }
}
Parameters
ctor: () -> T A function which will create a new instance of T. This function is NOT guaranteed to be called in place.
update: Updater<T>.() -> Unit A function to perform updates on the node. This will run every time emit is executed. This function is called in place and will be inlined.
children: () -> Unit the composable content that will emit the "children" of this node.

emptyContent

@Stable fun emptyContent(): () -> Unit

Represents empty content for a Composable function.

See orEmpty for handling nullable Composable lambdas using empty content.

escapeCompose

inline fun <T> escapeCompose(block: NullCompilationScope.() -> T): T

Deprecated.

isJoinedKey

fun isJoinedKey(key: Any?): Boolean

joinedKeyLeft

fun joinedKeyLeft(key: Any?): Any?

joinedKeyRight

fun joinedKeyRight(key: Any?): Any?

key

@Composable inline fun <T> key(
    vararg inputs: Any?,
    block: () -> T
): T

key is a utility composable that is used to "group" or "key" a block of execution inside of a composition. This is sometimes needed for correctness inside of control-flow that may cause a given composable invocation to execute more than once during composition.

The value for a key does not need to be globally unique, and needs only be unique amongst the invocations of key at that point in composition.

For instance, consider the following example:

import androidx.compose.key

for (user in users) {
    key(user.id) { UserPreview(user = user) }
}

for (user in users.filter { isAdmin }) {
    key(user.id) { Friend(friend = user) }
}

Even though there are users with the same id composed in both the top and the bottom loop, because they are different calls to key, there is no need to create compound keys.

The key must be unique for each element in the collection, however, or children and local state might be reused in unintended ways.

For instance, consider the following example:

import androidx.compose.key

for ((child, parent) in relationships) {
    key(parent.id) {
        User(user = child)
        User(user = parent)
    }
}
This example assumes that parent.id is a unique key for each item in the collection,but this is only true if it is fair to assume that a parent will only ever have a single child,which may not be the case. Instead, it may be more correct to do the following:
import androidx.compose.key

for ((child, parent) in relationships) {
    key(parent.id to child.id) {
        User(user = child)
        User(user = parent)
    }
}
A compound key can be created by passing in multiple arguments:
import androidx.compose.key
import androidx.compose.state

for (element in elements) {
    val selected by key(element.id, parentId) { state { false } }
    ListItem(item = element, selected = selected)
}
Parameters
vararg inputs: Any? The set of values to be used to create a compound key. These will be compared to their previous values using equals and hashCode
block: () -> T The composable children for this group.

keySourceInfoOf

actual fun keySourceInfoOf(key: Any): String?

launchInComposition

@Composable fun launchInComposition(block: suspend CompositionCoroutineScope.() -> Unit): Unit

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition. block will run in the apply scope of the composition's Recomposer, which is usually your UI's main thread.

block will be launched once when this call enters the composition; recomposition will not cause block to launch again. To re-launch a suspend function when inputs change, see the other overloads of launchInComposition that accept input value parameters.

launchInComposition

@Composable fun launchInComposition(
    key: Any?,
    block: suspend CompositionCoroutineScope.() -> Unit
): Unit

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition. If key has changed since the last recomposition, cancel the currently running block and launch again. block will run in the apply scope of the composition's Recomposer, which is usually your UI's main thread.

This function should not be used to (re-)launch ongoing tasks in response to callback events by way of storing callback data in MutableState passed to key. Instead, see rememberCoroutineScope to obtain a CoroutineScope that may be used to launch ongoing jobs scoped to the composition in response to event callbacks.

launchInComposition

@Composable fun launchInComposition(
    key1: Any?,
    key2: Any?,
    block: suspend CompositionCoroutineScope.() -> Unit
): Unit

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition. If key1 or key2 has changed since the last recomposition, cancel the currently running block and launch again. By default block will run in the apply scope of the composition's Recomposer, which is usually your UI's main thread.

This function should not be used to (re-)launch ongoing tasks in response to callback events by way of storing callback data in MutableState passed to key1 or key2. Instead, see rememberCoroutineScope to obtain a CoroutineScope that may be used to launch ongoing jobs scoped to the composition in response to event callbacks.

launchInComposition

@Composable fun launchInComposition(
    key1: Any?,
    key2: Any?,
    key3: Any?,
    block: suspend CompositionCoroutineScope.() -> Unit
): Unit

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition. If key1, key2 or key3 has changed since the last recomposition, cancel the currently running block and launch again. By default block will run in the apply scope of the composition's Recomposer, which is usually your UI's main thread.

This function should not be used to (re-)launch ongoing tasks in response to callback events by way of storing callback data in MutableState passed to key1, key2 or key3. Instead, see rememberCoroutineScope to obtain a CoroutineScope that may be used to launch ongoing jobs scoped to the composition in response to event callbacks.

launchInComposition

@Composable fun launchInComposition(
    vararg keys: Any?,
    block: suspend CompositionCoroutineScope.() -> Unit
): Unit

Launch a suspending side effect when this composition is committed and cancel it when launchInComposition leaves the composition. If keys have changed since the last recomposition, cancel the currently running block and launch again. By default block will run in the apply scope of the composition's Recomposer, which is usually your UI's main thread.

This function should not be used to (re-)launch ongoing tasks in response to callback events by way of storing callback data in MutableState passed to keys. Instead, see rememberCoroutineScope to obtain a CoroutineScope that may be used to launch ongoing jobs scoped to the composition in response to event callbacks.

mutableStateListOf

fun <T> mutableStateListOf(): SnapshotStateList<T>

Create a instance of MutableList that is observable and can be snapshot.

import androidx.compose.mutableStateListOf
import androidx.compose.state
import androidx.ui.foundation.Text
import androidx.ui.foundation.TextField
import androidx.ui.input.TextFieldValue
import androidx.ui.layout.Column
import androidx.ui.layout.Row
import androidx.ui.material.Button

@Composable
fun Names() {
    var name by state { TextFieldValue("user") }
    val names = mutableStateListOf<String>()

    Column {
        Row {
            TextField(
                value = name,
                onValueChange = { name = it }
            )
            Button(onClick = { names.add(name.text) }) {
                Text("Add")
            }
        }
        Text("Added names:")
        Column {
            for (addedName in names) {
                Text(addedName)
            }
        }
    }
}

mutableStateListOf

fun <T> mutableStateListOf(vararg elements: T): SnapshotStateList<T>

Create an instance of MutableList that is observable and can be snapshot.

mutableStateMapOf

fun <K, V> mutableStateMapOf(): SnapshotStateMap<K, V>

Create a instance of MutableSet<K, V> that is observable and can be snapshot.

import androidx.compose.mutableStateMapOf
import androidx.compose.state
import androidx.ui.foundation.Text
import androidx.ui.foundation.TextField
import androidx.ui.input.TextFieldValue
import androidx.ui.layout.Column
import androidx.ui.layout.Row
import androidx.ui.material.Button

@Composable
fun NamesAndAges() {
    var name by state { TextFieldValue("name") }
    var saying by state { TextFieldValue("saying") }
    val sayings = mutableStateMapOf(
        "Caesar" to "Et tu, Brute?",
        "Hamlet" to "To be or not to be",
        "Richard III" to "My kingdom for a horse"
    )

    Column {
        Row {
            TextField(
                value = name,
                onValueChange = { name = it }
            )
            TextField(
                value = saying,
                onValueChange = { saying = it }
            )
            Button(onClick = { sayings[name.text] = saying.text }) {
                Text("Add")
            }
            Button(onClick = { sayings.remove(name.text) }) {
                Text("Remove")
            }
        }
        Text("Sayings:")
        Column {
            for (entry in sayings) {
                Text("${entry.key} says '${entry.value}'")
            }
        }
    }
}

mutableStateMapOf

fun <K, V> mutableStateMapOf(vararg pairs: Pair<K, V>): SnapshotStateMap<K, V>

Create a instance of MutableMap<K, V> that is observable and can be snapshot.

mutableStateOf

fun <T> mutableStateOf(
    value: T,
    policy: SnapshotMutationPolicy<T> = referentialEqualityPolicy()
): MutableState<T>

Return a new MutableState initialized with the passed in value

The MutableState class is a single value holder whose reads and writes are observed by Compose. Additionally, writes to it are transacted as part of the Snapshot system. During composition, you will likely want to use the state and stateFor composables instead of this factory function.

Parameters
value: T the initial value for the MutableState
policy: SnapshotMutationPolicy<T> = referentialEqualityPolicy() a policy to controls how changes are handled in mutable snapshots.

neverEqualPolicy

fun <T> neverEqualPolicy(): SnapshotMutationPolicy<T>

A policy never treat values of a MutableState as equivalent.

Setting MutableState.value will always be considered a change. When applying a MutableSnapshot that changes the state will always conflict with other snapshots that change the same state.

onActive

@Composable fun onActive(callback: CommitScope.() -> Unit): Unit

An effect used to observe the lifecycle of the composition. The callback will execute once initially after the first composition is applied, and then will not fire again. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to be executed once whenever the effect leaves the composition

The onActive effect is essentially a convenience effect for onCommit(true) { ... }.

Parameters
callback: CommitScope.() -> Unit The lambda to execute when the composition commits for the first time and becomes active.

onCommit

@Composable inline fun onCommit(noinline callback: CommitScope.() -> Unit): Unit

The onCommit effect is a lifecycle effect that will execute callback every time the composition commits. It is useful for executing code in lock-step with composition that has side-effects. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to schedule code that cleans up the code in the callback.

Parameters
callback: CommitScope.() -> Unit The lambda to be executed when the effect is committed to the composition.

onCommit

@Composable fun <V1> onCommit(
    v1: V1,
    callback: CommitScope.() -> Unit
): Unit

The onCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed. It is useful for executing code in lock-step with composition that has side-effects that are based on the inputs. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to schedule code that cleans up the code in the callback.

Parameters
v1: V1 The input which will be compared across compositions to determine if callback will get executed.
callback: CommitScope.() -> Unit The lambda to be executed when the effect is committed to the composition.

onCommit

@Composable fun <V1, V2> onCommit(
    v1: V1,
    v2: V2,
    callback: CommitScope.() -> Unit
): Unit

The onCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed. It is useful for executing code in lock-step with composition that has side-effects that are based on the inputs. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to schedule code that cleans up the code in the callback.

Parameters
v1: V1 An input value which will be compared across compositions to determine if callback will get executed.
v2: V2 An input value which will be compared across compositions to determine if callback will get executed.
callback: CommitScope.() -> Unit The lambda to be executed when the effect is committed to the composition.

onCommit

@Composable fun onCommit(
    vararg inputs: Any?,
    callback: CommitScope.() -> Unit
): Unit

The onCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed. It is useful for executing code in lock-step with composition that has side-effects that are based on the inputs. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to schedule code that cleans up the code in the callback.

Parameters
vararg inputs: Any? A set of inputs which will be compared across compositions to determine if callback will get executed.
callback: CommitScope.() -> Unit The lambda to be executed when the effect is committed to the composition.

onDispose

@Composable fun onDispose(callback: () -> Unit): Unit

An effect used to schedule work to be done when the effect leaves the composition.

The onDispose effect is essentially a convenience effect for onPreCommit(true) { onDispose { ... } }.

Parameters
callback: () -> Unit The lambda to be executed when the effect leaves the composition.

onPreCommit

@Composable inline fun onPreCommit(noinline callback: CommitScope.() -> Unit): Unit

The onPreCommit effect is a lifecycle effect that will execute callback every time the composition commits, but before those changes have been reflected on the screen. It is useful for executing code that needs to update in response to a composition and it is critical that the previous results are never seen by the user. If it is not critical, onCommit is recommended instead. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to schedule code that cleans up the code in the callback.

Parameters
callback: CommitScope.() -> Unit The lambda to be executed when the effect is committed to the composition.

onPreCommit

@Composable fun <V1> onPreCommit(
    v1: V1,
    callback: CommitScope.() -> Unit
): Unit

The onPreCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed, but before those changes have been reflected on the screen. It is useful for executing code that needs to update in response to a composition and it is critical that the previous results are never seen by the user. If it is not critical, onCommit is recommended instead. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to schedule code that cleans up the code in the callback.

Parameters
v1: V1 The input which will be compared across compositions to determine if callback will get executed.
callback: CommitScope.() -> Unit The lambda to be executed when the effect is committed to the composition.

onPreCommit

@Composable fun <V1, V2> onPreCommit(
    v1: V1,
    v2: V2,
    callback: CommitScope.() -> Unit
): Unit

The onPreCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed, but before those changes have been reflected on the screen. It is useful for executing code that needs to update in response to a composition and it is critical that the previous results are never seen by the user. If it is not critical, onCommit is recommended instead. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to schedule code that cleans up the code in the callback.

Parameters
v1: V1 An input value which will be compared across compositions to determine if callback will get executed.
v2: V2 An input value which will be compared across compositions to determine if callback will get executed.
callback: CommitScope.() -> Unit The lambda to be executed when the effect is committed to the composition.

onPreCommit

@Composable fun onPreCommit(
    vararg inputs: Any?,
    callback: CommitScope.() -> Unit
): Unit

The onPreCommit effect is a lifecycle effect that will execute callback every time the inputs to the effect have changed, but before those changes have been reflected on the screen. It is useful for executing code that needs to update in response to a composition and it is critical that the previous results are never seen by the user. If it is not critical, onCommit is recommended instead. The callback will get executed with a receiver scope that has an onDispose method which can be used to schedule a callback to schedule code that cleans up the code in the callback.

Parameters
vararg inputs: Any? A set of inputs which will be compared across compositions to determine if callback will get executed.
callback: CommitScope.() -> Unit The lambda to be executed when the effect is committed to the composition.

referentialEqualityPolicy

fun <T> referentialEqualityPolicy(): SnapshotMutationPolicy<T>

A policy to treat values of a MutableState as equivalent if they are referentially (===) equal.

Setting MutableState.value to its current referentially (===) equal value is not considered a change. When applying a MutableSnapshot, if the snapshot changes the value to the equivalent value the parent snapshot has is not considered a conflict.

remember

@Composable inline fun <T> remember(calculation: () -> T): T

Remember the value produced by calculation. calculation will only be evaluated during the composition. Recomposition will always return the value produced by composition.

remember

@Composable inline fun <T, V1> remember(
    v1: V1,
    calculation: () -> T
): T

Remember the value returned by calculation if v1 is equal to the previous composition, otherwise produce and remember a new value by calling calculation.

remember

@Composable inline fun <T, V1, V2> remember(
    v1: V1,
    v2: V2,
    calculation: () -> T
): T

Remember the value returned by calculation if v1 and v2 are equal to the previous composition, otherwise produce and remember a new value by calling calculation.

remember

@Composable inline fun <T, V1, V2, V3> remember(
    v1: V1,
    v2: V2,
    v3: V3,
    calculation: () -> T
): T

Remember the value returned by calculation if v1, v2 and v3 are equal to the previous composition, otherwise produce and remember a new value by calling calculation.

remember

@Composable inline fun <V> remember(
    vararg inputs: Any?,
    block: () -> V
): V

Remember the value returned by block if all values of inputs are equal to the previous composition, otherwise produce and remember a new value by calling block.

rememberCoroutineScope

@Composable inline fun rememberCoroutineScope(getContext: () -> CoroutineContext = { EmptyCoroutineContext }): CoroutineScope

Return a CoroutineScope bound to this point in the composition using the optional CoroutineContext provided by getContext. getContext will only be called once and the same CoroutineScope instance will be returned across recompositions.

This scope will be cancelled when this call leaves the composition. The CoroutineContext returned by getContext may not contain a Job as this scope is considered to be a child of the composition.

The default dispatcher of this scope if one is not provided by the context returned by getContext will be the applying dispatcher of the composition's Recomposer.

Use this scope to launch jobs in response to callback events such as clicks or other user interaction where the response to that event needs to unfold over time and be cancelled if the composable managing that process leaves the composition. Jobs should never be launched into any coroutine scope as a side effect of composition itself. For scoped ongoing jobs initiated by composition, see launchInComposition.

This function will not throw if preconditions are not met, as composable functions do not yet fully support exceptions. Instead the returned scope's CoroutineScope.coroutineContext will contain a failed Job with the associated exception and will not be capable of launching child jobs.

resetSourceInfo

actual fun resetSourceInfo(): Unit

state

@Composable inline fun <T> state(
    policy: SnapshotMutationPolicy<T> = referentialEqualityPolicy(),
    init: () -> T
): MutableState<T>

A composable used to introduce a state value of type T into a composition.

This is useful when you have a value that you would like to locally mutate and use in the context of a composition. Since the returned MutableState instance implements snapshot changes to the MutableState.value property will be automatically tracked in composition and schedule a recompose.

The MutableState class can be used several different ways. For example, the most basic way is to store the returned state value into a local immutable variable, and then set the MutableState.value property on it.

import androidx.compose.state
import androidx.ui.foundation.Text
import androidx.ui.material.Button

val count = state { 0 }

Text(text = "You clicked ${count.value} times")
Button(onClick = { count.value++ }) {
    Text("Click me")
}
import androidx.compose.state
import androidx.ui.foundation.TextField
import androidx.ui.foundation.Text
import androidx.ui.input.TextFieldValue
import androidx.ui.material.Button

@Composable
fun LoginScreen() {
    var username by state { TextFieldValue("user") }
    var password by state { TextFieldValue("pass") }

    fun login() = Api.login(username.text, password.text)

    TextField(
        value = username,
        onValueChange = { username = it }
    )
    TextField(
        value = password,
        onValueChange = { password = it }
    )
    Button(onClick = { login() }) {
        Text("Login")
    }
}

In this example, LoginScreen is recomposed every time the username and password of the model updates, keeping the UI synchronized with the state.

Additionally, you can destructure the MutableState object into a value and a "setter" function.

import androidx.compose.state
import androidx.ui.foundation.Text
import androidx.ui.material.Button

val (count, setCount) = state { 0 }

Text(text = "You clicked $count times")
Button(onClick = { setCount(count + 1) }) {
    Text("Click me")
}
Finally, the MutableState instance can be used as a variable delegate to a local mutablevariable.
import androidx.compose.state
import androidx.ui.foundation.Text
import androidx.ui.material.Button

var count by state { 0 }

Text(text = "You clicked $count times")
Button(onClick = { count = count + 1 }) {
    Text("Click me")
}
Parameters
policy: SnapshotMutationPolicy<T> = referentialEqualityPolicy() a policy to control how changes are handled in mutable snapshots.
Return
An instance of MutableState that wraps the value.

stateFor

@Composable inline fun <T, V1> stateFor(
    v1: V1,
    init: () -> T
): MutableState<T>

An effect to introduce a state value of type T into a composition that will last as long as the input v1 does not change.

This is useful when you have a value that you would like to locally mutate and use in the context of a composition, and its value is scoped to another value and you want it to be reset every time the other value changes.

The returned MutableState instance implements snapshot so that changes to the MutableState.value property will be automatically tracked in composition and schedule a recompose.

import androidx.compose.onCommit
import androidx.compose.stateFor

@Composable
fun observeUser(userId: Int): User? {
    val user = stateFor<User?>(userId) { null }
    onCommit(userId) {
        val subscription = UserAPI.subscribeToUser(userId) {
            user.value = it
        }
        onDispose {
            subscription.unsubscribe()
        }
    }
    return user.value
}
Parameters
v1: V1 An input value that, when changed, will cause the state to reset and init to be rerun
init: () -> T A factory function to create the initial value of this state
Return
An instance of MutableState that wraps the value.

See Also

stateFor

@Composable inline fun <T, reified V1, reified V2> stateFor(
    v1: V1,
    v2: V2,
    init: () -> T
): MutableState<T>

An effect to introduce a state value of type T into a composition that will last as long as the inputs v1 and v2 do not change.

This is useful when you have a value that you would like to locally mutate and use in the context of a composition, and its value is scoped to another value and you want it to be reset every time the other value changes.

The returned MutableState instance implements snapshots such that changes to the MutableState.value property will be automatically tracked in composition and schedule a recompose.

Parameters
v1: V1 An input value that, when changed, will cause the state to reset and init to be rerun
v2: V2 An input value that, when changed, will cause the state to reset and init to be rerun
init: () -> T A factory function to create the initial value of this state
Return
An instance of MutableState that wraps the value.

See Also

stateFor

@Composable inline fun <T> stateFor(
    vararg inputs: Any?,
    init: () -> T
): MutableState<T>

An effect to introduce a state value of type T into a composition that will last as long as the inputs inputs do not change.

This is useful when you have a value that you would like to locally mutate and use in the context of a composition, and its value is scoped to another value and you want it to be reset every time the other value changes.

The returned MutableState instance implements snapshots so that changes to the MutableState.value property will be automatically tracked in composition and schedule a recompose.

Parameters
vararg inputs: Any? A set of inputs such that, when any of them have changed, will cause the state to reset and init to be rerun
init: () -> T A factory function to create the initial value of this state
Return
An instance of MutableState that wraps the value.

See Also

staticAmbientOf

fun <T> staticAmbientOf(defaultFactory: () -> T = null): ProvidableAmbient<T>

Create an ambient key that can be provided using Providers. Changing the value provided will cause the entire tree below Providers to be recomposed, disabling skipping of composable calls.

A static ambient should be only be used when the value provided is highly unlikely to change.

See Also

structuralEqualityPolicy

fun <T> structuralEqualityPolicy(): SnapshotMutationPolicy<T>

A policy to treat values of a MutableState as equivalent if they are structurally (==) equal.

Setting MutableState.value to its current structurally (==) equal value is not considered a change. When applying a MutableSnapshot, if the snapshot changes the value to the equivalent value the parent snapshot has is not considered a conflict.

withRunningRecomposer

suspend fun withRunningRecomposer(block: suspend CoroutineScope.(recomposer: Recomposer) -> Unit): Unit

Runs block with a new, active Recomposer applying changes in the calling CoroutineContext.

Top-level properties

NeverEqual

val NeverEqual: (Any?, Any?) -> Boolean

Deprecated.

Simple comparison callback that always returns false, for mutable objects that will be compared with the same reference.

In this case we cannot correctly compare for equality, and so we trust that something else correctly triggered a recomposition.

ReferentiallyEqual

val ReferentiallyEqual: (Any?, Any?) -> Boolean

Deprecated.

Simple comparison callback using referential === equality

StructurallyEqual

val StructurallyEqual: (Any?, Any?) -> Boolean

Deprecated.

Simple comparison callback using structural Any.equals equality

composer

val composer: Composer<*>

Deprecated.

This is here because outdated versions of the compose IDE plugin expect to find it. Without it, calls to remember are seen as errors, which breaks inference of state and more.

This API is no longer needed in any way by the compiler, but we still need this API to be here to support versions of Android Studio that are still looking for it. Without it, valid composable code will look broken in the IDE. Remove this after we have left some time to get all versions of Studio upgraded. TODO b/152059242

currentComposer

@Composable val currentComposer: Composer<*>

invalidate

@Composable val invalidate: () -> Unit

An Effect to get the nearest invalidation lambda to the current point of composition. This can be used to trigger an invalidation on the composition locally to cause a recompose.

Extension functions

awaitDispose

suspend fun CompositionCoroutineScope.awaitDispose(onDispose: () -> Unit = {}): Nothing

Suspends the current coroutine until the effect is disposed and the CompositionCoroutineScope is cancelled, and invokes onDispose before resuming. awaitDispose never resumes normally and will always throw either kotlinx.coroutines.CancellationException or the exception that failed the current kotlinx.coroutines.Job.

awaitFrameMillis

inline suspend fun <R> CompositionFrameClock.awaitFrameMillis(crossinline onFrame: (frameTimeMillis: Long) -> R): R

Deprecated.

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

frameTimeNanos should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame, not necessarily a direct, "now" value.

The time base of the value provided by awaitFrameNanos is implementation defined. Time values provided are monotonically increasing; after a call to awaitFrameNanos completes it must not provide the same value again for a subsequent call.

awaitFrameMillis

suspend fun CompositionFrameClock.awaitFrameMillis(): Long

Deprecated.

Suspends until a new frame is requested, returning the frame time in milliseconds. This value should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame, not necessarily a direct, "now" value.

The time base of the value returned by awaitFrameMillis is implementation defined. Time values returned are monotonically increasing; after a call to awaitFrameMillis returns it must not return the same value again for a subsequent call.

awaitFrameNanos

suspend fun CompositionFrameClock.awaitFrameNanos(): Long

Deprecated.

Suspends until a new frame is requested, returning the frame time in nanoseconds. This value should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame, not necessarily a direct, "now" value.

The time base of the value returned by awaitFrameNanos is implementation defined. Time values returned are monotonically increasing; after a call to awaitFrameNanos returns it must not return the same value again for a subsequent call.

collectAsState

@Composable fun <T : R, R> Flow<T>.collectAsState(
    initial: R,
    context: CoroutineContext = Dispatchers.Main
): State<R>

Collects values from this Flow and represents its latest value via State. Every time there would be new value posted into the Flow the returned State will be updated causing recomposition of every State.value usage.

import androidx.compose.collectAsState
import androidx.ui.foundation.Text

val value: String by flow.collectAsState("initial")
Text("Value is $value")
Parameters
context: CoroutineContext = Dispatchers.Main CoroutineContext to use for collecting.

collectAsState

@ExperimentalCoroutinesApi @Composable inline fun <T> StateFlow<T>.collectAsState(context: CoroutineContext = Dispatchers.Main): State<T>

Collects values from this StateFlow and represents its latest value via State. The StateFlow.value is used as an initial value. Every time there would be new value posted into the StateFlow the returned State will be updated causing recomposition of every State.value usage.

import androidx.compose.collectAsState
import androidx.ui.foundation.Text

val value: String by stateFlow.collectAsState()
Text("Value is $value")
Parameters
context: CoroutineContext = Dispatchers.Main CoroutineContext to use for collecting.

getValue

inline operator fun <T> State<T>.getValue(
    thisObj: Any?,
    property: KProperty<*>
): T

Permits property delegation of vals using by for State.

import androidx.ui.foundation.Text
import androidx.ui.layout.Row

// 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")
}

orEmpty

inline fun (() -> Unit).orEmpty(): () -> Unit
Return
this Composable if not null, else emptyContent.

setValue

inline operator fun <T> MutableState<T>.setValue(
    thisObj: Any?,
    property: KProperty<*>,
    value: T
): Unit

Permits property delegation of vars using by for MutableState.

import androidx.compose.state
import androidx.ui.foundation.Text
import androidx.ui.material.Button

var count by state { 0 }

Text(text = "You clicked $count times")
Button(onClick = { count = count + 1 }) {
    Text("Click me")
}

toMutableStateList

fun <T> Collection<T>.toMutableStateList(): SnapshotStateList<T>

Create an instance of MutableList from a collection that is observerable and can be snapshot.

toMutableStateMap

fun <K, V> Iterable<Pair<K, V>>.toMutableStateMap(): SnapshotStateMap<K, V>

Create an instance of MutableMap<K, V> from a collection of pairs that is observable and can be snapshot.

withFrameMillis

inline suspend fun <R> CompositionFrameClock.withFrameMillis(crossinline onFrame: (frameTimeMillis: Long) -> R): R

Deprecated.

Suspends until a new frame is requested, immediately invokes onFrame with the frame time in nanoseconds in the calling context of frame dispatch, then resumes with the result from onFrame.

frameTimeNanos should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame, not necessarily a direct, "now" value.

The time base of the value provided by CompositionFrameClock.withFrameMillis is implementation defined. Time values provided are monotonically increasing; after a call to CompositionFrameClock.withFrameMillis completes it must not provide the same value again for a subsequent call.