androidx.compose

Classes

Ambient

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

Anchor

Applier

A helper class to apply changes to a tree with startNode types N given an apply adapter for type N

Composer

Implementation of a composer for mutable tree.

ComposerUpdater

Composition

A Composition is an object that is used to manage the UI created from a Composable from the top level.

Handler

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

Recomposer

SlotEditor

A gap buffer implementation of the composition slot space.

SlotReader

SlotTable

SlotWriter

ThreadLocal

ViewAdapters

ViewComposer

ViewValidator

Type-aliases

ViewUpdater

Annotations

CheckResult

Composable

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

Immutable

MainThread

Model

Model can be applied to a class which represents your application's data model, and will cause instances of the class to become observable, such that a read of a property of an instance of this class during the invocation of a composable function will cause that component to be "subscribed" to mutations of that instance.

Pivotal

Pivotal can be applied to the parameters of a composable to indicate that the parameter contributes to the "identity" of the composable.

Stable

StableMarker

StableMarker marks an annotation as indicating a type as having a stable equals comparision that can be used during composition.

TestOnly

UnionType

Top-level constants summary

const Int

const Int

Top-level functions summary

Unit
Observe(body: () -> Unit)

This component creates a scope which will be the root of recomposition for any reads or writes to Model classes that happen inside of it.

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

Providers binds values to ProvidableAmbient keys.

Unit
Recompose(body: (recompose: () -> Unit) -> Unit)

Recompose is a component which passes a "recompose" function to its children which, when invoked, will cause its children to recompose.

ThreadLocal<T?>

T
ambient(key: Ambient<T>)

An Effect used to get the value of an ambient at a specific position during composition.

ProvidableAmbient<T>
ambientOf(areEquivalent: (old: T, new: T) -> Boolean = ReferentiallyEqual, defaultFactory: () -> T = null)

Create an ambient key that can be provided using Providers.

CompositionReference

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

T
effectOf(block: () -> T)

This is the public version of the Effect constructor.

T

expect Int
identityHashCode(instance: Any?)

Boolean

actual Boolean

Any?

Any?

T
key(@Pivotal v1: V1, block: () -> T)

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

T
key(@Pivotal v1: V1, @Pivotal v2: V2, block: () -> T)

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

T
key(@Pivotal 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?

T
memo(calculation: () -> T)

An Effect that positionally memoizes the result of a computation.

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

An Effect that positionally memoizes the result of a computation.

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

An Effect that positionally memoizes the result of a computation.

T
memo(vararg inputs: Any?, calculation: () -> T)

An Effect that positionally memoizes the result of a computation.

MutableState<T>
mutableStateOf(value: T, areEquivalent: (old: T, new: T) -> Boolean = ReferentiallyEqual)

Return a new MutableState initialized with the passed in value

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

An effect used to observe the lifecycle of the composition.

Unit
onCommit(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(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.

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.

MutableState<T>
state(noinline areEquivalent: (old: T, new: T) -> Boolean = ReferentiallyEqual, 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.

expect R
synchronized(lock: Any, block: () -> R)

T
trace(sectionName: String, block: () -> T)

Wrap the specified block in calls to Trace.beginSection (with the supplied sectionName) and Trace.endSection.

operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Top-level properties summary

(Any?, Any?) -> Boolean

Simple comparison callback using referential === equality

(Any?, Any?) -> Boolean

Simple comparison callback using structural Any.equals equality

ViewComposer

Composer<*>

actual Composer<*>

() -> Unit

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

Extension functions summary

For android.app.Activity
Unit

Disposes of a composition that was started using setContent.

Composition?
Activity.setViewContent(composable: () -> Unit)

Sets the contentView of an activity to a FrameLayout, and composes the contents of the layout with the passed in composable.

For android.view.ViewGroup
Unit

Disposes of a composition of the children of this view.

Composition
ViewGroup.setViewContent(composable: () -> Unit)

Composes the children of the view with the passed in composable.

For Composer
T
Composer<N>.cache(valid: Boolean = true, block: () -> T)

Cache a value in the composition.

Any?

Get the next value of the slot table.

actual T
Composer<*>.runWithComposing(block: () -> T)

actual T
Composer<*>.runWithCurrent(block: () -> T)

For ViewComposer
Boolean?
ViewComposer.registerAdapter(adapter: (parent: Any, child: Any) -> Any?)

Extension properties summary

Top-level constants

DEFAULT_SLOT_ACTIONS_SIZE

const val DEFAULT_SLOT_ACTIONS_SIZE: Int
Value: 16

DEFAULT_SLOT_KEYS_SIZE

const val DEFAULT_SLOT_KEYS_SIZE: Int
Value: 8

Top-level functions

Observe

@Composable fun Observe(body: () -> Unit): Unit

This component creates a scope which will be the root of recomposition for any reads or writes to Model classes that happen inside of it. This can be used to improve performance in situations where you know that a specific Model object will need to change at high frequencies, and you want to reduce the burden of recomposition. It is recommended that you not introduce Observe into the composition until it is clear that is necessary to improve performance.

Parameters
body: () -> Unit The composable content to observe

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()
    }
}

Recompose

@Composable fun Recompose(body: (recompose: () -> Unit) -> Unit): Unit

Recompose is a component which passes a "recompose" function to its children which, when invoked, will cause its children to recompose. This is useful if you are updating local state and need to cause a recomposition manually.

In most cases we recommend using Model classes or state with immutable types in order to maintain local state inside of composables. For cases where this is impractical, Recompose can help you.

Example:

import androidx.compose.Recompose
import androidx.compose.remember
import androidx.ui.core.Text
import androidx.ui.core.TextField
import androidx.ui.material.Button

class LoginState(var username: String, var password: String) {
    fun login() = Api.login(username, password)
}

@Composable
fun LoginScreen() {
    val model = remember { LoginState("user", "pass") }

    Recompose { recompose ->
        TextField(
            value = model.username,
            onValueChange = {
                model.username = it
                recompose()
            }
        )
        TextField(
            value = model.password,
            onValueChange = {
                model.password = it
                recompose()
            }
        )
        Button(onClick = { model.login() }) {
            Text("Login")
        }
    }
}
Note: The above example can be done without Recompose by annotating LoginState with Model.

ThreadLocal

fun <T> ThreadLocal(): ThreadLocal<T?>

ambient

@Composable fun <T> ambient(key: Ambient<T>): T

Deprecated.

An Effect used to get the value of an ambient at a specific position during composition.

Parameters
key: Ambient<T> The Ambient that you want to consume the value of
Return
An Effect that resolves to the current value of the Ambient

See Also

ambientOf

fun <T> ambientOf(
    areEquivalent: (old: T, new: T) -> Boolean = ReferentiallyEqual,
    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.

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.

effectOf

@Composable fun <T> effectOf(block: () -> T): T

Deprecated.

This is the public version of the Effect constructor. It is meant to be used to compose effects together to create custom effects.

For example, a custom observeUser Effect might look something like this:

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
block: () -> T the executable block of code that returns the value of the effect, run in the context of the Effect

escapeCompose

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

identityHashCode

expect fun identityHashCode(instance: Any?): Int

isJoinedKey

fun isJoinedKey(key: Any?): Boolean

isMainThread

actual fun isMainThread(): Boolean

joinedKeyLeft

fun joinedKeyLeft(key: Any?): Any?

joinedKeyRight

fun joinedKeyRight(key: Any?): Any?

key

@Composable inline fun <T, V1> key(
    @Pivotal v1: V1,
    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)
    }
}
Parameters
v1: V1 The value used to identify this group. The value will be compared for equality using equals and hashed using hashCode.
block: () -> T The composable children for this group.

See Also

key

@Composable inline fun <T, V1, V2> key(
    @Pivotal v1: V1,
    @Pivotal v2: V2,
    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
v1: V1 The first value to use as a key. This will be compared to its previous value using equals
v2: V2 The second value to use as a key. This will be compared to its previous value using equals
block: () -> T The composable children for this group.

key

@Composable inline fun <T> key(
    @Pivotal 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)
    }
}
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
block: () -> T The composable children for this group.

keySourceInfoOf

actual fun keySourceInfoOf(key: Any): String?

memo

@Composable fun <T> memo(calculation: () -> T): T

Deprecated.

An Effect that positionally memoizes the result of a computation.

Parameters
calculation: () -> T A function to produce the result
Return
The result of the calculation, or the cached value from the composition

memo

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

Deprecated.

An Effect that positionally memoizes the result of a computation.

Parameters
v1: V1 An input to the memoization. If this value changes, the calculation will be re-executed.
calculation: () -> T A function to produce the result
Return
The result of the calculation, or the cached value from the composition

memo

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

Deprecated.

An Effect that positionally memoizes the result of a computation.

Parameters
v1: V1 An input to the memoization. If this value changes, the calculation will be re-executed.
v2: V2 An input to the memoization. If this value changes, the calculation will be re-executed.
calculation: () -> T A function to produce the result
Return
The result of the calculation, or the cached value from the composition

memo

@Composable fun <T> memo(
    vararg inputs: Any?,
    calculation: () -> T
): T

Deprecated.

An Effect that positionally memoizes the result of a computation.

Parameters
vararg inputs: Any? The inputs to the memoization. If any of these values change, the calculation will be re-executed.
calculation: () -> T A function to produce the result
Return
The result of the calculation, or the cached value from the composition

mutableStateOf

fun <T> mutableStateOf(
    value: T,
    areEquivalent: (old: T, new: T) -> Boolean = ReferentiallyEqual
): MutableState<T>

Return a new MutableState initialized with the passed in value

Parameters
value: T the initial value for the MutableState
areEquivalent: (old: T, new: T) -> Boolean = ReferentiallyEqual a callback to compare the previous and new instance of value when it is written to. If this returns true, then no recomposition will be scheduled. See ReferentiallyEqual and StructurallyEqual for simple implementations.

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 fun onCommit(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 fun onPreCommit(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.

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.

state

@Composable inline fun <T> state(
    noinline areEquivalent: (old: T, new: T) -> Boolean = ReferentiallyEqual,
    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 Model, 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.core.Text
import androidx.ui.material.Button

val count = state { 0 }

Text(text = "You clicked ${count.value} times")
Button(onClick = { count.value++ }) {
    Text("Click me")
}
Additionally, you can destructure the MutableState object into a value and a "setter" function.
import androidx.compose.state
import androidx.ui.core.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 mutable variable.
import androidx.compose.state
import androidx.ui.core.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
areEquivalent: (old: T, new: T) -> Boolean = ReferentiallyEqual a callback to compare the previous and new instance of T when MutableState.value is written to. If this returns true, then no recomposition will be scheduled. See ReferentiallyEqual and StructurallyEqual for simple implementations.
init: () -> T A factory function to create the initial value of this state
Return
An Model instance of MutableState that wraps the value.

See Also

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 Model so 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
init: () -> T A factory function to create the initial value of this state
Return
An Model 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 Model so 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 Model 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 Model 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 Model 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

synchronized

inline expect fun <R> synchronized(
    lock: Any,
    block: () -> R
): R

trace

inline fun <T> trace(
    sectionName: String,
    block: () -> T
): T

Wrap the specified block in calls to Trace.beginSection (with the supplied sectionName) and Trace.endSection.

unaryPlus

operator fun <T> T.unaryPlus(): T

Deprecated.

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached. At that time, the unaryPlus operator on the composer itself is the one that should be used.

Resolves the effect and returns the result.

Top-level properties

ReferentiallyEqual

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

Simple comparison callback using referential === equality

StructurallyEqual

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

Simple comparison callback using structural Any.equals equality

composer

val composer: ViewComposer

currentComposerIntrinsic

@Composable val currentComposerIntrinsic: Composer<*>

currentComposerNonNull

actual val currentComposerNonNull: 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

cache

inline fun <N, T> Composer<N>.cache(
    valid: Boolean = true,
    block: () -> T
): T

Cache a value in the composition. During initial composition block is called to produce the value that is then * stored in the slot table. During recomposition, if valid is true the value is obtained from the slot table and block is not invoked. If valid is false a new value is produced by calling block and the slot table is updated to contain the new value.

disposeComposition

fun Activity.disposeComposition(): Unit

Disposes of a composition that was started using setContent. This is a convenience method around Compose.disposeComposition.

disposeComposition

fun ViewGroup.disposeComposition(): Unit

Disposes of a composition of the children of this view. This is a convenience method around Compose.disposeComposition.

nextValue

fun <N> Composer<N>.nextValue(): Any?

Get the next value of the slot table. This will unwrap lifecycle observer holders to return lifecycle observer and should be used instead of Composer.nextSlot.

registerAdapter

fun ViewComposer.registerAdapter(adapter: (parent: Any, child: Any) -> Any?): Boolean?

runWithComposing

actual fun <T> Composer<*>.runWithComposing(block: () -> T): T

runWithCurrent

actual fun <T> Composer<*>.runWithCurrent(block: () -> T): T

setViewContent

fun Activity.setViewContent(composable: () -> Unit): Composition?

Sets the contentView of an activity to a FrameLayout, and composes the contents of the layout with the passed in composable. This is a convenience method around Compose.composeInto.

setViewContent

fun ViewGroup.setViewContent(composable: () -> Unit): Composition

Composes the children of the view with the passed in composable. This is a convenience method around Compose.composeInto.

Extension properties

context

actual val View.context: Context

parent

actual val View.parent: ViewParent