@@ -90,11 +90,11 @@ public fun SparkButton(
90
90
Animatable (0.0f )
91
91
}
92
92
93
- val dotsSizeProgress = remember {
93
+ val largeDotSizeProgress = remember {
94
94
Animatable (0.0f )
95
95
}
96
96
97
- val dotsSizeProgress2 = remember {
97
+ val smallDotSizeProgress = remember {
98
98
Animatable (0.0f )
99
99
}
100
100
@@ -129,7 +129,7 @@ public fun SparkButton(
129
129
}
130
130
131
131
launch {
132
- dotsSizeProgress .animateTo(
132
+ largeDotSizeProgress .animateTo(
133
133
targetValue = 0f ,
134
134
animationSpec =
135
135
keyframes {
@@ -143,7 +143,7 @@ public fun SparkButton(
143
143
}
144
144
145
145
launch {
146
- dotsSizeProgress2 .animateTo(
146
+ smallDotSizeProgress .animateTo(
147
147
targetValue = 0f ,
148
148
animationSpec =
149
149
keyframes {
@@ -178,8 +178,7 @@ public fun SparkButton(
178
178
}
179
179
180
180
Box (
181
- modifier =
182
- modifier
181
+ modifier = modifier
183
182
.toggleable(
184
183
value = checked,
185
184
interactionSource = interactionSource,
@@ -196,15 +195,15 @@ public fun SparkButton(
196
195
if (enabled) {
197
196
1f
198
197
} else {
199
- disabledAlpha
198
+ DISABLED_ALPHA
200
199
}
201
200
)
202
201
.drawBehind {
203
202
val maxDotSize = this .size.maxDimension / 24
204
203
205
204
val maxOuterDotsRadius: Float = this .size.maxDimension * 1.5f
206
205
207
- val currentRadius1 : Float =
206
+ val outerDotsRadius : Float =
208
207
mapValueFromRangeToRange(
209
208
dotsRadiusProgress.value,
210
209
0.0f ,
@@ -213,7 +212,7 @@ public fun SparkButton(
213
212
maxOuterDotsRadius
214
213
)
215
214
216
- val currentRadius2 : Float =
215
+ val middleDotsRadius : Float =
217
216
mapValueFromRangeToRange(
218
217
dotsRadiusProgress.value,
219
218
0.0f ,
@@ -222,7 +221,7 @@ public fun SparkButton(
222
221
maxOuterDotsRadius / 8 * 7
223
222
)
224
223
225
- val currentRadius3 : Float =
224
+ val innerDotsRadius : Float =
226
225
mapValueFromRangeToRange(
227
226
dotsRadiusProgress.value,
228
227
0.0f ,
@@ -231,74 +230,71 @@ public fun SparkButton(
231
230
maxOuterDotsRadius / 4 * 3
232
231
)
233
232
234
- val dotColors =
235
- if (dotsRadiusProgress.value < 0.5f ) {
236
- val progress =
237
- mapValueFromRangeToRange(
238
- dotsRadiusProgress.value,
239
- 0.0f ,
240
- 0.5f ,
241
- 0.0f ,
242
- 1.0f
243
- )
244
- listOf (
245
- primaryColor.interpolate(primaryColorDark, progress),
246
- primaryColorDark.interpolate(secondaryColor, progress),
247
- secondaryColor.interpolate(secondaryColorDark, progress),
248
- secondaryColorDark.interpolate(primaryColor, progress)
249
- )
250
- } else {
251
- val progress =
252
- mapValueFromRangeToRange(
253
- dotsRadiusProgress.value,
254
- 0.5f ,
255
- 1.0f ,
256
- 0.0f ,
257
- 1.0f
258
- )
259
- listOf (
260
- primaryColorDark.interpolate(primaryColor, progress),
261
- secondaryColor.interpolate(primaryColorDark, progress),
262
- secondaryColorDark.interpolate(secondaryColor, progress),
263
- primaryColor.interpolate(secondaryColorDark, progress)
264
- )
265
- }
233
+ val dotColors = if (dotsRadiusProgress.value < 0.5f ) {
234
+ val progress = mapValueFromRangeToRange(
235
+ dotsRadiusProgress.value,
236
+ 0.0f ,
237
+ 0.5f ,
238
+ 0.0f ,
239
+ 1.0f
240
+ )
241
+ listOf (
242
+ primaryColor.interpolate(primaryColorDark, progress),
243
+ primaryColorDark.interpolate(secondaryColor, progress),
244
+ secondaryColor.interpolate(secondaryColorDark, progress),
245
+ secondaryColorDark.interpolate(primaryColor, progress)
246
+ )
247
+ } else {
248
+ val progress = mapValueFromRangeToRange(
249
+ dotsRadiusProgress.value,
250
+ 0.5f ,
251
+ 1.0f ,
252
+ 0.0f ,
253
+ 1.0f
254
+ )
255
+ listOf (
256
+ primaryColorDark.interpolate(primaryColor, progress),
257
+ secondaryColor.interpolate(primaryColorDark, progress),
258
+ secondaryColorDark.interpolate(secondaryColor, progress),
259
+ primaryColor.interpolate(secondaryColorDark, progress)
260
+ )
261
+ }
266
262
267
263
// outer Dots
268
264
for (i in 0 until DOT_COUNT ) {
269
265
val cX: Float =
270
- (center.x + currentRadius1 * cos(i * DOT_POSITION_ANGLE * PI / 180f )).toFloat()
266
+ (center.x + outerDotsRadius * cos(i * DOT_POSITION_ANGLE * PI / 180f )).toFloat()
271
267
val cY: Float =
272
- (center.y + currentRadius1 * sin(i * DOT_POSITION_ANGLE * PI / 180f )).toFloat()
268
+ (center.y + outerDotsRadius * sin(i * DOT_POSITION_ANGLE * PI / 180f )).toFloat()
273
269
drawCircle(
274
270
color = dotColors[i % dotColors.size],
275
- radius = dotsSizeProgress2 .value * maxDotSize,
271
+ radius = smallDotSizeProgress .value * maxDotSize,
276
272
center = Offset (cX, cY)
277
273
)
278
274
}
279
275
280
- // innerDots
276
+ // middle Dots (larger)
281
277
for (i in 0 until DOT_COUNT ) {
282
278
val cX: Float =
283
- (center.x + currentRadius2 * cos((i * DOT_POSITION_ANGLE - DOT_POSITION_ANGLE / 2f ) * PI / 180f )).toFloat()
279
+ (center.x + middleDotsRadius * cos((i * DOT_POSITION_ANGLE - DOT_POSITION_ANGLE / 2f ) * PI / 180f )).toFloat()
284
280
val cY: Float =
285
- (center.y + currentRadius2 * sin((i * DOT_POSITION_ANGLE - DOT_POSITION_ANGLE / 2f ) * PI / 180f )).toFloat()
281
+ (center.y + middleDotsRadius * sin((i * DOT_POSITION_ANGLE - DOT_POSITION_ANGLE / 2f ) * PI / 180f )).toFloat()
286
282
drawCircle(
287
283
color = dotColors[(i + 1 ) % dotColors.size],
288
- radius = dotsSizeProgress .value * 2 * maxDotSize,
284
+ radius = largeDotSizeProgress .value * 2 * maxDotSize,
289
285
center = Offset (cX, cY)
290
286
)
291
287
}
292
288
293
- // innerDots
289
+ // inner Dots
294
290
for (i in 0 until DOT_COUNT ) {
295
291
val cX: Float =
296
- (center.x + currentRadius3 * cos((i * DOT_POSITION_ANGLE ) * PI / 180f )).toFloat()
292
+ (center.x + innerDotsRadius * cos((i * DOT_POSITION_ANGLE ) * PI / 180f )).toFloat()
297
293
val cY: Float =
298
- (center.y + currentRadius3 * sin((i * DOT_POSITION_ANGLE ) * PI / 180f )).toFloat()
294
+ (center.y + innerDotsRadius * sin((i * DOT_POSITION_ANGLE ) * PI / 180f )).toFloat()
299
295
drawCircle(
300
296
color = dotColors[(i + 1 ) % dotColors.size],
301
- radius = dotsSizeProgress2 .value * maxDotSize,
297
+ radius = smallDotSizeProgress .value * maxDotSize,
302
298
center = Offset (cX, cY)
303
299
)
304
300
}
@@ -314,4 +310,4 @@ private const val DOT_POSITION_ANGLE: Float = 360f / DOT_COUNT
314
310
315
311
private val SlowOutFastInEasing = CubicBezierEasing (0.8f , 0.0f , 0.4f , 1.0f )
316
312
317
- private val disabledAlpha = 0.38f
313
+ private const val DISABLED_ALPHA = 0.38f
0 commit comments