Skip to content

Transitions ​

Transitions animate a property when it changes. They run once per change, unlike animations, which run continuously.

luau
const Transitions = PeanutUI.Transitions

Attaching a transition ​

Transitions go in the transitions table of a widget's props:

luau
PeanutUI.Frame {
    size = PeanutUI.Size(200, 200),
    transitions = {
        size = Transitions.Ease(0.5, "EaseOutBounce"),
        backgroundColor = Transitions.Ease(0.4, "EaseOut"),
    },
}

Now changing size or backgroundColor animates instead of snapping.

Ease ​

Transitions.Ease(duration, curve?) animates over a fixed duration using an easing curve:

luau
Transitions.Ease(0.3, "EaseOut")

The curve can be a named curve from Curves or a custom function:

luau
Transitions.Ease(0.3, function(t)
    return t * t
end)

See the Ease Curves reference for the full list of named curves.

EaseCubicBezier ​

Transitions.EaseCubicBezier(duration, x1, y1, x2, y2) uses a cubic bezier curve:

luau
Transitions.EaseCubicBezier(0.4, 0.25, 0.1, 0.25, 1)

Spring ​

Transitions.Spring(dampingRatio, frequency) uses spring physics:

luau
Transitions.Spring(0.5, 4)

Springs are good for natural-feeling motion that settles over time.

Per-modifier transitions ​

Modifiers accept their own transitions table:

luau
PeanutUI.Frame {
    size = PeanutUI.Size(200, 200),
    cornerRadius = {
        all = PeanutUI.Unit(12),
        transitions = { all = Transitions.Ease(0.3, "EaseOut") },
    },
}

Snapping ​

To set a property without animating, use snapProperty:

luau
widget.snapProperty("size", PeanutUI.Size(300, 300))

Transitions vs animations ​

TransitionsAnimations
RunsOnce per changeEvery frame
TriggerProperty changeAlways
Use forState changesContinuous motion