refactor: decoupling color, style and make some private in ProgressIndicator

This commit is contained in:
2023-11-30 13:13:07 +08:00
parent 90db05c28c
commit d76f266fdf

View File

@@ -111,8 +111,8 @@ fun CircularProgressIndicator(
min: Float = 0f, min: Float = 0f,
max: Float = 100f, max: Float = 100f,
indeterminate: Boolean = progress < min, indeterminate: Boolean = progress < min,
colors: ProgressIndicatorColors = ProgressIndicator.circularColors, colors: ProgressIndicatorColors = CircularProgressIndicator.colors,
style: CircularIndicatorStyle = ProgressIndicator.circularStyle style: CircularIndicatorStyle = CircularProgressIndicator.style
) { ) {
val diameter = style.radius * 2 val diameter = style.radius * 2
val stroke = with(LocalDensity.current) { Stroke(width = style.strokeWidth.toPx(), cap = style.strokeCap) } val stroke = with(LocalDensity.current) { Stroke(width = style.strokeWidth.toPx(), cap = style.strokeCap) }
@@ -195,8 +195,8 @@ fun LinearProgressIndicator(
min: Float = 0f, min: Float = 0f,
max: Float = 100f, max: Float = 100f,
indeterminate: Boolean = progress < min, indeterminate: Boolean = progress < min,
colors: ProgressIndicatorColors = ProgressIndicator.linearColors, colors: ProgressIndicatorColors = LinearProgressIndicator.colors,
style: LinearIndicatorStyle = ProgressIndicator.linearStyle style: LinearIndicatorStyle = LinearProgressIndicator.style
) { ) {
@Composable @Composable
fun Determinate() { fun Determinate() {
@@ -338,8 +338,8 @@ private fun DrawScope.drawLinearIndicator(
} }
} }
object ProgressIndicator { object CircularProgressIndicator {
val circularColors: ProgressIndicatorColors val colors: ProgressIndicatorColors
@Composable @Composable
@ReadOnlyComposable @ReadOnlyComposable
get() = LocalProgressIndicatorColors.current.copy( get() = LocalProgressIndicatorColors.current.copy(
@@ -348,7 +348,14 @@ object ProgressIndicator {
backgroundColor = LocalProgressIndicatorColors.current.backgroundColor.orElse() backgroundColor = LocalProgressIndicatorColors.current.backgroundColor.orElse()
?: defaultCircularIndicatorColors().backgroundColor ?: defaultCircularIndicatorColors().backgroundColor
) )
val linearColors: ProgressIndicatorColors val style: CircularIndicatorStyle
@Composable
@ReadOnlyComposable
get() = defaultCircularIndicatorStyle()
}
object LinearProgressIndicator {
val colors: ProgressIndicatorColors
@Composable @Composable
@ReadOnlyComposable @ReadOnlyComposable
get() = LocalProgressIndicatorColors.current.copy( get() = LocalProgressIndicatorColors.current.copy(
@@ -357,11 +364,7 @@ object ProgressIndicator {
backgroundColor = LocalProgressIndicatorColors.current.backgroundColor.orElse() backgroundColor = LocalProgressIndicatorColors.current.backgroundColor.orElse()
?: defaultLinearIndicatorColors().backgroundColor ?: defaultLinearIndicatorColors().backgroundColor
) )
val circularStyle: CircularIndicatorStyle val style: LinearIndicatorStyle
@Composable
@ReadOnlyComposable
get() = defaultCircularIndicatorStyle()
val linearStyle: LinearIndicatorStyle
@Composable @Composable
@ReadOnlyComposable @ReadOnlyComposable
get() = defaultLinearIndicatorStyle() get() = defaultLinearIndicatorStyle()
@@ -369,7 +372,7 @@ object ProgressIndicator {
internal val LocalProgressIndicatorColors = compositionLocalOf { DefaultProgressIndicatorColors } internal val LocalProgressIndicatorColors = compositionLocalOf { DefaultProgressIndicatorColors }
internal val DefaultProgressIndicatorColors = ProgressIndicatorColors(Color.Unspecified, Color.Unspecified) private val DefaultProgressIndicatorColors = ProgressIndicatorColors(Color.Unspecified, Color.Unspecified)
@Composable @Composable
@ReadOnlyComposable @ReadOnlyComposable