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

Component

A Component is a class variant of a Composable function.

Composer

Implementation of a composer for mutable tree.

ComposerUpdater

CompositionContext

Effect

The Effect class is really an opaque class that holds a block of executable code that is meant to be executed positionally in the context of a composition.

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.

Recomposer

SlotEditor

A gap buffer implementation of the composition slot space.

SlotReader

SlotTable

SlotWriter

State

The State class is an @Model class meant to wrap around a single value.

ThreadLocal

ViewAdapters

ViewComposer

ViewComposition

ViewValidator

Type-aliases

ViewUpdater

Annotations

Composable

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

EffectsDsl

Effects are positionally memoized which means that the "resolving" of them depends on execution order and the fact that the resolve happens inside of composition.

HiddenAttribute

Immutable

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.

StableMarker

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

UnionType

Top-level constants summary

const Int

const Int

Top-level functions summary

Unit
Key(@Pivotal key: Any?, children: () -> Unit)

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

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
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?>

Effect<T>
ambient(key: Ambient<T>)

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

Effect<CompositionReference>

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

Effect<T>
effectOf(block: Effect<T>.() -> T)

This is the public version of the Effect constructor.

T

actual Int
identityHashCode(instance: Any?)

Boolean

actual Boolean

Any?

Any?

Effect<T>
key(v1: V1, block: Effect<T>.() -> T)

The key effect is a primitive effect that allows for an effect to have a custom group key.

Effect<T>
key(v1: V1, v2: V2, block: Effect<T>.() -> T)

The key effect is a primitive effect that allows for an effect to have a custom group key.

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

The key effect is a primitive effect that allows for an effect to have a custom group key.

actual String?

Effect<T>
memo(calculation: () -> T)

An Effect that positionally memoizes the result of a computation.

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

An Effect that positionally memoizes the result of a computation.

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

An Effect that positionally memoizes the result of a computation.

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

An Effect that positionally memoizes the result of a computation.

Effect<T>
model(init: () -> T)

An effect to introduce a state value of type T into a composition.

Effect<T>
modelFor(v1: V1, init: () -> T)

An effect to introduce a state value of type T into a composition.

Effect<T>
modelFor(v1: V1, v2: V2, init: () -> T)

An effect to introduce a state value of type T into a composition.

Effect<T>
modelFor(vararg inputs: Any?, init: () -> T)

An effect to introduce a state value of type T into a composition.

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

An effect used to observe the lifecycle of the composition.

Effect<Unit>
onCommit(callback: CommitScope.() -> Unit)

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

Effect<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.

Effect<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.

Effect<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.

Effect<Unit>
onDispose(callback: () -> Unit)

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

Effect<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.

Effect<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.

Effect<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.

Effect<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.

Int

This is a special function which kotlin will inline into a number representing the source location of the caller.

Effect<State<T>>
state(init: () -> T)

An effect to introduce a state value of type T into a composition.

Effect<State<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.

Effect<State<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.

Effect<State<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.

actual 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.

Top-level properties summary

ViewComposition

Effect<() -> 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.

CompositionContext?
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.

CompositionContext?
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.

V
Composer<N>.remember(block: () -> V)

Remember the value produced by block.

V
Composer<N>.remember(p1: P1, block: () -> V)

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

V
Composer<N>.remember(p1: P1, p2: P2, block: () -> V)

Remember the value returned by block if p1 and p2 are equal to the previous composition, otherwise produce and remember a new value by calling block.

V
Composer<N>.remember(p1: P1, p2: P2, p3: P3, block: () -> V)

Remember the value returned by block if p1, p2 and p3 are equal to the previous composition, otherwise produce and remember a new value by calling block.

V
Composer<N>.remember(p1: P1, p2: P2, p3: P3, p4: P4, block: () -> V)

Remember the value returned by block if p1, p2, p3, p4 are equal to the previous composition, otherwise produce and remember a new value by calling block.

V
Composer<N>.remember(vararg args: Any?, block: () -> V)

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

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

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

For Effect
operator T

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

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

Key

@Composable fun Key(
    @Pivotal key: Any?,
    children: () -> Unit
): Unit

Key is a utility component 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
key: Any? The value used to identify this group. The value will be compared for equality using Any.equals and hashed using Any.hashCode.
children: () -> Unit The composable children for this group.

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

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.memo
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 = +memo { LoginState("user", "pass") }

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

ThreadLocal

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

ambient

@CheckResult("+") fun <T> ambient(key: Ambient<T>): Effect<T>

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

compositionReference

fun compositionReference(): Effect<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

fun <T> effectOf(block: Effect<T>.() -> T): Effect<T>

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.effectOf
import androidx.compose.onCommit
import androidx.compose.stateFor

fun observeUser(userId: Int) = effectOf<User?> {
    val user = +stateFor<User?>(userId) { null }
    +onCommit(userId) {
        val subscription = UserAPI.subscribeToUser(userId) {
            user.value = it
        }
        onDispose {
            subscription.unsubscribe()
        }
    }
    user.value
}
Parameters
block: Effect<T>.() -> 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

actual 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

@CheckResult("+") fun <T, V1> key(
    v1: V1,
    block: Effect<T>.() -> T
): Effect<T>

The key effect is a primitive effect that allows for an effect to have a custom group key. This allows for effects to be associated with data. If you are constructing effects based on data such as lists or collections, keys can be used to help Compose determine which effects should be removed or added. Any other effects can be created inside of the block of the key effect.

import androidx.compose.key
import androidx.compose.state

for (element in elements) {
    val selected by +key<State<Boolean>>(element.id) { +state { false } }
    ListItem(item = element, selected = selected)
}
Parameters
v1: V1 The value to use as the key. This will be compared to its previous value using Any.equals
block: Effect<T>.() -> T The block to execute other effects in

key

@CheckResult("+") fun <T, V1, V2> key(
    v1: V1,
    v2: V2,
    block: Effect<T>.() -> T
): Effect<T>

The key effect is a primitive effect that allows for an effect to have a custom group key. This allows for effects to be associated with data. If you are constructing effects based on data such as lists or collections, keys can be used to help Compose determine which effects should be removed or added. Any other effects can be created inside of the block of the key effect.

A compound key will be created from both v1 and v2.

import androidx.compose.key
import androidx.compose.state

for (element in elements) {
    val selected by +key<State<Boolean>>(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 Any.equals
v2: V2 The second value to use as a key. This will be compared to its previous value using Any.equals
block: Effect<T>.() -> T The block to execute other effects in

key

@CheckResult("+") fun <T> key(
    vararg inputs: Any?,
    block: Effect<T>.() -> T
): Effect<T>

The key effect is a primitive effect that allows for an effect to have a custom group key. This allows for effects to be associated with data. If you are constructing effects based on data such as lists or collections, keys can be used to help Compose determine which effects should be removed or added. Any other effects can be created inside of the block of the key effect.

import androidx.compose.key
import androidx.compose.state

for (element in elements) {
    val selected by +key<State<Boolean>>(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. This will be compared to its previous value using Any.equals
block: Effect<T>.() -> T The block to execute other effects in

keySourceInfoOf

actual fun keySourceInfoOf(key: Any): String?

memo

@CheckResult("+") fun <T> memo(calculation: () -> T): Effect<T>

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

@CheckResult("+") fun <T, V1> memo(
    v1: V1,
    calculation: () -> T
): Effect<T>

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

@CheckResult("+") fun <T, V1, V2> memo(
    v1: V1,
    v2: V2,
    calculation: () -> T
): Effect<T>

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

@CheckResult("+") fun <T> memo(
    vararg inputs: Any?,
    calculation: () -> T
): Effect<T>

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

model

@CheckResult("+") fun <T> model(init: () -> T): Effect<T>

An effect to introduce a state value of type T into a composition. The init lambda will be called only once to create the initial value, and then that instance will be used for the lifetime of the composition.

This is useful when you have a Model class that you would like to instantiate and use in the context of a composition. Since the returned.

Parameters
init: () -> T A lambda that creates the Model instance
Return
The Effect which resolves to the result of init cached across compositions

modelFor

@CheckResult("+") fun <T, V1> modelFor(
    v1: V1,
    init: () -> T
): Effect<T>

An effect to introduce a state value of type T into a composition. The init lambda will be called only once to create the initial value, and then that instance will be used as long as the input v1 has not changed.

This is useful when you have a Model class that you would like to instantiate and use in the context of a composition. Since the returned.

Parameters
v1: V1 An input value that, when changed, will cause the state to reset and init to be rerun
init: () -> T A lambda that creates the Model instance
Return
The Effect which resolves to the result of init cached across compositions

See Also

modelFor

@CheckResult("+") fun <T, V1, V2> modelFor(
    v1: V1,
    v2: V2,
    init: () -> T
): Effect<T>

An effect to introduce a state value of type T into a composition. The init lambda will be called only once to create the initial value, and then that instance will be used as long as the inputs v1 and v2 have not changed.

This is useful when you have a Model class that you would like to instantiate and use in the context of a composition. Since the returned.

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 lambda that creates the Model instance
Return
The Effect which resolves to the result of init cached across compositions

See Also

modelFor

@CheckResult("+") fun <T> modelFor(
    vararg inputs: Any?,
    init: () -> T
): Effect<T>

An effect to introduce a state value of type T into a composition. The init lambda will be called only once to create the initial value, and then that instance will be used as long as the the values of inputs have not changed.

This is useful when you have a Model class that you would like to instantiate and use in the context of a composition. Since the returned.

Parameters
vararg inputs: Any? A set of inputs such that, when any of them have changed, the state will reset and init will be rerun
init: () -> T A lambda that creates the Model instance
Return
The Effect which resolves to the result of init cached across compositions

See Also

onActive

@CheckResult("+") fun onActive(callback: CommitScope.() -> Unit): Effect<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

@CheckResult("+") fun onCommit(callback: CommitScope.() -> Unit): Effect<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

@CheckResult("+") fun <V1> onCommit(
    v1: V1,
    callback: CommitScope.() -> Unit
): Effect<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

@CheckResult("+") fun <V1, V2> onCommit(
    v1: V1,
    v2: V2,
    callback: CommitScope.() -> Unit
): Effect<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

@CheckResult("+") fun onCommit(
    vararg inputs: Any?,
    callback: CommitScope.() -> Unit
): Effect<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

@CheckResult("+") fun onDispose(callback: () -> Unit): Effect<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

@CheckResult("+") fun onPreCommit(callback: CommitScope.() -> Unit): Effect<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

@CheckResult("+") fun <V1> onPreCommit(
    v1: V1,
    callback: CommitScope.() -> Unit
): Effect<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

@CheckResult("+") fun <V1, V2> onPreCommit(
    v1: V1,
    v2: V2,
    callback: CommitScope.() -> Unit
): Effect<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

@CheckResult("+") fun onPreCommit(
    vararg inputs: Any?,
    callback: CommitScope.() -> Unit
): Effect<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.

sourceLocation

inline fun sourceLocation(): Int

This is a special function which kotlin will inline into a number representing the source location of the caller. At the moment, this is just hardcoded to a constant, but we will implement the source location inlining in the future. Until this happens, effects will be UNSAFE to use inside of conditional logic.

state

@CheckResult("+") fun <T> state(init: () -> T): Effect<State<T>>

An effect 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 State instance implements Model, changes to the State.value property will be automatically tracked in composition and schedule a recompose.

The State 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 State.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(text = "Click me", onClick = { count.value++ })
Additionally, you can destructure the State 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(text = "Click me", onClick = { setCount(count + 1) })
Finally, the State 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(text = "Click me", onClick = { count = count + 1 })
Parameters
init: () -> T A factory function to create the initial value of this state
Return
An Model instance of State that wraps the value.

stateFor

@CheckResult("+") fun <T, V1> stateFor(
    v1: V1,
    init: () -> T
): Effect<State<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 State instance implements Model so that changes to the State.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 State that wraps the value.

See Also

stateFor

@CheckResult("+") fun <T, V1, V2> stateFor(
    v1: V1,
    v2: V2,
    init: () -> T
): Effect<State<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 State instance implements Model so that changes to the State.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 State that wraps the value.

See Also

stateFor

@CheckResult("+") fun <T> stateFor(
    vararg inputs: Any?,
    init: () -> T
): Effect<State<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 State instance implements Model so that changes to the State.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 State that wraps the value.

See Also

synchronized

inline actual 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.

Top-level properties

composer

val composer: ViewComposition

invalidate

val invalidate: Effect<() -> 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 ViewComposition.registerAdapter(adapter: (parent: Any, child: Any) -> Any?): Boolean?

remember

fun <N, V> Composer<N>.remember(block: () -> V): V

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

remember

fun <N, V, P1> Composer<N>.remember(
    p1: P1,
    block: () -> V
): V

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

remember

fun <N, V, P1, P2> Composer<N>.remember(
    p1: P1,
    p2: P2,
    block: () -> V
): V

Remember the value returned by block if p1 and p2 are equal to the previous composition, otherwise produce and remember a new value by calling block.

remember

fun <N, V, P1, P2, P3> Composer<N>.remember(
    p1: P1,
    p2: P2,
    p3: P3,
    block: () -> V
): V

Remember the value returned by block if p1, p2 and p3 are equal to the previous composition, otherwise produce and remember a new value by calling block.

remember

fun <N, V, P1, P2, P3, P4> Composer<N>.remember(
    p1: P1,
    p2: P2,
    p3: P3,
    p4: P4,
    block: () -> V
): V

Remember the value returned by block if p1, p2, p3, p4 are equal to the previous composition, otherwise produce and remember a new value by calling block.

remember

fun <N, V> Composer<N>.remember(
    vararg args: Any?,
    block: () -> V
): V

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

runWithCurrent

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

setViewContent

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

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): CompositionContext?

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

unaryPlus

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

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.

Extension properties

context

actual val View.context: Context

parent

actual val View.parent: ViewParent