animation/orchestrate.go
Functions
func Chain
func Chain(animations ...Startable) *SequenceBuilder {
return NewSequence(animations...)
}
func Group
Group plays all animations in parallel.
Group is a convenience alias for [NewParallel] with a clearer name for
orchestration contexts. All animations start simultaneously and the
group completes when the longest animation finishes.
Example:
animation.Group(
animation.FadeIn(opacity, animation.DurationMedium2),
animation.ScaleIn(scale, animation.DurationMedium2),
).Start(ctrl)
func Group(animations ...Startable) *ParallelBuilder {
return NewParallel(animations...)
}
func OnDone
OnDone sets a callback invoked when all repetitions complete.
Not called for infinite repetitions.
func (b *RepeatingBuilder) OnDone(fn func()) *RepeatingBuilder {
b.rep.onDone = fn
return b
}
func RepeatForever
RepeatForever creates an animation that repeats indefinitely.
The animation factory is called fresh for each iteration.
Example:
animation.RepeatForever(
animation.To(pulse, 1.0).From(0.5).Duration(500*time.Millisecond).AutoReverse(),
).Start(ctrl)
func RepeatForever(anim Startable) *RepeatingBuilder {
return RepeatN(0, anim)
}
func RepeatN
RepeatN creates an animation that repeats the given animation exactly n times.
Pass n=0 for infinite repetition. The animation factory is called fresh for
each iteration, ensuring clean state.
Example:
// Pulse opacity 3 times
animation.RepeatN(3,
animation.To(opacity, 1.0).From(0.0).Duration(200*time.Millisecond).Ease(animation.Linear),
).Start(ctrl)
func RepeatN(n int, anim Startable) *RepeatingBuilder {
return &RepeatingBuilder{
rep: &repeating{
factory: anim,
maxCount: n,
},
}
}
func Reverse
Reverse wraps an animation to play with inverted time mapping.
This works by intercepting the easing and inverting the progress value.
For tween animations, it swaps the from/to values. For other types,
it wraps the animatable.
Example:
// Slide out to bottom (reverse of slide in from bottom)
animation.Reverse(
animation.SlideInFromBottom(translateY, 100, animation.DurationMedium2),
).Start(ctrl)
func Reverse(anim Startable) Startable {
return &reversedStartable{inner: anim}
}
func Stagger
Stagger creates a composition where each animation starts after a fixed
delay from the previous one's start time.
This is implemented as a parallel composition where each successive
animation has an additional delay added. All animations run concurrently
but with staggered start times.
Example:
// Each item fades in 50ms after the previous one starts
animation.Stagger(50*time.Millisecond,
animation.FadeIn(item1, animation.DurationMedium2),
animation.FadeIn(item2, animation.DurationMedium2),
animation.FadeIn(item3, animation.DurationMedium2),
).Start(ctrl)
func Stagger(delay time.Duration, animations ...Startable) *ParallelBuilder {
staggered := make([]Startable, len(animations))
for i, anim := range animations {
if i == 0 {
staggered[i] = anim
continue
}
staggered[i] = &delayedStartable{
inner: anim,
delay: time.Duration(i) * delay,
}
}
return NewParallel(staggered...)
}
func Start
Start registers the repeating animation with the controller.
func (b *RepeatingBuilder) Start(ctrl *Controller) {
ctrl.addComposition(b.rep)
}
func WithDelay
WithDelay wraps an animation builder with an initial delay before it starts.
This returns a new [AnimationBuilder] if the input is an [AnimationBuilder],
otherwise wraps the animation in a delayed orchestration wrapper.
Example:
animation.WithDelay(200*time.Millisecond,
animation.FadeIn(opacity, animation.DurationMedium2),
).Start(ctrl)
func WithDelay(delay time.Duration, anim Startable) Startable {
return &delayedStartable{
inner: anim,
delay: delay,
}
}
Structs
type RepeatingBuilder struct
RepeatingBuilder constructs a repeating animation.
type RepeatingBuilder struct {
rep *repeating
}
Chain creates a sequential composition that plays animations one after another.
Chain is a convenience alias for [NewSequence] with a clearer name for
orchestration contexts. Each animation starts only after the previous
one completes.
Example:
animation.Chain(
animation.FadeOut(oldOpacity, animation.DurationShort4),
animation.FadeIn(newOpacity, animation.DurationMedium2),
).Start(ctrl)