https://kotlinlang.org logo
#compose
Title
# compose
s

Stephen Vinouze

02/03/2022, 5:19 PM
Hello, is there a way to apply a rotation animation with an anchor point? So far, all modifiers I've found apply the rotation at the center. There is a
rotationMatrix
method where you can specify your anchor point but I don't think it's supported by Compose yet. Am I missing something?
r

romainguy

02/03/2022, 5:49 PM
I know there’s a way to specify the rotation pivot with a
TransformOrigin
that you give to a
Modifier.graphicsLayer()
👀 2
s

Stephen Vinouze

02/03/2022, 6:19 PM
That was it 🙂 I could shift the anchor point to the top center and apply and swing-like rotation animation
Copy code
val infiniteTransition = rememberInfiniteTransition()
val angle by infiniteTransition.animateFloat(
    initialValue = -10f,
    targetValue = 10f,
    animationSpec = infiniteRepeatable(
        animation = tween(),
        repeatMode = RepeatMode.Reverse,
    )
)
Modifier.graphicsLayer(
    transformOrigin = TransformOrigin(0.5f, 0f),
    rotationZ = angle,
)
Thanks @romainguy !
👍 7
👍🏻 1
👍🏽 1