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

ComposableContract

@Target([AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.TYPE]) annotation class ComposableContract
androidx.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. This metadata can be used to generate more efficient code.

Caution: Use of this annotation means that the annotated declaration MUST comply with those contracts, or else the resulting code's behavior will be undefined.

Summary

Public constructors
<init>(restartable: Boolean = true, readonly: Boolean = false, tracked: Boolean = true, preventCapture: Boolean = false)

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.

Properties
Boolean

if true, this will prevent composable calls from happening inside of the function that it applies to.

Boolean

if true, no group will be generated around the body of the function it annotates .

Boolean

if false, this will prevent code from being generated which allow this function's execution to be skipped or restarted.

Boolean

if false, this will disable lambda optimizations such as tracking execution of composable function expressions or remembering a function expression value based on its capture variables.

Public constructors

<init>

ComposableContract(
    restartable: Boolean = true,
    readonly: Boolean = false,
    tracked: Boolean = true,
    preventCapture: Boolean = false)

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. This metadata can be used to generate more efficient code.

Caution: Use of this annotation means that the annotated declaration MUST comply with those contracts, or else the resulting code's behavior will be undefined.

Parameters
restartable: Boolean = true if false, this will prevent code from being generated which allow this function's execution to be skipped or restarted. This may be desirable for small functions which just directly call another composable function and have very little machinery in them directly.
readonly: Boolean = false if true, no group will be generated around the body of the function it annotates . This is not safe unless the body of the function only executes "read" operations on the passed in composer..
tracked: Boolean = true if false, this will disable lambda optimizations such as tracking execution of composable function expressions or remembering a function expression value based on its capture variables. This flag is only meaningful when applied to @Composable lambda expressions
preventCapture: Boolean = false if true, this will prevent composable calls from happening inside of the function that it applies to. This is usually applied to lambda parameters of inline functions that ought to be safely inlined but cannot safely have composable calls in them

Properties

preventCapture

val preventCapture: Boolean

if true, this will prevent composable calls from happening inside of the function that it applies to. This is usually applied to lambda parameters of inline functions that ought to be safely inlined but cannot safely have composable calls in them

readonly

val readonly: Boolean

if true, no group will be generated around the body of the function it annotates . This is not safe unless the body of the function only executes "read" operations on the passed in composer..

restartable

val restartable: Boolean

if false, this will prevent code from being generated which allow this function's execution to be skipped or restarted. This may be desirable for small functions which just directly call another composable function and have very little machinery in them directly.

tracked

val tracked: Boolean

if false, this will disable lambda optimizations such as tracking execution of composable function expressions or remembering a function expression value based on its capture variables. This flag is only meaningful when applied to @Composable lambda expressions