Package-level declarations

Types

Link copied to clipboard
class Animatable<T, V : AnimationVector>(initialValue: T, val typeConverter: TwoWayConverter<T, V>, visibilityThreshold: T? = null, val label: String = "Animatable")

Animatable is a value holder that automatically animates its value when the value is changed via animateTo. If animateTo is invoked during an ongoing value change animation, a new animation will transition Animatable from its current value (i.e. value at the point of interruption) to the new targetValue. This ensures that the value change is always continuous using animateTo. If a spring animation (e.g. default animation) is used with animateTo, the velocity change will guarantee to be continuous as well.

Link copied to clipboard

This interface provides a convenient way to query from an com.jakewharton.mosaic.animation.VectorizedAnimationSpec or com.jakewharton.mosaic.animation.FloatDecayAnimationSpec: It spares the need to pass the starting conditions and in some cases ending condition for each value or velocity query, and instead only requires the play time to be passed for such queries.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class AnimationResult<T, V : AnimationVector>(val endState: AnimationState<T, V>, val endReason: AnimationEndReason)

AnimationResult contains information about an animation at the end of the animation. endState captures the value/velocity/frame time, etc of the animation at its last frame. It can be useful for starting another animation to continue the velocity from the previously interrupted animation. endReason describes why the animation ended, it could be either of the following:

Link copied to clipboard

AnimationScope provides all the animation related info specific to an animation run. An AnimationScope will be accessible during an animation.

Link copied to clipboard
interface AnimationSpec<T>

AnimationSpec stores the specification of an animation, including 1) the data type to be animated, and 2) the animation configuration (i.e. VectorizedAnimationSpec) that will be used once the data (of type T) has been converted to AnimationVector.

Link copied to clipboard
class AnimationState<T, V : AnimationVector>(val typeConverter: TwoWayConverter<T, V>, initialValue: T, initialVelocityVector: V? = null, lastFrameTimeNanos: Long = AnimationConstants.UnspecifiedTime, finishedTimeNanos: Long = AnimationConstants.UnspecifiedTime, isRunning: Boolean = false) : State<T>

AnimationState contains the necessary information to indicate the state of an animation. Once an AnimationState is constructed, it can only be updated/mutated by animations. If there's a need to mutate some of the fields of an AnimationState, consider using copy functions.

Link copied to clipboard
sealed class AnimationVector

AnimationVector class that is the base class of AnimationVector1D, AnimationVector2D, AnimationVector3D and AnimationVector4D. In order to animate any arbitrary type, it is required to provide a TwoWayConverter that defines how to convert that arbitrary type T to an AnimationVector, and vice versa. Depending on how many dimensions this type T has, it may need to be converted to any of the subclasses of AnimationVector. For example, a position based object should be converted to AnimationVector2D, whereas an object that describes rectangle bounds should convert to AnimationVector4D.

Link copied to clipboard

This class defines a 1D vector. It contains only one Float value that is initialized in the constructor.

Link copied to clipboard

This class defines a 2D vector that contains two Float values for the two dimensions.

Link copied to clipboard

This class defines a 3D vector that contains three Float value fields for the three dimensions.

Link copied to clipboard

This class defines a 4D vector that contains four Float fields for its four dimensions.

Link copied to clipboard
@Immutable
class ArcAnimationSpec<T>(val mode: ArcMode = ArcBelow, val durationMillis: Int = AnimationConstants.DefaultDurationMillis, val delayMillis: Int = 0, val easing: Easing = FastOutSlowInEasing) : DurationBasedAnimationSpec<T>

DurationBasedAnimationSpec that interpolates 2-dimensional values using arcs of quarter of an Ellipse.

Link copied to clipboard
value class ArcMode

Interpolation mode for Arc-based animation spec.

Link copied to clipboard
@Immutable
class CubicBezierEasing(a: Float, b: Float, c: Float, d: Float) : Easing

A cubic polynomial easing.

Link copied to clipboard
class DecayAnimation<T, V : AnimationVector>(animationSpec: VectorizedDecayAnimationSpec<V>, val typeConverter: TwoWayConverter<T, V>, val initialValue: T, initialVelocityVector: V) : Animation<T, V>

DecayAnimation is an animation that slows down from initialVelocityVector as time goes on. DecayAnimation is stateless, and it does not have any concept of lifecycle. It serves as an animation calculation engine that supports convenient query of value/velocity given a play time. To achieve that, DecayAnimation stores all the animation related information: initialValue, initialVelocityVector, decay animation spec, typeConverter.

Link copied to clipboard

DecayAnimationSpec stores the specification of an animation, including 1) the data type to be animated, and 2) the animation configuration (i.e. com.jakewharton.mosaic.animation.VectorizedDecayAnimationSpec) that will be used once the data (of type T) has been converted to AnimationVector.

Link copied to clipboard

DeferredTargetAnimation is intended for animations where the target is unknown at the time of instantiation. Such use cases include, but are not limited to, size or position animations created during composition or the initialization of a Modifier.Node, yet the target size or position stays unknown until the later measure and placement phase.

Link copied to clipboard

This describes AnimationSpecs that are based on a fixed duration, such as KeyframesSpec, TweenSpec, and SnapSpec. These duration based specs can repeated when put into a RepeatableSpec.

Link copied to clipboard
@Stable
fun interface Easing

Easing is a way to adjust an animation’s fraction. Easing allows transitioning elements to speed up and slow down, rather than moving at a constant rate.

Link copied to clipboard
annotation class ExperimentalAnimatableApi
Link copied to clipboard
Link copied to clipboard
annotation class ExperimentalTransitionApi
Link copied to clipboard

FiniteAnimationSpec is the interface that all non-infinite AnimationSpecs implement, including: TweenSpec, SpringSpec, KeyframesSpec, RepeatableSpec, SnapSpec, etc. By definition, InfiniteRepeatableSpec does not implement this interface.

Link copied to clipboard

FloatAnimationSpec interface is similar to com.jakewharton.mosaic.animation.VectorizedAnimationSpec, except it deals exclusively with floats.

Link copied to clipboard

This animation interface is intended to be stateless, just like Animation. But unlike Animation, DecayAnimation does not have an end value defined. The end value is a result of the animation rather than an input.

Link copied to clipboard
class FloatExponentialDecaySpec(@FloatRange(from = 0.0, fromInclusive = false) frictionMultiplier: Float = 1.0f, @FloatRange(from = 0.0, fromInclusive = false) absVelocityThreshold: Float = 0.1f) : FloatDecayAnimationSpec

This is a decay animation where the friction/deceleration is always proportional to the velocity. As a result, the velocity goes under an exponential decay. The constructor parameter, frictionMultiplier, can be tuned to adjust the amount of friction applied in the decay. The higher the multiplier, the higher the friction, the sooner the animation will stop, and the shorter distance the animation will travel with the same starting condition.

Link copied to clipboard
class FloatSpringSpec(val dampingRatio: Float = Spring.DampingRatioNoBouncy, val stiffness: Float = Spring.StiffnessMedium, visibilityThreshold: Float = Spring.DefaultDisplacementThreshold) : FloatAnimationSpec

FloatSpringSpec animation uses a spring animation to animate a Float value. Its configuration can be tuned via adjusting the spring parameters, namely damping ratio and stiffness.

Link copied to clipboard
class FloatTweenSpec(val duration: Int = DefaultDurationMillis, val delay: Int = 0, easing: Easing = FastOutSlowInEasing) : FloatAnimationSpec

FloatTweenSpec animates a Float value from any start value to any end value using a provided easing function. The animation will finish within the duration time. Unless a delay is specified, the animation will start right away.

Link copied to clipboard

Provides a policy that will be applied to animations that get their frame time from withInfiniteAnimationFrameNanos or withInfiniteAnimationFrameMillis This can be used to intervene in infinite animations to make them finite, for example by cancelling such coroutines.

Link copied to clipboard
class InfiniteRepeatableSpec<T>(val animation: DurationBasedAnimationSpec<T>, val repeatMode: RepeatMode = RepeatMode.Restart, val initialStartOffset: StartOffset = StartOffset(0)) : AnimationSpec<T>

InfiniteRepeatableSpec repeats the provided animation infinite amount of times. It will never naturally finish. This means the animation will only be stopped via some form of manual cancellation. When used with transition or other animation composables, the infinite animations will stop when the composable is removed from the compose tree.

Link copied to clipboard

InfiniteTransition is responsible for running child animations. Child animations can be added using InfiniteTransition.animateColor, InfiniteTransition.animateFloat, or InfiniteTransition.animateValue. Child animations will start running as soon as they enter the composition, and will not stop until they are removed from the composition.

Link copied to clipboard
sealed class KeyframeBaseEntity<T>

Base holder class for building a keyframes animation.

Link copied to clipboard

Shared configuration class used as DSL for keyframe based animations.

Link copied to clipboard

KeyframesWithSplineSpec creates a keyframe based DurationBasedAnimationSpec using the Monotone cubic Hermite spline to interpolate between the values in config.

Link copied to clipboard

Provides a duration scale for motion such as animations. When the duration scaleFactor is 0, the motion will end in the next frame callback. Otherwise, the duration scaleFactor will be used as a multiplier to scale the duration of the motion. The larger the scale, the longer the motion will take to finish, and therefore the slower it will be perceived.

Link copied to clipboard
class MutableTransitionState<S>(initialState: S) : TransitionState<S>

MutableTransitionState contains two fields: currentState and targetState. currentState is initialized to the provided initialState, and can only be mutated by a Transition. targetState is also initialized to initialState. It can be mutated to alter the course of a transition animation that is created with the MutableTransitionState using rememberTransition. Both currentState and targetState are backed by a State object.

Link copied to clipboard
@Immutable
class RepeatableSpec<T>(val iterations: Int, val animation: DurationBasedAnimationSpec<T>, val repeatMode: RepeatMode = RepeatMode.Restart, val initialStartOffset: StartOffset = StartOffset(0)) : FiniteAnimationSpec<T>

RepeatableSpec takes another DurationBasedAnimationSpec and plays it iterations times. For creating infinitely repeating animation spec, consider using InfiniteRepeatableSpec.

Link copied to clipboard
class SeekableTransitionState<S>(initialState: S) : TransitionState<S>

A TransitionState that can manipulate the progress of the Transition by seeking with seekTo or animating with animateTo.

Link copied to clipboard
@Immutable
class SnapSpec<T>(val delay: Int = 0) : DurationBasedAnimationSpec<T>

SnapSpec describes a jump-cut type of animation. It immediately snaps the animating value to the end value.

Link copied to clipboard
object Spring

Physics class contains a number of recommended configurations for physics animations.

Link copied to clipboard
@Immutable
class SpringSpec<T>(val dampingRatio: Float = Spring.DampingRatioNoBouncy, val stiffness: Float = Spring.StiffnessMedium, val visibilityThreshold: T? = null) : FiniteAnimationSpec<T>

Creates a SpringSpec that uses the given spring constants (i.e. dampingRatio and stiffness. The optional visibilityThreshold defines when the animation should be considered to be visually close enough to round off to its target.

Link copied to clipboard

This class defines a start offset for repeatable and infiniteRepeatable. There are two types of start offsets: StartOffsetType.Delay and StartOffsetType.FastForward. StartOffsetType.Delay delays the start of the animation, whereas StartOffsetType.FastForward fast forwards the animation to a given play time and starts it right away.

Link copied to clipboard

This class defines the two types of StartOffset: StartOffsetType.Delay and StartOffsetType.FastForward. StartOffsetType.Delay delays the start of the animation, whereas StartOffsetType.FastForward starts the animation right away from a given play time in the animation.

Link copied to clipboard

This is a convenient animation wrapper class that works for all target based animations, i.e. animations that has a pre-defined end value, unlike decay.

Link copied to clipboard
@Stable
class Transition<S>

Transition manages all the child animations on a state level. Child animations can be created in a declarative way using Transition.animateFloat, Transition.animateValue, animateColor etc. When the targetState changes, Transition will automatically start or adjust course for all its child animations to animate to the new target values defined for each animation.

Link copied to clipboard
sealed class TransitionState<S>

Use with rememberTransition to create a Transition that can be dynamically targeted with MutableTransitionState or seekable with SeekableTransitionState.

Link copied to clipboard
@Immutable
class TweenSpec<T>(val durationMillis: Int = AnimationConstants.DefaultDurationMillis, val delay: Int = 0, val easing: Easing = FastOutSlowInEasing) : DurationBasedAnimationSpec<T>

Creates a TweenSpec configured with the given duration, delay, and easing curve.

Link copied to clipboard

TwoWayConverter class contains the definition on how to convert from an arbitrary type T to a AnimationVector, and convert the AnimationVector back to the type T. This allows animations to run on any type of objects, e.g. position, rectangle, color, etc.

Link copied to clipboard

VectorizedAnimationSpecs are stateless vector based animation specifications. They do not assume any starting/ending conditions. Nor do they manage a lifecycle. All it stores is the configuration that is particular to the type of the animation. easing and duration for VectorizedTweenSpecs, or spring constants for VectorizedSpringSpecs. Its stateless nature allows the same VectorizedAnimationSpec to be reused by a few different running animations with different starting and ending values. More importantly, it allows the system to reuse the same animation spec when the animation target changes in-flight.

Link copied to clipboard

VectorizedDecayAnimationSpecs are stateless vector based decay animation specifications. They do not assume any starting/ending conditions. Nor do they manage a lifecycle. All it stores is the configuration that is particular to the type of the decay animation: friction multiplier for exponentialDecay. Its stateless nature allows the same VectorizedDecayAnimationSpec to be reused by a few different running animations with different starting and ending values.

Link copied to clipboard

A convenient implementation of VectorizedFloatAnimationSpec that turns a FloatAnimationSpec into a multi-dimensional VectorizedFloatAnimationSpec, by using the same FloatAnimationSpec on each dimension of the AnimationVector that is being animated.

Link copied to clipboard
class VectorizedInfiniteRepeatableSpec<V : AnimationVector>(animation: VectorizedDurationBasedAnimationSpec<V>, repeatMode: RepeatMode = RepeatMode.Restart, initialStartOffset: StartOffset = StartOffset(0)) : VectorizedAnimationSpec<V>

This animation takes another VectorizedDurationBasedAnimationSpec and plays it infinite times.

Link copied to clipboard

VectorizedKeyframesSpec class manages the animation based on the values defined at different timestamps in the duration of the animation (i.e. different keyframes). Each keyframe can be provided via keyframes parameter. VectorizedKeyframesSpec allows very specific animation definitions with a precision to millisecond.

Link copied to clipboard
class VectorizedRepeatableSpec<V : AnimationVector>(iterations: Int, animation: VectorizedDurationBasedAnimationSpec<V>, repeatMode: RepeatMode = RepeatMode.Restart, initialStartOffset: StartOffset = StartOffset(0)) : VectorizedFiniteAnimationSpec<V>

This animation takes another VectorizedDurationBasedAnimationSpec and plays it iterations times. For infinitely repeating animation spec, VectorizedInfiniteRepeatableSpec is recommended.

Link copied to clipboard

VectorizedSnapSpec immediately snaps the animating value to the end value.

Link copied to clipboard

VectorizedSpringSpec uses spring animations to animate (each dimension of) AnimationVectors.

Link copied to clipboard
class VectorizedTweenSpec<V : AnimationVector>(val durationMillis: Int = DefaultDurationMillis, val delayMillis: Int = 0, val easing: Easing = FastOutSlowInEasing) : VectorizedDurationBasedAnimationSpec<V>

VectorizedTweenSpec animates a AnimationVector value by interpolating the start and end value, in the given durationMillis using the given easing curve.

Properties

Link copied to clipboard

Easing Curve that speeds up quickly and ends slowly.

Link copied to clipboard

Easing Curve that starts slowly and ends quickly.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Easing Curve that starts slowly, speeds up and then ends slowly.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Easing Curve that starts slowly and ends quickly. Similar to EaseIn, but with slightly less abrupt beginning

Link copied to clipboard

Easing Curve that starts quickly and ends slowly.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Elements exiting a screen use acceleration easing, where they start at rest and end at peak velocity.

Link copied to clipboard

Elements that begin and end at rest use this standard easing. They speed up quickly and slow down gradually, in order to emphasize the end of the transition.

Link copied to clipboard

Indicates whether the given AnimationState is for an animation that has finished, indicated by AnimationState.finishedTimeNanos having a specified value.

Link copied to clipboard

It returns fraction unmodified. This is useful as a default value for cases where a Easing is required but no actual easing is desired.

Link copied to clipboard

Incoming elements are animated using deceleration easing, which starts a transition at peak velocity (the fastest point of an element’s movement) and ends at rest.

Link copied to clipboard

Visibility threshold for IntOffset. This defines the amount of value change that is considered to be no longer visible. The animation system uses this to signal to some default spring animations to stop when the value is close enough to the target.

Visibility threshold for IntSize. This defines the amount of value change that is considered to be no longer visible. The animation system uses this to signal to some default spring animations to stop when the value is close enough to the target.

Visibility threshold for Int. This defines the amount of value change that is considered to be no longer visible. The animation system uses this to signal to some default spring animations to stop when the value is close enough to the target.

Functions

Link copied to clipboard

This Animatable function creates a Color value holder that automatically animates its value when the value is changed via animateTo. Animatable supports value change during an ongoing value change animation. When that happens, a new animation will transition Animatable from its current value (i.e. value at the point of interruption) to the new target. This ensures that the value change is always continuous using animateTo. If spring animation (i.e. default animation) is used with animateTo, the velocity change will be guaranteed to be continuous as well.

fun Animatable(initialValue: Float, visibilityThreshold: Float = Spring.DefaultDisplacementThreshold): Animatable<Float, AnimationVector1D>

This Animatable function creates a float value holder that automatically animates its value when the value is changed via animateTo. Animatable supports value change during an ongoing value change animation. When that happens, a new animation will transition Animatable from its current value (i.e. value at the point of interruption) to the new target. This ensures that the value change is always continuous using animateTo. If spring animation (i.e. default animation) is used with animateTo, the velocity change will be guaranteed to be continuous as well.

Link copied to clipboard
suspend fun animate(initialValue: Float, targetValue: Float, initialVelocity: Float = 0.0f, animationSpec: AnimationSpec<Float> = spring(), block: (value: Float, velocity: Float) -> Unit)

Target based animation that animates from the given initialValue towards the targetValue, with an optional initialVelocity. By default, a spring will be used for the animation. An alternative animationSpec can be provided to replace the default spring.

suspend fun <T, V : AnimationVector> animate(typeConverter: TwoWayConverter<T, V>, initialValue: T, targetValue: T, initialVelocity: T? = null, animationSpec: AnimationSpec<T> = spring(), block: (value: T, velocity: T) -> Unit)

Target based animation for animating any data type T, so long as T can be converted to an AnimationVector using typeConverter. The animation will start from the initialValue and animate to the targetValue value. The initialVelocity will be derived from an all-0 AnimationVector unless specified. animationSpec can be provided to create a specific look and feel for the animation. By default, a spring will be used.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateColor(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<Color> = { spring() }, label: String = "ColorAnimation", targetValueByState: @Composable (state: S) -> Color): State<Color>

Creates a Color animation as a part of the given Transition. This means the lifecycle of this animation will be managed by the Transition.

@Composable
fun InfiniteTransition.animateColor(initialValue: Color, targetValue: Color, animationSpec: InfiniteRepeatableSpec<Color>, label: String = "ColorAnimation"): State<Color>

Creates a Color animation that runs infinitely as a part of the given InfiniteTransition.

Link copied to clipboard
@Composable
fun animateColorAsState(targetValue: Color, animationSpec: AnimationSpec<Color> = colorDefaultSpring, label: String = "ColorAnimation", finishedListener: (Color) -> Unit? = null): State<Color>

Fire-and-forget animation function for Color. This Composable function is overloaded for different parameter types such as Float, Int, IntSize, IntOffset, etc. When the provided targetValue is changed, the animation will run automatically. If there is already an animation in-flight when targetValue changes, the on-going animation will adjust course to animate towards the new target value.

Link copied to clipboard
suspend fun animateDecay(initialValue: Float, initialVelocity: Float, animationSpec: FloatDecayAnimationSpec, block: (value: Float, velocity: Float) -> Unit)

Decay animation that slows down from the given initialVelocity starting at initialValue until the velocity reaches 0. This is often used after a fling gesture.

Link copied to clipboard
suspend fun <T, V : AnimationVector> AnimationState<T, V>.animateDecay(animationSpec: DecayAnimationSpec<T>, sequentialAnimation: Boolean = false, block: AnimationScope<T, V>.() -> Unit = {})

Decay animation that slows down from the current velocity and value captured in AnimationState until the velocity reaches 0. During the animation, the given AnimationState will be updated with the up-to-date value/velocity, frame time, etc. This is often used to animate the result of a fling gesture.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateFloat(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<Float> = { spring() }, label: String = "FloatAnimation", targetValueByState: @Composable (state: S) -> Float): State<Float>

Creates a Float animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.

@Composable
fun InfiniteTransition.animateFloat(initialValue: Float, targetValue: Float, animationSpec: InfiniteRepeatableSpec<Float>, label: String = "FloatAnimation"): State<Float>

Creates an animation of Float type that runs infinitely as a part of the given InfiniteTransition.

Link copied to clipboard
@Composable
fun animateFloatAsState(targetValue: Float, animationSpec: AnimationSpec<Float> = defaultAnimation, visibilityThreshold: Float = 0.01f, label: String = "FloatAnimation", finishedListener: (Float) -> Unit? = null): State<Float>

Fire-and-forget animation function for Float. This Composable function is overloaded for different parameter types such as Color, IntOffset, etc. When the provided targetValue is changed, the animation will run automatically. If there is already an animation in-flight when targetValue changes, the on-going animation will adjust course to animate towards the new target value.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateInt(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<Int> = { spring(visibilityThreshold = 1) }, label: String = "IntAnimation", targetValueByState: @Composable (state: S) -> Int): State<Int>

Creates a Int animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.

Link copied to clipboard
@Composable
fun animateIntAsState(targetValue: Int, animationSpec: AnimationSpec<Int> = intDefaultSpring, label: String = "IntAnimation", finishedListener: (Int) -> Unit? = null): State<Int>

Fire-and-forget animation function for Int. This Composable function is overloaded for different parameter types such as Color, IntOffset, etc. When the provided targetValue is changed, the animation will run automatically. If there is already an animation in-flight when targetValue changes, the on-going animation will adjust course to animate towards the new target value.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateIntOffset(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<IntOffset> = { spring(visibilityThreshold = IntOffset(1, 1)) }, label: String = "IntOffsetAnimation", targetValueByState: @Composable (state: S) -> IntOffset): State<IntOffset>

Creates a IntOffset animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.

Link copied to clipboard
@Composable
fun animateIntOffsetAsState(targetValue: IntOffset, animationSpec: AnimationSpec<IntOffset> = intOffsetDefaultSpring, label: String = "IntOffsetAnimation", finishedListener: (IntOffset) -> Unit? = null): State<IntOffset>

Fire-and-forget animation function for IntOffset. This Composable function is overloaded for different parameter types such as Color, IntOffset, etc. When the provided targetValue is changed, the animation will run automatically. If there is already an animation in-flight when targetValue changes, the on-going animation will adjust course to animate towards the new target value.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateIntSize(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<IntSize> = { spring(visibilityThreshold = IntSize(1, 1)) }, label: String = "IntSizeAnimation", targetValueByState: @Composable (state: S) -> IntSize): State<IntSize>

Creates a IntSize animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.

Link copied to clipboard
@Composable
fun animateIntSizeAsState(targetValue: IntSize, animationSpec: AnimationSpec<IntSize> = intSizeDefaultSpring, label: String = "IntSizeAnimation", finishedListener: (IntSize) -> Unit? = null): State<IntSize>

Fire-and-forget animation function for IntSize. This Composable function is overloaded for different parameter types such as Color, IntOffset, etc. When the provided targetValue is changed, the animation will run automatically. If there is already an animation in-flight when targetValue changes, the on-going animation will adjust course to animate towards the new target value.

Link copied to clipboard
suspend fun <T, V : AnimationVector> AnimationState<T, V>.animateTo(targetValue: T, animationSpec: AnimationSpec<T> = spring(), sequentialAnimation: Boolean = false, block: AnimationScope<T, V>.() -> Unit = {})

Target based animation that takes the value and velocity from the AnimationState as the starting condition, and animate to the targetValue, using the animationSpec. During the animation, the given AnimationState will be updated with the up-to-date value/velocity, frame time, etc.

Link copied to clipboard
@Composable
inline fun <S, T, V : AnimationVector> Transition<S>.animateValue(typeConverter: TwoWayConverter<T, V>, noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<T> = { spring() }, label: String = "ValueAnimation", targetValueByState: @Composable (state: S) -> T): State<T>

Creates an animation of type T as a part of the given Transition. This means the states of this animation will be managed by the Transition. typeConverter will be used to convert between type T and AnimationVector so that the animation system knows how to animate it.

@Composable
fun <T, V : AnimationVector> InfiniteTransition.animateValue(initialValue: T, targetValue: T, typeConverter: TwoWayConverter<T, V>, animationSpec: InfiniteRepeatableSpec<T>, label: String = "ValueAnimation"): State<T>

Creates an animation of type T that runs infinitely as a part of the given InfiniteTransition. Any data type can be animated so long as it can be converted from and to an AnimationVector. This conversion needs to be provided as a typeConverter. Some examples of such TwoWayConverter are: Int.VectorConverter, IntSize.Companion.VectorConverter, etc

Link copied to clipboard
@Composable
fun <T, V : AnimationVector> animateValueAsState(targetValue: T, typeConverter: TwoWayConverter<T, V>, animationSpec: AnimationSpec<T> = remember { spring() }, visibilityThreshold: T? = null, label: String = "ValueAnimation", finishedListener: (T) -> Unit? = null): State<T>

Fire-and-forget animation function for any value. This Composable function is overloaded for different parameter types such as Color, IntOffset, etc. When the provided targetValue is changed, the animation will run automatically. If there is already an animation in-flight when targetValue changes, the on-going animation will adjust course to animate towards the new target value.

Link copied to clipboard
fun AnimationState(initialValue: Float, initialVelocity: Float = 0.0f, lastFrameTimeNanos: Long = AnimationConstants.UnspecifiedTime, finishedTimeNanos: Long = AnimationConstants.UnspecifiedTime, isRunning: Boolean = false): AnimationState<Float, AnimationVector1D>

Factory method for creating an AnimationState for Float initialValue.

fun <T, V : AnimationVector> AnimationState(typeConverter: TwoWayConverter<T, V>, initialValue: T, initialVelocity: T, lastFrameTimeNanos: Long = AnimationConstants.UnspecifiedTime, finishedTimeNanos: Long = AnimationConstants.UnspecifiedTime, isRunning: Boolean = false): AnimationState<T, V>

Factory method for creating an AnimationState with an initialValue and an initialVelocity.

Link copied to clipboard

Factory method to create an AnimationVector1D

Factory method to create an AnimationVector2D

Factory method to create an AnimationVector3D

Factory method to create an AnimationVector4D

Link copied to clipboard
fun DecayAnimationSpec<Float>.calculateTargetValue(initialValue: Float, initialVelocity: Float): Float

Calculates the target value of a Float decay animation based on the initialValue and initialVelocity.

fun <T, V : AnimationVector> DecayAnimationSpec<T>.calculateTargetValue(typeConverter: TwoWayConverter<T, V>, initialValue: T, initialVelocity: T): T

Calculates the target value of a decay animation based on the initialValue and initialVelocity, and the typeConverter that converts the given type T to AnimationVector.

Link copied to clipboard
fun <T, V : AnimationVector> AnimationState<T, V>.copy(value: T = this.value, velocityVector: V? = this.velocityVector.copy(), lastFrameTimeNanos: Long = this.lastFrameTimeNanos, finishedTimeNanos: Long = this.finishedTimeNanos, isRunning: Boolean = this.isRunning): AnimationState<T, V>

Creates a new AnimationState from a given AnimationState. This function allows some of the fields to be different in the new AnimationState.

fun AnimationState<Float, AnimationVector1D>.copy(value: Float = this.value, velocity: Float = this.velocityVector.value, lastFrameTimeNanos: Long = this.lastFrameTimeNanos, finishedTimeNanos: Long = this.finishedTimeNanos, isRunning: Boolean = this.isRunning): AnimationState<Float, AnimationVector1D>

Creates a new AnimationState of Float value type from a given AnimationState of the same type. This function allows some of the fields to be different in the new AnimationState.

Link copied to clipboard
@RestrictTo(value = [RestrictTo.Scope.LIBRARY])
fun <V : AnimationVector> VectorizedAnimationSpec<V>.createAnimation(initialValue: V, targetValue: V, initialVelocity: V): TargetBasedAnimation<V, V>

Creates a TargetBasedAnimation from a given com.jakewharton.mosaic.animation.VectorizedAnimationSpec of AnimationVector type. This convenient method is intended for when the value being animated (i.e. start value, end value, etc) is of AnimationVector type.

Link copied to clipboard
@Composable
inline fun <S, T> Transition<S>.createChildTransition(label: String = "ChildTransition", transformToChildState: @Composable (parentState: S) -> T): Transition<T>

createChildTransition creates a child Transition based on the mapping between parent state to child state provided in transformToChildState. This serves the following purposes:

Link copied to clipboard
@RestrictTo(value = [RestrictTo.Scope.LIBRARY])
@Composable
fun <S, T, V : AnimationVector> Transition<S>.createDeferredAnimation(typeConverter: TwoWayConverter<T, V>, label: String = "DeferredAnimation"): Transition.DeferredAnimation<T, V, S>

This creates a DeferredAnimation, which will not animate until it is set up using DeferredAnimation.animate. Once the animation is set up, it will animate from the currentState to targetState. If the Transition has already arrived at its target state at the time when the animation added, there will be no animation.

Link copied to clipboard

Creates an AnimationVector with all the values set to 0 using the provided com.jakewharton.mosaic.animation.TwoWayConverter and the value.

Link copied to clipboard
fun DecayAnimation(animationSpec: FloatDecayAnimationSpec, initialValue: Float, initialVelocity: Float = 0.0f): DecayAnimation<Float, AnimationVector1D>

DecayAnimation is an animation that slows down from initialVelocity as time goes on. DecayAnimation is stateless, and it does not have any concept of lifecycle. It serves as an animation calculation engine that supports convenient query of value/velocity given a play time. To achieve that, DecayAnimation stores all the animation related information: initialValue, initialVelocity, decay animation spec.

Link copied to clipboard
@RestrictTo(value = [RestrictTo.Scope.LIBRARY])
fun estimateAnimationDurationMillis(stiffness: Float, dampingRatio: Float, initialVelocity: Float, initialDisplacement: Float, delta: Float): Long

Returns the estimated time that the spring will last be at delta

Link copied to clipboard
fun <T> exponentialDecay(@FloatRange(from = 0.0, fromInclusive = false) frictionMultiplier: Float = 1.0f, @FloatRange(from = 0.0, fromInclusive = false) absVelocityThreshold: Float = 0.1f): DecayAnimationSpec<T>

Creates a decay animation spec where the friction/deceleration is always proportional to the velocity. As a result, the velocity goes under an exponential decay. The constructor parameter, frictionMultiplier, can be tuned to adjust the amount of friction applied in the decay. The higher the multiplier, the higher the friction, the sooner the animation will stop, and the shorter distance the animation will travel with the same starting condition. absVelocityThreshold describes the absolute value of a velocity threshold, below which the animation is considered finished.

Link copied to clipboard
fun <T, V : AnimationVector> Animation<T, V>.getVelocityFromNanos(playTimeNanos: Long): T

Returns the velocity of the animation at the given play time.

Link copied to clipboard
@Stable
fun <T> infiniteRepeatable(animation: DurationBasedAnimationSpec<T>, repeatMode: RepeatMode = RepeatMode.Restart, initialStartOffset: StartOffset = StartOffset(0)): InfiniteRepeatableSpec<T>

Creates a InfiniteRepeatableSpec that plays a DurationBasedAnimationSpec (e.g. TweenSpec, KeyframesSpec) infinite amount of iterations.

Link copied to clipboard

Creates a KeyframesSpec animation, initialized with init. For example:

Link copied to clipboard

Creates a KeyframesWithSplineSpec animation, initialized with init.

fun <T> keyframesWithSpline(@FloatRange(from = 0.0, to = 1.0) periodicBias: Float, init: KeyframesWithSplineSpec.KeyframesWithSplineSpecConfig<T>.() -> Unit): KeyframesWithSplineSpec<T>

Creates a periodic KeyframesWithSplineSpec animation, initialized with init.

Link copied to clipboard
@Composable
fun rememberInfiniteTransition(label: String = "InfiniteTransition"): InfiniteTransition

Creates a InfiniteTransition that runs infinite child animations. Child animations can be added using InfiniteTransition.animateColor, InfiniteTransition.animateFloat, or InfiniteTransition.animateValue. Child animations will start running as soon as they enter the composition, and will not stop until they are removed from the composition.

Link copied to clipboard
@Composable
fun <T> rememberTransition(transitionState: TransitionState<T>, label: String? = null): Transition<T>

Creates a Transition and puts it in the currentState of the provided transitionState. If the TransitionState.targetState changes, the Transition will change where it will animate to.

Link copied to clipboard
@Stable
fun <T> repeatable(iterations: Int, animation: DurationBasedAnimationSpec<T>, repeatMode: RepeatMode = RepeatMode.Restart, initialStartOffset: StartOffset = StartOffset(0)): RepeatableSpec<T>

Creates a RepeatableSpec that plays a DurationBasedAnimationSpec (e.g. TweenSpec, KeyframesSpec) the amount of iterations specified by iterations.

Link copied to clipboard
@Stable
fun <T> snap(delayMillis: Int = 0): SnapSpec<T>

Creates a Snap animation for immediately switching the animating value to the end value.

Link copied to clipboard
@Stable
fun <T> spring(dampingRatio: Float = Spring.DampingRatioNoBouncy, stiffness: Float = Spring.StiffnessMedium, visibilityThreshold: T? = null): SpringSpec<T>

Creates a SpringSpec that uses the given spring constants (i.e. dampingRatio and stiffness. The optional visibilityThreshold defines when the animation should be considered to be visually close enough to round off to its target.

Link copied to clipboard
fun <T, V : AnimationVector> TargetBasedAnimation(animationSpec: AnimationSpec<T>, typeConverter: TwoWayConverter<T, V>, initialValue: T, targetValue: T, initialVelocity: T): TargetBasedAnimation<T, V>

Creates a TargetBasedAnimation with the given start/end conditions of the animation, and the provided animationSpec.

Link copied to clipboard
@Stable
fun <T> tween(durationMillis: Int = AnimationConstants.DefaultDurationMillis, delayMillis: Int = 0, easing: Easing = FastOutSlowInEasing): TweenSpec<T>

Creates a TweenSpec configured with the given duration, delay and easing curve.

Link copied to clipboard
fun <T, V : AnimationVector> TwoWayConverter(convertToVector: (T) -> V, convertFromVector: (V) -> T): TwoWayConverter<T, V>

Factory method to create a TwoWayConverter that converts a type T from and to an AnimationVector type.

Link copied to clipboard
@Composable
fun <T> updateTransition(targetState: T, label: String? = null): Transition<T>

This sets up a Transition, and updates it with the target provided by targetState. When targetState changes, Transition will run all of its child animations towards their target values specified for the new targetState. Child animations can be dynamically added using Transition.animateFloat, animateColor, Transition.animateValue, etc.

Link copied to clipboard
inline suspend fun <R> withInfiniteAnimationFrameMillis(crossinline onFrame: (frameTimeMillis: Long) -> R): R

Like withFrameMillis, but applies the InfiniteAnimationPolicy from the calling CoroutineContext if there is one.

Link copied to clipboard
suspend fun <R> withInfiniteAnimationFrameNanos(onFrame: (frameTimeNanos: Long) -> R): R

Like withFrameNanos, but applies the InfiniteAnimationPolicy from the calling CoroutineContext if there is one.