animation/composition.go
Functions
func NewParallel
func NewParallel(items ...Startable) *ParallelBuilder {
anims := make([]animatable, len(items))
for i, item := range items {
anims[i] = item.buildAnimatable()
}
return &ParallelBuilder{
par: ¶llel{items: anims},
}
}
func NewSequence
NewSequence creates a composition that plays animations one after another.
Each animation starts only after the previous one completes.
The sequence is complete when all animations have finished.
Example:
animation.NewSequence(
animation.To(opacity, 1.0).Duration(200*time.Millisecond),
animation.To(scale, 1.0).Duration(300*time.Millisecond),
).Start(ctrl)
func NewSequence(items ...Startable) *SequenceBuilder {
anims := make([]animatable, len(items))
for i, item := range items {
anims[i] = item.buildAnimatable()
}
return &SequenceBuilder{
seq: &sequence{items: anims},
}
}
func OnDone
OnDone sets a callback invoked when the sequence completes.
func (b *SequenceBuilder) OnDone(fn func()) *SequenceBuilder {
b.seq.onDone = fn
return b
}
func OnDone
OnDone sets a callback invoked when all parallel animations complete.
func (b *ParallelBuilder) OnDone(fn func()) *ParallelBuilder {
b.par.onDone = fn
return b
}
func Start
Start registers the sequence with the controller.
func (b *SequenceBuilder) Start(ctrl *Controller) {
ctrl.addComposition(b.seq)
}
func Start
Start registers the parallel composition with the controller.
func (b *ParallelBuilder) Start(ctrl *Controller) {
ctrl.addComposition(b.par)
}
Structs
type SequenceBuilder struct
SequenceBuilder constructs a sequence composition.
type SequenceBuilder struct {
seq *sequence
}
type ParallelBuilder struct
ParallelBuilder constructs a parallel composition.
type ParallelBuilder struct {
par *parallel
}
Interfaces
type Startable interface
Startable is the interface for anything that can be built into an animatable.
Both AnimationBuilder and SpringBuilder satisfy this via their Build methods.
This interface is used by Sequence and Parallel to accept both types.
type Startable interface {
buildAnimatable() animatable
}
NewParallel creates a composition that plays animations simultaneously.
All animations start at the same time. The parallel composition is complete
when the longest animation finishes.
Example:
animation.NewParallel(
animation.To(opacity, 1.0).Duration(200*time.Millisecond),
animation.To(translateY, 0).Duration(300*time.Millisecond),
).Start(ctrl)