Greetings Friends :star2: Do you know what's the b...
# kilua
s
Greetings Friends 🌟 Do you know what's the best way to have animations in Kilua? I was wondering that I could try to port the Framer Motion JS library to be workable with Kilua but wasn't sure about its WASM compatibility, since I'm new to Kotlin/JS, I might need some beginner's guidance here.
r
You can easily use vanilla Motion with both JS and WasmJS targets.
An example:
implementation(npm("motion", "*"))
in
build.gradle.kts
A very simple wrapper:
Copy code
@JsModule("motion")
external object Motion : JsAny {
    fun animate(element: Element, keyframes: JsAny)
    fun animate(selector: String, keyframes: JsAny)
    fun animate(element: Element, keyframes: JsAny, options: JsAny)
    fun animate(selector: String, keyframes: JsAny, options: JsAny)
}
And animations can be used like this:
Copy code
div("box") {
    width(100.px)
    height(100.px)
    background(Background(color = Color.rgb(255, 0, 0)))
}
button("Animate background") {
    onClick {
        Motion.animate(".box", jsObjectOf("background" to "rgb(0, 255, 0)"))
    }
}

button("Start rotating") {
    onClick {
        Motion.animate(
            ".box",
            jsObjectOf("rotate" to 90),
            jsObjectOf(
                "type" to "spring",
                "stiffness" to 300,
                "repeat" to Int.MAX_VALUE,
                "repeatDelay" to 0.2
            )
        )
    }
}
s
This is great! Thanks for the tip Robert.. you're a Kotlin rockstar K
r
I've been also playing with compose animations. It works quite well but only when you enable and load skiko library, which is not really required. I've filled an issue almost a year ago https://youtrack.jetbrains.com/issue/CMP-4133
s
I was actually curious about this. Great thing that you already raised a ticket for this. I have dropped a comment as well, maybe it'd raise the issue a bit higher. It would be neat to be able to use Compose animation APIs without the bloat 👌
Because I see we already have access to APIs like
derivedStateOf
and
movableContentOf
that don't make a lot of sense unless we're actually animating and/or changing states very frequently.
m
So @Robert Jaros, compose animation can be used with Kilua if wasm is not targeted ??
r
Yes, at least some part of it. I haven't tested it much, just some basic
animate*AsState
calls with simple specs (at least tween and spring were working).
K 2
I don't really know compose animations, I've just watched this video

https://www.youtube.com/watch?v=HNSKJIQtb4câ–¾

and made some experiments with Kilua out of the curiosity.