Package-level declarations
Types
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.
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.
Possible reasons for com.jakewharton.mosaic.animation.Animatables to end.
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:
AnimationScope provides all the animation related info specific to an animation run. An AnimationScope will be accessible during an animation.
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.
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.
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.
This class defines a 1D vector. It contains only one Float value that is initialized in the constructor.
This class defines a 2D vector that contains two Float values for the two dimensions.
This class defines a 3D vector that contains three Float value fields for the three dimensions.
This class defines a 4D vector that contains four Float fields for its four dimensions.
DurationBasedAnimationSpec that interpolates 2-dimensional values using arcs of quarter of an Ellipse.
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.
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.
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.
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.
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.
FloatAnimationSpec interface is similar to com.jakewharton.mosaic.animation.VectorizedAnimationSpec, except it deals exclusively with floats.
This animation interface is intended to be stateless, just like Animation
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.
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.
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.
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.
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.
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.
Base holder class for building a keyframes animation.
KeyframesSpec creates a com.jakewharton.mosaic.animation.VectorizedKeyframesSpec animation.
Shared configuration class used as DSL for keyframe based animations.
KeyframesWithSplineSpec creates a keyframe based DurationBasedAnimationSpec using the Monotone cubic Hermite spline to interpolate between the values in config.
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.
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.
RepeatableSpec takes another DurationBasedAnimationSpec and plays it iterations times. For creating infinitely repeating animation spec, consider using InfiniteRepeatableSpec.
Repeat mode for RepeatableSpec and com.jakewharton.mosaic.animation.VectorizedRepeatableSpec.
A TransitionState that can manipulate the progress of the Transition by seeking with seekTo or animating with animateTo.
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.
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.
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.
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.
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.
Use with rememberTransition to create a Transition that can be dynamically targeted with MutableTransitionState or seekable with SeekableTransitionState.
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.
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.
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.
Base class for VectorizedAnimationSpecs that are based on a fixed durationMillis.
All the finite VectorizedAnimationSpecs implement this interface, including: VectorizedKeyframesSpec, VectorizedTweenSpec, VectorizedRepeatableSpec, VectorizedSnapSpec, VectorizedSpringSpec, etc. The VectorizedAnimationSpec that does not implement this is: InfiniteRepeatableSpec.
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.
This animation takes another VectorizedDurationBasedAnimationSpec and plays it infinite times.
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.
This animation takes another VectorizedDurationBasedAnimationSpec and plays it iterations times. For infinitely repeating animation spec, VectorizedInfiniteRepeatableSpec is recommended.
VectorizedSnapSpec immediately snaps the animating value to the end value.
VectorizedSpringSpec uses spring animations to animate (each dimension of) AnimationVectors.
VectorizedTweenSpec animates a AnimationVector value by interpolating the start and end value, in the given durationMillis using the given easing curve.
Properties
Easing Curve that starts slowly and ends quickly. Similar to EaseIn, but with slightly less abrupt beginning
Elements exiting a screen use acceleration easing, where they start at rest and end at peak velocity.
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.
Indicates whether the given AnimationState is for an animation that has finished, indicated by AnimationState.finishedTimeNanos having a specified value.
It returns fraction unmodified. This is useful as a default value for cases where a Easing is required but no actual easing is desired.
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.
Returns a converter that can both convert a Color to a AnimationVector3D, and convert a AnimationVector3D) back to a Color.
A type converter that converts a IntOffset to a AnimationVector2D, and vice versa.
A type converter that converts a IntSize to a AnimationVector2D, and vice versa.
A TwoWayConverter that converts Float from and to AnimationVector1D
A TwoWayConverter that converts Int from and to AnimationVector1D
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.
Functions
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.
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.
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.
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.
Creates a Color animation as a part of the given Transition. This means the lifecycle of this animation will be managed by the Transition.
Creates a Color animation that runs infinitely as a part of the given InfiniteTransition.
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.
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.
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.
Creates a Float animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.
Creates an animation of Float type that runs infinitely as a part of the given InfiniteTransition.
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.
Creates a Int animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.
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.
Creates a IntOffset animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.
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.
Creates a IntSize animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.
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.
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.
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.
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
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.
Factory method for creating an AnimationState for Float initialValue.
Factory method for creating an AnimationState with an initialValue and an initialVelocity.
Factory method to create an AnimationVector1D
Factory method to create an AnimationVector2D
Factory method to create an AnimationVector3D
Factory method to create an AnimationVector4D
Calculates the target value of a Float decay animation based on the initialValue and initialVelocity.
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.
Creates a new AnimationState from a given AnimationState. This function allows some of the fields to be different in the new AnimationState.
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.
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.
createChildTransition creates a child Transition based on the mapping between parent state to child state provided in transformToChildState. This serves the following purposes:
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.
Creates an AnimationVector with all the values set to 0 using the provided com.jakewharton.mosaic.animation.TwoWayConverter and the value.
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.
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.
Creates a DecayAnimationSpec from a com.jakewharton.mosaic.animation.FloatDecayAnimationSpec by applying the given com.jakewharton.mosaic.animation.FloatDecayAnimationSpec on every dimension of the AnimationVector that T converts to.
Returns the velocity of the animation at the given play time.
Creates a InfiniteRepeatableSpec that plays a DurationBasedAnimationSpec (e.g. TweenSpec, KeyframesSpec) infinite amount of iterations.
Creates a KeyframesSpec animation, initialized with init. For example:
Creates a KeyframesWithSplineSpec animation, initialized with init.
Creates a periodic KeyframesWithSplineSpec animation, initialized with init.
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.
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.
Creates a RepeatableSpec that plays a DurationBasedAnimationSpec (e.g. TweenSpec, KeyframesSpec) the amount of iterations specified by iterations.
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.
Creates a TargetBasedAnimation with the given start/end conditions of the animation, and the provided animationSpec.
Factory method to create a TwoWayConverter that converts a type T from and to an AnimationVector type.
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.
Like withFrameMillis, but applies the InfiniteAnimationPolicy from the calling CoroutineContext if there is one.
Like withFrameNanos, but applies the InfiniteAnimationPolicy from the calling CoroutineContext if there is one.