Skip to content

Commit 6867d47

Browse files
committed
better variable names in sparkbutton compose
1 parent 116fe62 commit 6867d47

File tree

1 file changed

+50
-54
lines changed
  • sparkbutton-compose/src/main/kotlin/at/connyduck/sparkbutton/compose

1 file changed

+50
-54
lines changed

sparkbutton-compose/src/main/kotlin/at/connyduck/sparkbutton/compose/SparkButton.kt

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ public fun SparkButton(
9090
Animatable(0.0f)
9191
}
9292

93-
val dotsSizeProgress = remember {
93+
val largeDotSizeProgress = remember {
9494
Animatable(0.0f)
9595
}
9696

97-
val dotsSizeProgress2 = remember {
97+
val smallDotSizeProgress = remember {
9898
Animatable(0.0f)
9999
}
100100

@@ -129,7 +129,7 @@ public fun SparkButton(
129129
}
130130

131131
launch {
132-
dotsSizeProgress.animateTo(
132+
largeDotSizeProgress.animateTo(
133133
targetValue = 0f,
134134
animationSpec =
135135
keyframes {
@@ -143,7 +143,7 @@ public fun SparkButton(
143143
}
144144

145145
launch {
146-
dotsSizeProgress2.animateTo(
146+
smallDotSizeProgress.animateTo(
147147
targetValue = 0f,
148148
animationSpec =
149149
keyframes {
@@ -178,8 +178,7 @@ public fun SparkButton(
178178
}
179179

180180
Box(
181-
modifier =
182-
modifier
181+
modifier = modifier
183182
.toggleable(
184183
value = checked,
185184
interactionSource = interactionSource,
@@ -196,15 +195,15 @@ public fun SparkButton(
196195
if (enabled) {
197196
1f
198197
} else {
199-
disabledAlpha
198+
DISABLED_ALPHA
200199
}
201200
)
202201
.drawBehind {
203202
val maxDotSize = this.size.maxDimension / 24
204203

205204
val maxOuterDotsRadius: Float = this.size.maxDimension * 1.5f
206205

207-
val currentRadius1: Float =
206+
val outerDotsRadius: Float =
208207
mapValueFromRangeToRange(
209208
dotsRadiusProgress.value,
210209
0.0f,
@@ -213,7 +212,7 @@ public fun SparkButton(
213212
maxOuterDotsRadius
214213
)
215214

216-
val currentRadius2: Float =
215+
val middleDotsRadius: Float =
217216
mapValueFromRangeToRange(
218217
dotsRadiusProgress.value,
219218
0.0f,
@@ -222,7 +221,7 @@ public fun SparkButton(
222221
maxOuterDotsRadius / 8 * 7
223222
)
224223

225-
val currentRadius3: Float =
224+
val innerDotsRadius: Float =
226225
mapValueFromRangeToRange(
227226
dotsRadiusProgress.value,
228227
0.0f,
@@ -231,74 +230,71 @@ public fun SparkButton(
231230
maxOuterDotsRadius / 4 * 3
232231
)
233232

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+
}
266262

267263
// outer Dots
268264
for (i in 0 until DOT_COUNT) {
269265
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()
271267
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()
273269
drawCircle(
274270
color = dotColors[i % dotColors.size],
275-
radius = dotsSizeProgress2.value * maxDotSize,
271+
radius = smallDotSizeProgress.value * maxDotSize,
276272
center = Offset(cX, cY)
277273
)
278274
}
279275

280-
// innerDots
276+
// middle Dots (larger)
281277
for (i in 0 until DOT_COUNT) {
282278
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()
284280
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()
286282
drawCircle(
287283
color = dotColors[(i + 1) % dotColors.size],
288-
radius = dotsSizeProgress.value * 2 * maxDotSize,
284+
radius = largeDotSizeProgress.value * 2 * maxDotSize,
289285
center = Offset(cX, cY)
290286
)
291287
}
292288

293-
// innerDots
289+
// inner Dots
294290
for (i in 0 until DOT_COUNT) {
295291
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()
297293
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()
299295
drawCircle(
300296
color = dotColors[(i + 1) % dotColors.size],
301-
radius = dotsSizeProgress2.value * maxDotSize,
297+
radius = smallDotSizeProgress.value * maxDotSize,
302298
center = Offset(cX, cY)
303299
)
304300
}
@@ -314,4 +310,4 @@ private const val DOT_POSITION_ANGLE: Float = 360f / DOT_COUNT
314310

315311
private val SlowOutFastInEasing = CubicBezierEasing(0.8f, 0.0f, 0.4f, 1.0f)
316312

317-
private val disabledAlpha = 0.38f
313+
private const val DISABLED_ALPHA = 0.38f

0 commit comments

Comments
 (0)