AnimatedToolkitIcon

fun AnimatedToolkitIcon(icon: ToolkitIcon, clickCount: Int, contentDescription: String?, modifier: Modifier = Modifier, selectedIcon: ToolkitIcon = icon, selected: Boolean = false, tint: Color = LocalContentColor.current)(source)

Renders the icon of a clickable component, mixing the unselected and selected icons with the click driven playback of animated sources.

Behavior, per icon combination:

  • Two static icons (vector, drawable resource, or bitmap): the icon is swapped on selection, nothing animates.

  • Static unselected icon + animated selected icon: the static icon is shown at rest; the first click swaps in the animated source and plays it forward, and every further click plays it again, so a repeatedly clicked action such as Share animates every single time.

  • A single animated icon used for both states: the artwork rests on its first frame while unselected and on its last frame while selected, and still replays on every click.

  • Animated unselected icon + static selected icon: the animation plays while the component is unselected, and the static icon takes over once it is selected.

A repeated click restarts the animation from its first frame by default. Drawables that morph between two distinct shapes can instead travel back by declaring ToolkitIconReplayMode.Reverse on the ToolkitIcon.AnimatedVector. They only travel back while the component is unselected: a selected one stays on its selected frame, so clicking a selected tab again never draws it unselected.

An icon that declares ToolkitIcon.Animated.loop opts out of all of this once its loop is running: it animates on its own for as long as it is composed, so clicks and selection no longer drive its playback. With ToolkitIconLoopTrigger.OnInteraction the loop only starts on the first click or selection, and until then the icon behaves like every other animated one.

Components without a selected state, such as buttons, pass only icon and clickCount.

Parameters

icon

Icon shown while the component is unselected.

clickCount

Number of clicks the component received while composed. Incrementing it replays the animation; components that are never selected rely on this alone. Owners that never animate can leave it at 0.

contentDescription

Accessibility description of the icon.

modifier

The Modifier to apply to the icon.

selectedIcon

Icon shown while the component is selected. Defaults to icon.

selected

Whether the component is currently selected. Defaults to false.

tint

Tint color to apply to the icon, defaults to LocalContentColor.