Is `animate*AsState` somehow usable from Compose H...
# compose-web
n
Is
animate*AsState
somehow usable from Compose HTML? Thanks.
d
It is not. Animations in Compose HTML are done through CSS transitions (simpler) and/or keyframed animations (complex but powerful). https://developer.mozilla.org/en-US/docs/Web/CSS/transition https://developer.mozilla.org/en-US/docs/Web/CSS/animation You may be interested in my project Kobweb, which has built some support on top of these fundamental web concepts. https://github.com/varabyte/kobweb#animations Transition example from my blog site
βœ… 1
πŸ™ 1
r
I wouldn't say it is correct. You can use compose animations in compose html. I suppose you can use it in any compose based applicaton. I've tested a simple example in compose html and in my kilua framework (with
js
target). The only issue is probably the bundle size, but it doesn't seem to be very large addon (about 50KB).
n
@Robert Jaros which dependency have you used? simply
androidx.compose.animation:animation
? it does not seem to work in multiplatform projects 😐
r
It works for me.
Copy code
sourceSets {
        val jsMain by getting {
            dependencies {
                implementation(compose.html.core)
                implementation(compose.runtime)
                implementation(compose.animation)
            }
        }
    }
πŸ™ 1
βœ… 1
Copy code
kotlin.version=1.9.21
compose.version=1.5.11
πŸ‘πŸ» 1
Had to add
org.jetbrains.compose.experimental.jscanvas.enabled=true
πŸ‘πŸ» 1
And something like this:
Copy code
var enabled by mutableStateOf(true)
    val alpha: Float by animateFloatAsState(if (enabled) 1f else 0.1f, tween(1000))

            Div(attrs = {
                style {
                    width(400.px)
                    color(rgba(255, 0, 0, alpha))
                }
            }) {
                Text(info.value)
            }
πŸ‘πŸ» 1
d
Wow, that's Compose HTML? Interesting, thanks
I wonder what it needs
jscanvas
for?
r
There are some issues with dependencies. Compose animations depend on ui and skiko and probably some more advanced animations will not work with plain compose html.
Still even this one function (animateFloatAsState) is enough to make some nice effects, especially with the ability to use many different compose animation specs.
d
Yeah the compose animation APIs are really nice.