Hello everyone, Does incorporating verticalScroll(...
# compose
v
Hello everyone, Does incorporating verticalScroll(rememberScrollState()) impact the recomposition count? should I need to be concerned about the recomposition count? In the case of a regular button, two recompositions occur for each click: one for the press and one for the release.
Copy code
Button(
    modifier = Modifier
        .height(100.dp)
        .width(300.dp)
        .padding(16.dp),
    onClick = {}
) {}
However, when you add verticalScroll(rememberScrollState()) to the button, only one recomposition happens for each click. Interestingly, if there is a delay between the press and release, one recomposition occurs for each (for a total of two recompositions). Why does this happen?
Copy code
Button(
    modifier = Modifier
        .height(100.dp)
        .width(300.dp)
        .padding(16.dp)
        .verticalScroll(rememberScrollState()),
    onClick = {}
) {}
l
This extra recomposition is happening because presses are delayed inside a scrollable container, in case the press is actually the start of scroll. When you release before the delay finishes naturally, we emit the press and release quickly which normally means in the same frame, so there will only be one recomposition. You can reproduce the same outside a scrollable container if your press is really fast But no, you don't need to worry about this explicitly, if you have performance concerns / issues you should benchmark and figure out if / what the problem is. Recompositions on their own like this aren't a problem
v
@Louis Pullen-Freilich [G] ahh got it. I’ve incorporated a clickable modifier into the Text element to get a ripple effect:
Copy code
Text(
    text = "Blah blah",
    modifier = Modifier
        .clickable(enabled = true, onClick = {})
)
However, it seems that the ripple effect is not causing recompositions. My understanding is that all UI changes should occur through recompositions. Is my understanding correct?
l
Not always, ripple doesn't require a recomposition as it only affects drawing, so it just causes a re-draw There's some more information here https://developer.android.com/jetpack/compose/phases#:~:text=Like%20most%20other%20UI%20toolkits,measure%2C%20layout%2C%20and%20drawing.
v
@Louis Pullen-Freilich [G] thanks 🙂