Skip to content

Commit 279556e

Browse files
committed
library: Optimize ProgressIndicator Components
1 parent 27428fc commit 279556e

File tree

3 files changed

+160
-106
lines changed

3 files changed

+160
-106
lines changed

composeApp/src/commonMain/kotlin/component/OtherComponent.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package component
22

3+
import androidx.compose.animation.core.RepeatMode
4+
import androidx.compose.animation.core.animateFloat
5+
import androidx.compose.animation.core.infiniteRepeatable
6+
import androidx.compose.animation.core.rememberInfiniteTransition
7+
import androidx.compose.animation.core.tween
38
import androidx.compose.foundation.layout.Arrangement
49
import androidx.compose.foundation.layout.Column
510
import androidx.compose.foundation.layout.FlowRow
@@ -95,7 +100,15 @@ fun OtherComponent(padding: PaddingValues) {
95100
var text3 by remember { mutableStateOf("") }
96101
var progress by remember { mutableStateOf(0.5f) }
97102
var progressHaptic by remember { mutableStateOf(0.5f) }
98-
val progressValues = remember { listOf(0.1f, 0.3f, progress, 0.7f, 0.9f, null) }
103+
val animatedProgressValue by rememberInfiniteTransition().animateFloat(
104+
initialValue = 0f,
105+
targetValue = 1f,
106+
animationSpec = infiniteRepeatable(
107+
animation = tween(1000),
108+
repeatMode = RepeatMode.Reverse
109+
)
110+
)
111+
val progressValues = remember { listOf(0.0f, 0.25f, 0.5f, 0.75f, 1.0f, null) }
99112
val progressDisable by remember { mutableStateOf(0.5f) }
100113
val tabTexts = listOf("tab1", "tab2", "tab3", "tab4", "tab5", "tab6")
101114
var selectedTabIndex1 by remember { mutableStateOf(0) }
@@ -194,11 +207,17 @@ fun OtherComponent(padding: PaddingValues) {
194207
}
195208

196209
SmallTitle(text = "ProgressIndicator")
210+
LinearProgressIndicator(
211+
progress = animatedProgressValue,
212+
modifier = Modifier
213+
.padding(horizontal = 15.dp)
214+
.padding(bottom = 12.dp)
215+
)
197216
progressValues.forEach { progressValue ->
198217
LinearProgressIndicator(
199218
progress = progressValue,
200219
modifier = Modifier
201-
.padding(horizontal = 15.dp) // Increased from 12.dp because of StrokeCap.Round.
220+
.padding(horizontal = 15.dp) // Increased from 12.dp.
202221
.padding(bottom = 12.dp)
203222
)
204223
}
@@ -210,6 +229,9 @@ fun OtherComponent(padding: PaddingValues) {
210229
.padding(bottom = 6.dp),
211230
horizontalArrangement = Arrangement.SpaceEvenly,
212231
) {
232+
CircularProgressIndicator(
233+
progress = animatedProgressValue
234+
)
213235
progressValues.forEach { progressValue ->
214236
CircularProgressIndicator(
215237
progress = progressValue

0 commit comments

Comments
 (0)