ThemeAnimationState

class ThemeAnimationState(themeProvider: ThemeProvider, coroutineScope: CoroutineScope, animationSpec: AnimationSpec<Float>, format: ThemeAnimationFormat, useDynamicContent: Boolean)

A state holder that manages theme toggle animations.

This class provides internal state management for theme animations, including the current theme state, button position tracking, and recording coordination for smooth theme transitions. It is not recommended to use the class constructor directly. Use the rememberThemeAnimationState method instead.

Parameters

themeProvider

A ThemeProvider instance that provides the current theme and allows for theme updates. Typically, a data access object that saves the theme to a local or remote storage.

coroutineScope

The coroutine scope used for launching asynchronous operations, such as record request coordination.

animationSpec

The animation specification for theme transitions.

format

The format/style of the theme animation. See ThemeAnimationFormat for available styles.

useDynamicContent

Whether to capture and animate dynamic content during theme transitions. If set to true, the target content (that is, the theme

  • to which the theme is toggled) will be drawn dynamically and any changes to it, including scrolling,

  • animations etc. will be preserved. Note that the abandoned theme will still be drawn statically, which may lead to inconsistency

  • between the target and abandoned parts of the animation. Defaults to false.

Constructors

Link copied to clipboard
constructor(themeProvider: ThemeProvider, coroutineScope: CoroutineScope, animationSpec: AnimationSpec<Float>, format: ThemeAnimationFormat, useDynamicContent: Boolean)

Properties

Link copied to clipboard

The current theme being displayed in the UI.

Functions

Link copied to clipboard
fun toggleTheme(isSystemInDarkTheme: Boolean)

Toggles the current theme to its opposite value.

Link copied to clipboard

Updates the button position using screen coordinates.

fun updateButtonPosition(position: Rect)

Updates the button position using a rectangular bounds.