Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9e16ad
commit a6ccc4e
Showing
5 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/theapache64/composeanimationplayground/ui/composable/ChildSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.theapache64.composeanimationplayground.ui.composable | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun ChildSample( | ||
title: String, | ||
content: @Composable () -> Unit | ||
) { | ||
Text(text = title) | ||
Spacer(modifier = Modifier.height(4.dp)) | ||
content() | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/theapache64/composeanimationplayground/ui/composable/VerticalSpace.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.theapache64.composeanimationplayground.ui.composable | ||
|
||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun VerticalSpace() { | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 34 additions & 4 deletions
38
...composeanimationplayground/ui/screen/animation/animateproperty/AnimateFloatAsStateDemo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,54 @@ | ||
package com.theapache64.composeanimationplayground.ui.screen.animation.animateproperty | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.compose.animation.core.FastOutSlowInEasing | ||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.theapache64.composeanimationplayground.ui.composable.ChildSample | ||
import com.theapache64.composeanimationplayground.ui.composable.TeslaLogo | ||
|
||
|
||
@SuppressLint("UnrememberedMutableState") | ||
@Composable | ||
fun AnimateFloatAsStateDemo( | ||
isOn: Boolean | ||
isActive: Boolean | ||
) { | ||
val targetValue = if (isOn) 0f else 100f | ||
val animatedValue by animateFloatAsState(targetValue = targetValue) | ||
val targetValue = if (isActive) 0f else 100f | ||
|
||
Column { | ||
ChildSample(title = "Simple Usage") { | ||
SimpleUsage(targetValue) | ||
} | ||
|
||
ChildSample(title = "animationSpec usage") { | ||
AnimationSpecUsage(targetValue) | ||
} | ||
} | ||
} | ||
|
||
|
||
@Composable | ||
private fun SimpleUsage( | ||
targetValue: Float | ||
) { | ||
val animatedValue by animateFloatAsState(targetValue = targetValue) | ||
TeslaLogo( | ||
modifier = Modifier.padding(start = animatedValue.dp) | ||
) | ||
} | ||
|
||
@Composable | ||
private fun AnimationSpecUsage(targetValue: Float) { | ||
val animatedValue by animateFloatAsState( | ||
targetValue = targetValue, | ||
animationSpec = tween(1000, 1000, easing = FastOutSlowInEasing) | ||
) | ||
TeslaLogo( | ||
modifier = Modifier.padding(start = animatedValue.dp) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters