Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ebfada8

Browse files
fix easing sample
1 parent 3d29496 commit ebfada8

File tree

2 files changed

+23
-34
lines changed

2 files changed

+23
-34
lines changed

‎Tutorial1-1Basics/src/main/java/com/smarttoolfactory/tutorial1_1basics/chapter6_graphics/Tutorial6_39_1GraphicsLayer1.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -313,18 +313,6 @@ fun GraphicsLayerToParticles() {
313313
println("alive particle size: $aliveParticle, progress: $progress")
314314
}
315315
)
316-
// animatable.snapTo(1f)
317-
// graphicsLayer.toImageBitmap().let {
318-
// particleList.clear()
319-
// particleList.addAll(
320-
// createParticles(
321-
// imageBitmap = it.asAndroidBitmap()
322-
// .copy(Bitmap.Config.ARGB_8888, false)
323-
// .asImageBitmap(),
324-
// particleSize = particleSize.toInt()
325-
// )
326-
// )
327-
// }
328316
}
329317
}
330318
.size(widthDp)
@@ -456,4 +444,3 @@ fun createParticles(imageBitmap: ImageBitmap, particleSize: Int): List<TestParti
456444

457445
return particleList
458446
}
459-

‎Tutorial1-1Basics/src/main/java/com/smarttoolfactory/tutorial1_1basics/chapter9_animation/Easing.kt

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,11 @@ private fun Easingsample() {
8282

8383
val x = (width * currentTime / 1000f).coerceAtMost(1000f)
8484

85-
// val y = height * (1 - progress)
86-
val y = height * progress
85+
val y = height * (1 - progress)
8786

8887
(animatable.velocity as? Float)?.let {
8988
totalVelocity += it
9089
}
91-
println(
92-
"Time: $currentTime, progress: $progress, x: $x, y: $y, " +
93-
"velocity: ${animatable.velocity}, totalVelocity: $totalVelocity"
94-
)
9590

9691
if (path.isEmpty.not()) {
9792
path.lineTo(x, y)
@@ -117,7 +112,7 @@ private fun Easingsample() {
117112
targetValue = 1f,
118113
animationSpec = tween(
119114
durationMillis = 1000,
120-
easing = LinearEasing
115+
easing = LinearOutSlowInEasing
121116
)
122117
)
123118

@@ -131,14 +126,18 @@ private fun Easingsample() {
131126
}
132127
}
133128

129+
data class PathWithAnimatable(val path: Path, val animatable: Animatable<Float, AnimationVector1D>)
134130

135131
@Preview
136132
@Composable
137133
private fun EasingTest2() {
138134

139-
val animatableList = remember {
135+
val data = remember {
140136
List(5) {
141-
Animatable(0f)
137+
PathWithAnimatable(
138+
Path(),
139+
Animatable(0f)
140+
)
142141
}
143142
}
144143

@@ -151,17 +150,19 @@ private fun EasingTest2() {
151150
Column {
152151
Box(modifier = Modifier.fillMaxWidth().aspectRatio(1f)) {
153152

154-
animatableList.forEachIndexed { index, animatable ->
153+
data.forEachIndexed { index, data ->
155154
val color = when (index) {
156155
0 -> Color.Red
157-
1 -> Color.Yellow
156+
1 -> Color.Blue
158157
2 -> Color.Green
159158
3 -> Color.Magenta
160159
else -> Color.Black
161160
}
162161

163162
EasingTestBox(
164-
animatable = animatable,
163+
modifier = Modifier.padding(16.dp),
164+
animatable = data.animatable,
165+
path = data.path,
165166
color = color,
166167
startTime = startTime
167168
)
@@ -173,7 +174,7 @@ private fun EasingTest2() {
173174
onClick = {
174175

175176
startTime = System.currentTimeMillis()
176-
animatableList.forEachIndexed { index, animatable ->
177+
data.forEachIndexed { index, data ->
177178

178179
val animationSpec = when (index) {
179180
0 -> tween(
@@ -201,12 +202,16 @@ private fun EasingTest2() {
201202
else -> spring()
202203
}
203204
coroutineScope.launch {
205+
206+
val path = data.path
207+
path.reset()
208+
val animatable = data.animatable
209+
204210
animatable.snapTo(0f)
205211
animatable.animateTo(
206-
targetValue = 0f,
212+
targetValue = 1f,
207213
animationSpec = animationSpec
208214
)
209-
210215
}
211216
}
212217
}
@@ -220,17 +225,14 @@ private fun EasingTest2() {
220225

221226
@Composable
222227
private fun EasingTestBox(
228+
modifier: Modifier = Modifier,
229+
path: Path,
223230
animatable: Animatable<Float, AnimationVector1D>,
224231
startTime: Long,
225232
color: Color,
226233
) {
227-
228-
val path = remember {
229-
Path()
230-
}
231-
232234
Canvas(
233-
modifier = Modifier.fillMaxWidth().aspectRatio(1f).border(1.dp, Color.Blue)
235+
modifier = modifier.fillMaxWidth().aspectRatio(1f).border(1.dp, Color.Blue)
234236
) {
235237
val progress = animatable.value
236238
val width = size.width

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /