wasyl
10/21/2019, 10:49 PM@Model
into another @Composable
function? Something like:
@Composable
fun App() {
val appState = +memo {
ParentModel(
listOf(
ChildModel("Item 1", false),
ChildModel("Item 2", true)
)
)
}
Column {
appState.childModels.forEach { item ->
Item(item)
}
}
}
@Composable
fun Item(item: ChildModel) {
ListItem(
text = { Text(item.description) },
trailing = {
Checkbox(
checked = item.checked,
onCheckedChange = { item.checked = it })
}
)
}
@Model
data class ParentModel(
var childModels: List<ChildModel>
)
@Model
data class ChildModel(
var description: String,
var checked: Boolean
)
?Item
function and change it as wellGeorge Mount
10/21/2019, 11:11 PMModelList
instead listOf
. Try replacing listOf
with modelListOf
.wasyl
10/21/2019, 11:14 PM@Model
instance to a composable functions, changes to that model don’t trigger the recomposition. Specifically in fun Item(item: ChildModel)
I have onCheckedChange = { item.checked = it }
. I’d expect that part of subtree to be recreated, while it isn’tGeorge Mount
10/21/2019, 11:15 PM@Composable
fun ListItem(text: @Composable() () -> Unit, trailing: @Composable() () -> Unit) {
Row {
text()
trailing()
}
}
wasyl
10/21/2019, 11:37 PMsetContent { MaterialTheme { App() } }
in Activity’s onCreate
. I should be up to date too, a9891c6791
.
My ListItem
is androidx.ui.material.ListItemKt#ListItem
:ui:ui-*
dependencies to the module--rerun-tasks
to make sure it’s not some weird cache issue, and still doesn’t work 😕
I also synced the repo again, I’m on 8277cf7b6f
romainguy
10/21/2019, 11:57 PMstudiow
or gradle studio
right?wasyl
10/21/2019, 11:59 PM./gradlew studio
implementation(KOTLIN_COMPOSE_STDLIB)
~implementation(project(":ui:ui-android-view"))~
implementation project(":compose:compose-runtime")
implementation project(":ui:ui-core")
implementation project(":ui:ui-foundation")
~implementation project(":ui:ui-framework")~
implementation project(":ui:ui-animation")
implementation project(":ui:ui-layout")
implementation project(":ui:ui-text")
implementation project(':ui:ui-material')
@Composable
fun Item(item: ChildModel) {
val stubState = +state { 0 }
ListItem(
text = { Text("${item.description} [${stubState.value} changes]") },
trailing = { Checkbox(checked = item.checked, onCheckedChange = { }) },
onClick = {
item.checked = !item.checked
stubState.value++
}
)
}
With this I get different texts when I click on the items, but the checked state still doesn’t change. But when I debug the calls to Text(...
I can see that the model has an updated checked
valuedemos
project, so I didn’t have compose plugin applied 😞AndroidXUiPlugin
plugin, kotlinPlugin project(path: ":compose:compose-compiler", configuration: "embeddablePlugin")
dependency and useIR
option to Kotlin plugin and it works. I had a feeling it’s something with dependencies, didn’t realize it would be that obviousAndrey Kulikov
10/22/2019, 10:35 AMwasyl
10/22/2019, 10:44 AMLeland Richardson [G]
10/22/2019, 8:38 PMvoddan
10/28/2019, 8:45 AM@Model
with @Deprecated(error)
and then make your compiler plugin disable it 🤔Leland Richardson [G]
10/28/2019, 6:06 PM@ExperimentalFeature
flag. IIRC there were some issues with this, and the messages that would result in other versions of android studio/kotlin would be pretty hard to understand what to do, so we decided against it i guess