Raxol.Animation.Lifecycle (Raxol v2.0.1)

View Source

Manages the lifecycle of animations including starting, stopping, and completion handling.

This module is responsible for:

  • Starting animations on elements
  • Stopping animations
  • Handling animation completion and callbacks
  • Managing animation announcements and accessibility

Summary

Functions

Get the current value of an animation for a specific element.

Handle animation completion, including callbacks and notifications.

Stop an animation for a specific element.

Functions

get_current_value(animation_name, element_id)

Get the current value of an animation for a specific element.

Parameters

  • animation_name - The name of the animation
  • element_id - Identifier for the element

Returns

  • {:ok, value} - Current animation value
  • {:error, :animation_not_found} - Animation was not found

handle_animation_completion(animation, element_id, animation_name, instance, user_preferences_pid)

Handle animation completion, including callbacks and notifications.

This function is called when an animation completes, either naturally or due to being disabled.

start_animation(animation_name, element_id, opts \\ %{}, user_preferences_pid \\ nil)

Start an animation for a specific element.

Parameters

  • animation_name - The name of the animation to start
  • element_id - Identifier for the element being animated
  • opts - Additional options
  • user_preferences_pid - (Optional) The UserPreferences process pid or name for accessibility announcements

Options

  • :on_complete - Function to call when animation completes
  • :context - Additional context for the animation

Path Scoping

If the animation's target_path is a property (e.g., [:opacity]), the framework will automatically scope it to the element's state (e.g., [:elements, element_id, :opacity]). If you provide a fully qualified path, it will be used as-is.

Examples

iex> AnimationFramework.start_animation(:fade_in, "search_button", %{}, user_preferences_pid)
:ok

iex> AnimationFramework.start_animation(:slide_in, "panel", %{on_complete: &handle_complete/1}, user_preferences_pid)
:ok

stop_animation(animation_name, element_id)

Stop an animation for a specific element.

Parameters

  • animation_name - The name of the animation to stop
  • element_id - Identifier for the element

Returns

  • :ok - Animation was stopped successfully
  • {:error, :animation_not_found} - Animation was not found