StyleAnimation
StyleAnimation is a runtime style animator for UIElement.
Use it when you want to animate style properties directly in code (for example on click, hover, or custom events), instead of relying only on passive transition.
Usage
UIElement.animation() automatically selects the current element as the animation target.
target.animation()
.duration(1f)
.ease(Eases.QUAD_IN_OUT)
.style(PropertyRegistry.TRANSFORM_2D, new Transform2D().scale(0.5f).translate(100f, 0))
.style(PropertyRegistry.OPACITY, 0f)
.onFinished(element -> {
target.animation()
.ease(Eases.QUART_IN_OUT)
.style(PropertyRegistry.TRANSFORM_2D, new Transform2D())
.style(PropertyRegistry.OPACITY, 1f)
.start();
})
.start();
target.animationDsl {
duration(1f)
ease(Eases.QUAD_IN_OUT)
style(PropertyRegistry.TRANSFORM_2D, Transform2D().scale(0.5f).translate(100f, 0f))
style(PropertyRegistry.OPACITY, 0f)
onFinished {
target.animationDsl {
ease(Eases.QUART_IN_OUT)
style(PropertyRegistry.TRANSFORM_2D, Transform2D())
style(PropertyRegistry.OPACITY, 1f)
}
}
}
Tips
Warning
StyleAnimation.start() only works when ModularUI is valid (non-null).
If you want an enter animation (play once when the element is mounted into a valid ModularUI), use the callback overload:
The callback is invoked immediately when ModularUI is already available, or once after UIEvents.MUI_CHANGED when it becomes available.
Kotlin DSL does not usually need extra start() handling:
animationDsl { ... }defaults tostart = true- animation execution is deferred until
ModularUIbecomes valid
Keyframes
style(property, frames...) supports keyframes by progress (0.0 -> 1.0).
Target Selection
For multi-target animation, create an animation from ModularUI and select by element or selector.
Lifecycle and Control
start() returns ISubscription.
Call unsubscribe() to stop/cancel the running animation subscription.
You can also configure:
duration(float)delay(float)ease(IEase)onInterpolate((runtime, element) -> ...)onFinished(element -> ...)origin(StyleOrigin)andanimationOrigin(StyleOrigin)for advanced style-origin control
API Reference
| Method | Returns | Description |
|---|---|---|
select(UIElement) |
StyleAnimation |
Adds one element target. |
select(String) |
StyleAnimation |
Selects targets by selector on current ModularUI. |
style(Property<T>, T) |
StyleAnimation |
Animates one property to a final value. |
style(Property<T>, FloatObjectPair...) |
StyleAnimation |
Animates one property with keyframes. |
lss(String, Object) |
StyleAnimation |
Sets target property by LSS property name and value string/object. |
duration(float) |
StyleAnimation |
Sets animation duration in seconds. |
delay(float) |
StyleAnimation |
Sets start delay in seconds. |
ease(IEase) |
StyleAnimation |
Sets easing function. |
onInterpolate(BiConsumer<AnimationRuntime, UIElement>) |
StyleAnimation |
Called every animation frame update. |
onFinished(Consumer<UIElement>) |
StyleAnimation |
Called when animation finishes per target/property completion flow. |
start() |
ISubscription |
Starts the animation. |