1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.compose.runtime 18 19 /** 20 * [Composable] functions are the fundamental building blocks of an application built with Compose. 21 * 22 * [Composable] can be applied to a function or lambda to indicate that the function/lambda can be 23 * used as part of a composition to describe a transformation from application data into a tree or 24 * hierarchy. 25 * 26 * Annotating a function or expression with [Composable] changes the type of that function or 27 * expression. For example, [Composable] functions can only ever be called from within another 28 * [Composable] function. A useful mental model for [Composable] functions is that an implicit 29 * "composable context" is passed into a [Composable] function, and is done so implicitly when it is 30 * called from within another [Composable] function. This "context" can be used to store information 31 * from previous executions of the function that happened at the same logical point of the tree. 32 */ 33 @MustBeDocumented 34 @Retention(AnnotationRetention.BINARY) 35 @Target( 36 // function declarations 37 // @Composable fun Foo() { ... } 38 // lambda expressions 39 // val foo = @Composable { ... } 40 AnnotationTarget.FUNCTION, 41 42 // type declarations 43 // var foo: @Composable () -> Unit = { ... } 44 // parameter types 45 // foo: @Composable () -> Unit 46 AnnotationTarget.TYPE, 47 48 // composable types inside of type signatures 49 // foo: (@Composable () -> Unit) -> Unit 50 AnnotationTarget.TYPE_PARAMETER, 51 52 // composable property getters and setters 53 // val foo: Int @Composable get() { ... } 54 // var bar: Int 55 // @Composable get() { ... } 56 AnnotationTarget.PROPERTY_GETTER 57 ) 58 annotation class Composable 59