I’m curious why this really small change results i...
# compose
z
I’m curious why this really small change results in my component recomposing each time the value changes This snippet recomposes every time the
hue
changes
Copy code
.progressSemantics(
                value = hue(),
                valueRange = 0f..360f,
                steps = 360
            )
This doesn’t and skips as expected
Copy code
.semantics {
                progressBarRangeInfo = ProgressBarRangeInfo(
                    current = hue(),
                    range = 0f..360f,
                    steps = 360
                )
            }
Looking at the source code of
progressSemantics
it’s almost exactly the same
Copy code
@Stable
fun Modifier.progressSemantics(
    value: Float,
    valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
    @IntRange(from = 0) steps: Int = 0,
): Modifier {
    // Older versions of Talkback will ignore nodes with range info which aren't focusable or
    // screen reader focusable. Setting this semantics as merging descendants will mark it as
    // screen reader focusable.
    return semantics(mergeDescendants = true) {
        progressBarRangeInfo = ProgressBarRangeInfo(value.coerceIn(valueRange), valueRange, steps)
    }
}
i
one is reading the value in composition (thus causing a composition, layout, and drawing pass), then passing it into the
semantics
block, and one is only reading it in the
semantics
block (which only updates the separate accessibility tree).
You might consider putting in a feature request for a
progressSemantics
overload that takes a lambda for the
value
, similar to how `Modifier.offset` does so that the value read is only done in the semantic scope. That seems like it would be a clear performance win
Filing a bug here will get it into the right triage process
z
I see, that makes sense. Good idea for a feature request, I’ll do that sometime soon