Jetpack Compose Basics | Android Developers
A composable function is a regular function annotated with @Composable
This enables your function to call other @Composable functions within it.
Most Compose UI elements such as Surface and Text accept an optional modifier parameter. Modifiers tell a UI element how to lay out, display, or behave within its parent layout.
For example, the padding modifier will apply an amount of space around the element it decorates. You can create a padding modifier with Modifier.padding().
The three basic standard layout elements in Compose are Column, Row and Box.
remember is used to guard against recomposition, so the state is not reset.
To preserve state across recompositions, remember the mutable state using remember.
However you can’t just assign mutableStateOf to a variable inside a composable. As explained before, recomposition can happen at any time which would call the composable again, resetting the state to a new mutable state
Note that if you call the same composable from different parts of the screen you will create different UI elements, each with its own version of the state. You can think of internal state as a private variable in a class.
The composable function will automatically be “subscribed” to the state. If the state changes, composables that read these fields will be recomposed to display the updates.
LazyColumn doesn’t recycle its children like RecyclerView. It emits new Composables as you scroll through it and is still performant, as emitting Composables is relatively cheap compared to instantiating Android Views.
Our app has a problem: if you run the app on a device, click on the buttons and then you rotate, the onboarding screen is shown again. The remember function works only as long as the composable is kept in the Composition. When you rotate, the whole activity is restarted so all state is lost. This also happens with any configuration change and on process death.
Instead of using remember you can use rememberSaveable. This will save each state surviving configuration changes (such as rotations) and process death.