Minor indeterminate progress indicator optimization
Moving state reads inside the Canvas so new state values only cause redraw, and not recompose.
Test: n/a
Change-Id: I7de7208080a4691e690e8cc891c10256e91a1482
diff --git a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ProgressIndicator.kt b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ProgressIndicator.kt
index 8ad5a57..0be2779 100644
--- a/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ProgressIndicator.kt
+++ b/compose/material/material/src/commonMain/kotlin/androidx/compose/material/ProgressIndicator.kt
@@ -101,15 +101,15 @@
initState = 0,
toState = 1
)
- val firstLineHead = state[FirstLineHeadProp]
- val firstLineTail = state[FirstLineTailProp]
- val secondLineHead = state[SecondLineHeadProp]
- val secondLineTail = state[SecondLineTailProp]
Canvas(
modifier
.progressSemantics()
.preferredSize(LinearIndicatorWidth, LinearIndicatorHeight)
) {
+ val firstLineHead = state[FirstLineHeadProp]
+ val firstLineTail = state[FirstLineTailProp]
+ val secondLineHead = state[SecondLineHeadProp]
+ val secondLineTail = state[SecondLineTailProp]
val strokeWidth = ProgressIndicatorConstants.DefaultStrokeWidth.toPx()
drawLinearIndicatorBackground(backgroundColor, strokeWidth)
if (firstLineHead - firstLineTail > 0) {
@@ -213,25 +213,24 @@
initState = 0,
toState = 1
)
- val currentRotation = state[IterationProp]
- val baseRotation = state[BaseRotationProp]
-
- val currentRotationAngleOffset = (currentRotation * RotationAngleOffset) % 360f
-
- var startAngle = state[TailRotationProp]
- val endAngle = state[HeadRotationProp]
- // How long a line to draw using the start angle as a reference point
- val sweep = abs(endAngle - startAngle)
-
- // Offset by the constant offset and the per rotation offset
- startAngle += StartAngleOffset + currentRotationAngleOffset
- startAngle += baseRotation
-
Canvas(
modifier
.progressSemantics()
.preferredSize(CircularIndicatorDiameter)
) {
+ val currentRotation = state[IterationProp]
+ val baseRotation = state[BaseRotationProp]
+
+ val currentRotationAngleOffset = (currentRotation * RotationAngleOffset) % 360f
+
+ var startAngle = state[TailRotationProp]
+ val endAngle = state[HeadRotationProp]
+ // How long a line to draw using the start angle as a reference point
+ val sweep = abs(endAngle - startAngle)
+
+ // Offset by the constant offset and the per rotation offset
+ startAngle += StartAngleOffset + currentRotationAngleOffset
+ startAngle += baseRotation
drawIndeterminateCircularIndicator(startAngle, strokeWidth, sweep, color, stroke)
}
}