Last active
September 10, 2022 22:36
-
-
Save zsoltk/ed86882c60f8cb0d6a79c4b0dc2b8bfa to your computer and use it in GitHub Desktop.
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
class CardsTransitionHandler<T>( | |
private val transitionSpec: TransitionSpec<Cards.State, Float> = { | |
spring(stiffness = Spring.StiffnessVeryLow) | |
} | |
) : ModifierTransitionHandler<T, Cards.State>() { | |
private fun Cards.State.toProps() = | |
when (this) { | |
is Queued -> queued | |
is Bottom -> bottom | |
is Top -> top | |
is VoteLike -> voteLike | |
is VotePass -> votePass | |
} | |
override fun createModifier( | |
modifier: Modifier, | |
transition: Transition<Cards.State>, | |
descriptor: TransitionDescriptor<T, Cards.State> | |
): Modifier = modifier.composed { | |
val rotation = transition.animateFloat( | |
transitionSpec = transitionSpec, | |
targetValueByState = { it.toProps().rotation }) | |
val scale = transition.animateFloat( | |
transitionSpec = transitionSpec, | |
targetValueByState = { it.toProps().scale }) | |
val dpOffsetX = transition.animateFloat( | |
transitionSpec = transitionSpec, | |
targetValueByState = { it.toProps().offsetX.value }) | |
val zIndex = transition.animateFloat( | |
transitionSpec = transitionSpec, | |
targetValueByState = { it.toProps().zIndex }) | |
return@composed this | |
.offset { | |
IntOffset(x = (this.density * (dpOffsetX.value)).roundToInt(), y = 0) | |
} | |
.zIndex(zIndex.value) | |
.graphicsLayer( | |
rotationZ = rotation.value | |
) | |
.scale(scale.value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment