@@ -11,6 +11,7 @@ import androidx.compose.ui.unit.IntOffset
1111import androidx.compose.ui.unit.dp
1212import dev.bnorm.storyboard.StoryboardBuilder
1313import dev.bnorm.storyboard.easel.template.*
14+ import dev.bnorm.storyboard.easel.template.rememberAdvanceDirection
1415import dev.bnorm.storyboard.toState
1516import kotlin.math.roundToInt
1617
@@ -19,8 +20,11 @@ fun StoryboardBuilder.AnimationScene() = scene(
1920 enterTransition = enter(end = SceneEnter (alignment = Alignment .CenterEnd )),
2021 exitTransition = exit(end = SceneExit (alignment = Alignment .CenterEnd )),
2122) {
23+ fun <T > quick (): SpringSpec <T > = spring(stiffness = Spring .StiffnessVeryLow )
24+
2225 @OptIn(ExperimentalTransitionApi ::class )
2326 val state = frame.createChildTransition { it.toState() }
27+ val direction = rememberAdvanceDirection()
2428
2529 Column (verticalArrangement = Arrangement .spacedBy(16 .dp), modifier = Modifier .padding(16 .dp)) {
2630 Header { Text (" Animation" ) }
@@ -31,41 +35,35 @@ fun StoryboardBuilder.AnimationScene() = scene(
3135 val halfWidth = with (LocalDensity .current) { maxWidth.toPx().roundToInt() } / 2
3236 val halfHeight = with (LocalDensity .current) { maxWidth.toPx().roundToInt() } / 2
3337
38+
3439 state.AnimatedVisibility (
3540 visible = { it == 1 },
36- enter = enter(
37- start = { fadeIn(spring(stiffness = Spring .StiffnessVeryLow )) },
38- end = { fadeIn() },
39- ),
41+ enter = direction.enter(start = { fadeIn(quick()) }, end = { fadeIn() }),
4042 exit = fadeOut(),
4143 modifier = Modifier .align(Alignment .Center ),
4244 content = { Text (" Things can appear!" , style = MaterialTheme .typography.h4) },
4345 )
4446
47+ // TODO there seems to be a Compose bug where the first time it goes through the animation
48+ // it remembers it and won't change to the opposite direction.
49+ // - maybe not all of it though? only the direction it seems.
4550 state.AnimatedVisibility (
4651 visible = { it == 2 },
47- enter = enter(
48- start = {
49- slideInHorizontally(
50- spring(
51- stiffness = Spring .StiffnessVeryLow ,
52- visibilityThreshold = IntOffset .VisibilityThreshold ,
53- )
54- ) { - halfWidth - it / 2 }
55- },
52+ enter = fadeIn() + direction.enter(
53+ start = { slideInHorizontally(quick()) { - halfWidth - it / 2 } },
5654 end = { slideInHorizontally { halfWidth + it / 2 } },
57- ) + fadeIn() ,
58- exit = exit(
55+ ),
56+ exit = fadeOut() + direction. exit(
5957 start = { slideOutHorizontally { - halfWidth - it / 2 } },
6058 end = { slideOutHorizontally { halfWidth + it / 2 } },
61- ) + fadeOut() ,
59+ ),
6260 modifier = Modifier .align(Alignment .Center ),
6361 content = { Text (" Things can move!" , style = MaterialTheme .typography.h4) },
6462 )
6563
6664 state.AnimatedVisibility (
6765 visible = { it in 3 .. 5 },
68- enter = enter(
66+ enter = direction. enter(
6967 start = {
7068 slideInVertically(
7169 spring(
0 commit comments