Hello, is there a way to apply a rotation animatio...
# compose
s
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
I know there’s a way to specify the rotation pivot with a
TransformOrigin
that you give to a
Modifier.graphicsLayer()
👀 2
s
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