A basic compose question. If the inputs of a Composable are the same, it is skipped right? However, in my case:
@Composable fun Icons(
icons: List<IconState> = listOf(),
iconEventHandler: IconEventHandler? = null,
) {
icons.forEach { element ->
Icon(
iconState = element,
onClick = { iconEventHandler?.onClick(element) },
onDragStart = { offset -> iconEventHandler?.onDragStart(element, offset) },
onDrag = { offset -> iconEventHandler?.onDrag(element, offset) },
onDragEnd = { iconEventHandler?.onDragEnd(element) }
)
}
}
The icons states are the same, but the lambda's passed to the Icon composable have different hashcodes every time, and as such it rerenders. I guess it makes sense, because Kotlin can not determine structural equality of lambdas. However, this must be a common pitfall then? What could I do to improve the performance? Push the
iconEventHandler
insode the
Icon
composable?