https://kotlinlang.org logo
Title
k

Kebbin

01/18/2022, 2:20 PM
Also, is there a way to combine pan and rotate animations? I'm using coroutines to
animatePanBy
and
animateRotateBy
, but one runs, then the other after the first has finished. So the object pans across, then rotates. I'd like the object to pan while it is rotating. Is this possible somehow? Thanks! Goodnight all.
z

Zach Klippenstein (he/him) [MOD]

01/18/2022, 4:28 PM
Are you starting the animations concurrently?
k

Kebbin

01/19/2022, 1:26 AM
Yes. Well, as I understand it anyway. Launching two coroutines, one after the other. I just thought they would then operate on the object concurrently, but maybe the way the functions are setup they maybe be "blocking" or something? I wondered if I needed to use something like a Transform. I'm sure I've seen in a tutorial, objects rotating and changing shape simultaneously. Thanks!
This is what I reverted to:
.onPointerEvent(PointerEventType.Press) {

                if (this.currentEvent.buttons.isSecondaryPressed) {
                    sendData("110 2")
                    coroutineScope.launch {
                    state.animatePanBy(Offset(x, y) - offsetXY)
                    state.animateRotateBy(0f - rotation)
                    }
                }
            }
This was what I tried, and expected it would have my desired simultaneous animations effect:
.onPointerEvent(PointerEventType.Press) {

                if (this.currentEvent.buttons.isSecondaryPressed) {
                    sendData("110 2")
                    coroutineScope.launch { state.animatePanBy(Offset(x, y) - offsetXY) }
                    coroutineScope.launch { state.animateRotateBy(0f - rotation) }
                    
                }
z

Zach Klippenstein (he/him) [MOD]

01/19/2022, 1:32 PM
The multiple-launch-calls is generally the correct approach for something like this. However, if
animatePanBy
and
animateRotateBy
are operating on the same state object then I would guess they might be doing some sort of internal synchronization to explicitly prevent this use case. If you stored offset and rotation in separate animated states, the concurrent coroutines should work as expected. I’m not sure what
state
is here and how those animate functions are implemented (they don’t look like they’re from the Compose stdlib) so I can’t say for sure.
k

Kebbin

01/19/2022, 2:02 PM
OK! Thanks for your thoughts! Might give me another line of testing. I'll try and cogitate what you mean by storing them in separate states, and see how I go.