Closed brolicious12 closed 1 month ago
@brolicious12 maybe I'm wrong, but for me you passed directy windowIcon.value
to rememberVectorPainter and compose isn't "observing" changing of this value and this is fine. You should move val windowIcon = mutableStateOf(Icons.Filled.AccountBox)
to application {}
block:
fun main() = application {
val windowIcon = remember { mutableStateOf(Icons.Filled.AccountBox) }
Window(onCloseRequest = this::exitApplication,
icon = rememberVectorPainter(windowIcon.value)) {
Button(onClick = {
windowIcon.value = Icons.Filled.BrokenImage
}) {
Text("Change icon to BrokenImage")
}
}
}
thanks to this compose will know that you that it should be remember
ed and will perform recomposition after changing. Let me know if this helps you
@Kanialdo thanks for the effort but unfortunately it doesn't work with your example either
Please @brolicious12 did you try making windowIcon
a var
? (that is, var windowIcon
)
@AnonymousGeekDev val windowIcon
as far as I understand is itself just an object that holds the state (windowIcon.value
). I don't change the object, so it doesn't have to be var (although I tested it with var too, it doesn't work).
@brolicious12 Please did you try using delegation with the by
keyword? That is, val windowIcon by remember {
@AnonymousGeekDev I tried it but it didn't work either, I would be surprised if it worked that way and not the other way around without delegation
rememberVectorPainter fun always return the same instance, even argument changed. I use pre allocate icons. it'work ` var titleState = mutableStateOf("new") var iconIndex = mutableStateOf(1) fun main() = application {
var icons = listOf(rememberVectorPainter(Icons.Filled.AccountCircle), rememberVectorPainter(Icons.Filled.Call))
Window(onCloseRequest = this::exitApplication, icon = icons[iconIndex.value % icons.size], title = titleState.value) {
Button(onClick = {
iconIndex.value++
}) {
Text(titleState.value)
}
}
}`
@shenliuyang cool!
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
when I click the button in the example below, the icon is not changed. Am I doing something wrong or is it a bug?