Event callbacks
The DotLottieAnimation
instance emits the following events that can be listened to via a class implementing the Observer
protocol:
class YourDotLottieObserver: Observer { func onComplete() { // Animation completed }
func onFrame(frameNo: Float) { // New frame rendered }
func onLoad() { // Animation loaded successfully }
func onLoadError() { // Animation failed to load }
func onLoop(loopCount: UInt32) { // Animation completed a loop }
func onPause() { // Animation paused }
func onPlay() { // Animation started playing }
func onRender(frameNo: Float) { // Frame rendered }
func onStop() { // Animation stopped }}
// State Machine Observerclass YourStateMachineObserver: StateMachineObserver { func onStart() { // State machine started }
func onStop() { // State machine stopped }
func onTransition(previousState: String, newState: String) { // State machine transitioned from previousState to newState }
func onStateEntered(enteringState: String) { // Entered a new state }
func onStateExit(leavingState: String) { // Exited a state }
func onError(message: String) { // Error occurred in state machine }
func onCustomEvent(message: String) { // Custom event fired from state machine }
func onInputFired(inputName: String) { // Input was fired in state machine }
func onBooleanInputValueChange(inputName: String, oldValue: Bool, newValue: Bool) { // Boolean input value changed }
func onNumericInputValueChange(inputName: String, oldValue: Float, newValue: Float) { // Numeric input value changed }
func onStringInputValueChange(inputName: String, oldValue: String, newValue: String) { // String input value changed }}
// In your view codevar animation = DotLottieAnimation(...)var animationView = DotLottieView(dotLottie: animation)var myObserver = YourDotLottieObserver()var myStateMachineObserver = YourStateMachineObserver()
// Subscribe to animation eventsanimation.subscribe(observer: myObserver)
// Subscribe to state machine events (if using state machines)animation.stateMachineSubscribe(myStateMachineObserver)
State Machine Events
The StateMachineObserver
protocol provides the following callbacks:
Event | Description |
---|---|
onStart() | Called when state machine starts |
onStop() | Called when state machine stops |
onTransition(previousState: String, newState: String) | Called when transitioning between states |
onStateEntered(enteringState: String) | Called when entering a new state |
onStateExit(leavingState: String) | Called when exiting a state |
onError(message: String) | Called when an error occurs in the state machine |
onCustomEvent(message: String) | Called when a custom event is fired |
onInputFired(inputName: String) | Called when an input is fired |
onBooleanInputValueChange(inputName, oldValue, newValue) | Called when a boolean input value changes |
onNumericInputValueChange(inputName, oldValue, newValue) | Called when a numeric input value changes |
onStringInputValueChange(inputName, oldValue, newValue) | Called when a string input value changes |
Note: There’s also a
StateMachineInternalObserver
protocol used internally for handling URL opening events and other internal state machine messages. This is automatically handled by the framework and doesn’t require manual implementation.
Animation Observer Events
Event | Description |
---|---|
onComplete | Emitted when the animation completes. |
onFrame(frameNo: Float) | Emitted when the animation reaches a new frame. |
onLoad | Emitted when the animation is loaded. |
onLoadError | Emitted when the animation failed to load. |
onLoop(loopCount: UInt32) | Emitted when the animation completes a loop. |
onPause | Emitted when the animation is paused. |
onPlay | Emitted when the animation starts playing. |
onRender(frameNo: Float) | Emitted when the frame is rendered. |
onStop | Emitted when the animation is stopped. |