Hi all, not sure if this is the right channel. Gi...
# compose
s
Hi all, not sure if this is the right channel. Given the following minimal code (not sure this is Android / Compose specific),
Copy code
class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            var clicksAmount by remember { mutableStateOf(0) }

            fun onItemClick(index: Int): () -> Unit = { repeat(index) { clicksAmount++ } }

            BasicText(text = "Clicks: $clicksAmount")
            LazyRow(
                contentPadding = PaddingValues(12.dp),
                content = { items(listOf(1, 2, 3)) { Example(it, onItemClick(it)) } }
            )
        }
    }
}

@Composable
fun Example(index: Int, onClick: () -> Unit) {
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier.padding(top = 12.dp).clickable { onClick() }
    ) {
        Image(painterResource(android.R.drawable.star_on), contentDescription = null)
        BasicText(text = index.toString())
    }
}
I get a huge build error when trying to build it. By the way, the combination of
by
(
var clicksAmount by
) and
++
(
clicksAmount++
) is the cause. For instance,
var clicksAmount = remember { ... }
or
clicksAmount += 1
builds just fine. Is this an issue? I tried to google but didn't find anything, probably missed the right keywords
🧵 3
j
That looks like a crash probably caused by the Compose Compiler. Please file a bug: https://issuetracker.google.com/issues?q=componentid:612128
👍 1