https://kotlinlang.org logo
#compose
Title
# compose
b

blakelee

10/11/2020, 3:12 AM
I have a simple toggle that increment or decrements based on clicking + or -. The preview interaction doesn’t do anything but if I run it on device it works fine. Is there something that I’m missing in this example to make it work in the preview?
Copy code
@Preview
@Composable
fun Counter() {
    var count by remember { mutableStateOf(0) }
    Row {
        Image(vectorResource(R.drawable.ic_remove), Modifier.clickable { count-- })
        Text(text = count.toString(), modifier = Modifier.align(Alignment.CenterVertically))
        Image(vectorResource(R.drawable.ic_add), Modifier.clickable { count++ })
    }
}
g

gildor

10/11/2020, 4:22 AM
Maybe it fails because of vector resource?
b

blakelee

10/11/2020, 6:20 AM
I’ll take it out and give it a shot. EDIT: Even changing it to text it works in app but not the preview.
Invalidating cache fixed the issue. I guess it was a compose cache issue
👍 3