@@ -16,28 +16,61 @@ import kotlin.math.absoluteValue
1616
1717@Composable
1818fun rememberSharedAnimatableState (
19- animatableStates : List <AnimatableState >
19+ animatableStates : List <AnimatableState >,
20+ toTargetAnimationSpec : AnimationSpec <Float >? = null,
21+ toInitialAnimationSpec : AnimationSpec <Float >? = null,
2022): SharedAnimatableState {
2123 return remember {
2224 SharedAnimatableState (
23- animatableStates = animatableStates
25+ animatableStates = animatableStates,
26+ toTargetAnimationSpec = toTargetAnimationSpec,
27+ toInitialAnimationSpec = toInitialAnimationSpec
2428 )
2529 }
2630}
2731
2832data class SharedAnimatableState (
29- private val animatableStates : List <AnimatableState >
33+ private var animatableStates : List <AnimatableState >,
34+ private val toTargetAnimationSpec : AnimationSpec <Float >? = null ,
35+ private val toInitialAnimationSpec : AnimationSpec <Float >? = null ,
3036) {
37+ private val states by mutableStateOf(
38+ if (toTargetAnimationSpec != null && toInitialAnimationSpec != null ) {
39+ animatableStates.map {
40+ it.copy(
41+ toTargetAnimationSpec = toTargetAnimationSpec,
42+ toInitialAnimationSpec = toInitialAnimationSpec
43+ )
44+ }
45+ } else {
46+ if (toTargetAnimationSpec != null && toInitialAnimationSpec == null ) {
47+ animatableStates.map {
48+ it.copy(
49+ toTargetAnimationSpec = toTargetAnimationSpec
50+ )
51+ }
52+ } else if (toTargetAnimationSpec == null && toInitialAnimationSpec != null ) {
53+ animatableStates.map {
54+ it.copy(
55+ toTargetAnimationSpec = toTargetAnimationSpec
56+ )
57+ }
58+ } else {
59+ animatableStates
60+ }
61+ }
62+ )
63+
3164 fun getState (
3265 animatableStateTag : AnimatableStateTag ,
3366 index : Int
3467 ): AnimatableState ? {
35- val states = animatableStates .filter { it.animatableStateTag == animatableStateTag }
36- return states .getOrNull(index)
68+ val filteredStates = states .filter { it.animatableStateTag == animatableStateTag }
69+ return filteredStates .getOrNull(index)
3770 }
3871
3972 fun animate () {
40- animatableStates .forEach { it.animate() }
73+ states .forEach { it.animate() }
4174 }
4275
4376 fun animateToTarget () {
0 commit comments