Thinking in Compose
Why Stack Overflow recommends it
Stack Overflow users link it when explaining Compose concepts like state hoisting, event handling, property-delegated state and list rendering, treating it as the conceptual reference behind the docs.
Recommended by 2 people across 2 different months, 2020 to 2024.
What it is
A 25-minute talk from the Android Developers channel's 11 Weeks of Android series, presented by Leland Richardson of the Jetpack Compose team. It explains the declarative, component-based mindset behind Compose, including how state, recomposition and events work in a Kotlin-first UI toolkit.
What people said
Recommends m.reiter · 2021-12 · Stack Overflow · on “Is it a good design to define all events in the entrance UI?”
This design pattern is called state hoisting, and is explained in the docs: [LINK] State hoisting in Compose is a pattern of moving state to a composable's caller to make a composable stateless. State that is hoisted this way has some important properties: Single source of truth: By moving state instead of duplicating it, we're ensuring there's only one source of truth. This helps avoid bugs. Encapsulated: Only stateful composables will be able to modify their state. It's completely internal. Shareable: Hoisted state can be shared with multiple composables. Say we wanted to name in a different composable, hoisting would allow us to do that. Interceptable: callers to the stateless composables
Recommends SnuKies · 2024-02 · Stack Overflow · on “How to replace multiple lambda () -> Unit in a composable in Jetpack compose android”
I see you drew inspiration from Thinking in Compose [this video] I believe the Event Sinker described by @Muraino is the proper way to handle events; You have an Event Sinker (the onEvent lambda) that that could even be passed along multiple Compose layers. You could also annotated with @Immutable your Events, if they are data classes and contain only val s. The EventSinker is an approach also used by Circuit [LINK] , an MVP library used for navigation, created by Slack. Now, if you want to get rid of even more parameters, I suggest moving them to an UiModel . I can't say for sure, but I believe you want to show a list of messages from an User. In this case, you could bundle all the data in a UiM
Cites Marcel Pater · 2020-09 · Stack Overflow · on “How to make an endless list in Jetpack Compose”
You could use LazyColumnFor like explained here [LINK] : @Composable fun LazyColumnForDemo() { LazyColumnFor(items = listOf( "A", "B", "C", "D" ) + ((0..100).map { it.toString() }), modifier = Modifier, itemContent = { item -> Log.d("COMPOSE", "This get rendered $item") when (item) { "A" -> { Text(text = item, style = TextStyle(fontSize = 80.sp)) } "B" -> { Button(onClick = {}) { Text(text = item, style = TextStyle(fontSize = 80.sp)) } } "C" -> { //Do Nothing } "D" -> { Text(text = item) } else -> { Text(text = item, style = TextStyle(fontSize = 80.sp)) } } }) } Explained by google here: [this video] 23:18
Cites Valeriy Katkov · 2021-01 · Stack Overflow · on “Type 'State<List<User>?>' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate”
To fix the error add the following imports: // for a 'val' variable import androidx.compose.runtime.getValue // for a `var` variable also add import androidx.compose.runtime.setValue // or just import androidx.compose.runtime.* To use a variable as a property delegate [LINK] you should provide getValue [LINK] operator function [LINK] for read-only val variables and getValue [LINK] and setValue [LINK] functions for var variables. To read more about how property delegates and state are combined in jetpack compose see Use remember to create internal state in a composable [LINK] documentation section. There's also an explanation [this video] in Thinking in Compose [this video] video.