androidx.ui.animation

Classes

AnimatedFloatModel

Model class for AnimatedFloat.

AnimatedValueModel

Model class for AnimatedValue.

ColorPropKey

Built-in property key for Color properties.

DisposableAnimationClock

Clock that remembers all of its active subscriptions so that it can dispose of upstream subscriptions.

DpPropKey

Built-in property key for Dp properties.

PxPositionPropKey

Built-in property key for PxPosition properties.

PxPropKey

Built-in property key for Px properties.

RectPropKey

Built-in property key for Rect properties.

Top-level functions summary

Unit
Crossfade(current: T, animation: AnimationBuilder<Float> = TweenBuilder(), children: <ERROR CLASS>, Unit: <ERROR CLASS>)

Crossfade allows to switch between two layouts with a crossfade animation.

Unit
Transition(definition: TransitionDefinition<T>, toState: T, clock: AnimationClockObservable = AnimationClockAmbient.current, initState: T = toState, onStateChangeFinished: (T) -> Unit = null, children: <ERROR CLASS>, Unit: <ERROR CLASS>)

Transition composable creates a state-based transition using the animation configuration defined in TransitionDefinition.

Float
animate(target: Float, animBuilder: AnimationBuilder<Float> = remember { PhysicsBuilder() }, visibilityThreshold: Float = 0.01f, endListener: (Float) -> Unit = null)

Fire-and-forget animation Composable for Float.

Color
animate(target: Color, animBuilder: AnimationBuilder<Color> = remember { PhysicsBuilder() }, endListener: (Color) -> Unit = null)

Fire-and-forget animation Composable for Color.

Dp
animate(target: Dp, animBuilder: AnimationBuilder<Dp> = remember { PhysicsBuilder() }, endListener: (Dp) -> Unit = null)

Fire-and-forget animation Composable for Dp.

Position
animate(target: Position, animBuilder: AnimationBuilder<Position> = remember { PhysicsBuilder() }, endListener: (Position) -> Unit = null)

Fire-and-forget animation Composable for Position.

Size
animate(target: Size, animBuilder: AnimationBuilder<Size> = remember { PhysicsBuilder() }, endListener: (Size) -> Unit = null)

Fire-and-forget animation Composable for Size.

Bounds
animate(target: Bounds, animBuilder: AnimationBuilder<Bounds> = remember { PhysicsBuilder() }, endListener: (Bounds) -> Unit = null)

Fire-and-forget animation Composable for Bounds.

Px
animate(target: Px, animBuilder: AnimationBuilder<Px> = remember { PhysicsBuilder() }, endListener: (Px) -> Unit = null)

Fire-and-forget animation Composable for Px.

PxSize
animate(target: PxSize, animBuilder: AnimationBuilder<PxSize> = remember { PhysicsBuilder() }, endListener: (PxSize) -> Unit = null)

Fire-and-forget animation Composable for PxSize.

PxPosition
animate(target: PxPosition, animBuilder: AnimationBuilder<PxPosition> = remember { PhysicsBuilder() }, endListener: (PxPosition) -> Unit = null)

Fire-and-forget animation Composable for PxPosition.

PxBounds
animate(target: PxBounds, animBuilder: AnimationBuilder<PxBounds> = remember { PhysicsBuilder() }, endListener: (PxBounds) -> Unit = null)

Fire-and-forget animation Composable for PxBounds.

IntPx
animate(target: IntPx, animBuilder: AnimationBuilder<IntPx> = remember { PhysicsBuilder() }, endListener: (IntPx) -> Unit = null)

Fire-and-forget animation Composable for IntPx.

IntPxPosition
animate(target: IntPxPosition, animBuilder: AnimationBuilder<IntPxPosition> = remember { PhysicsBuilder() }, endListener: (IntPxPosition) -> Unit = null)

Fire-and-forget animation Composable for IntPxPosition.

IntPxSize
animate(target: IntPxSize, animBuilder: AnimationBuilder<IntPxSize> = remember { PhysicsBuilder() }, endListener: (IntPxSize) -> Unit = null)

Fire-and-forget animation Composable for IntPxSize.

IntPxBounds
animate(target: IntPxBounds, animBuilder: AnimationBuilder<IntPxBounds> = remember { PhysicsBuilder() }, endListener: (IntPxBounds) -> Unit = null)

Fire-and-forget animation Composable for IntPxBounds.

T
animate(target: T, animBuilder: AnimationBuilder<T> = remember { PhysicsBuilder() }, visibilityThreshold: T? = null, endListener: (T) -> Unit = null)

Fire-and-forget animation Composable for AnimationVector.

T
animate(target: T, converter: TwoWayConverter<T, V>, animBuilder: AnimationBuilder<T> = remember { PhysicsBuilder() }, visibilityThreshold: V? = null, endListener: (T) -> Unit = null)

Fire-and-forget animation Composable for any value.

AnimatedValue<Color, AnimationVector4D>
animatedColor(initVal: Color, clock: AnimationClockObservable = AnimationClockAmbient.current)

The animatedValue effect creates an AnimatedValue of Color and positionally memoizes it.

AnimatedFloat
animatedFloat(initVal: Float, visibilityThreshold: Float = Spring.DefaultDisplacementThreshold, clock: AnimationClockObservable = AnimationClockAmbient.current)

The animatedValue effect creates an AnimatedFloat and positionally memoizes it.

AnimatedValue<T, V>
animatedValue(initVal: T, converter: TwoWayConverter<T, V>, visibilityThreshold: V? = null, clock: AnimationClockObservable = AnimationClockAmbient.current)

The animatedValue effect creates an AnimatedValue and positionally memoizes it.

Top-level properties summary

TwoWayConverter<Bounds, AnimationVector4D>

A type converter that converts a Bounds to a AnimationVector4D, and vice versa.

(colorSpace: ColorSpace) -> TwoWayConverter<Color, AnimationVector4D>

A lambda that takes a ColorSpace and returns a converter that can both convert a Color to a AnimationVector4D, and convert a AnimationVector4D) back to a Color in the given ColorSpace.

TwoWayConverter<Dp, AnimationVector1D>

A type converter that converts a Dp to a AnimationVector1D, and vice versa.

TwoWayConverter<IntPxBounds, AnimationVector4D>

A type converter that converts a IntPxBounds to a AnimationVector4D, and vice versa.

TwoWayConverter<IntPxPosition, AnimationVector2D>

A type converter that converts a IntPxPosition to a AnimationVector2D, and vice versa.

TwoWayConverter<IntPxSize, AnimationVector2D>

A type converter that converts a IntPxSize to a AnimationVector2D, and vice versa.

TwoWayConverter<IntPx, AnimationVector1D>

A type converter that converts a Px to a AnimationVector1D, and vice versa.

TwoWayConverter<Position, AnimationVector2D>

A type converter that converts a Position to a AnimationVector2D, and vice versa.

TwoWayConverter<PxBounds, AnimationVector4D>

A type converter that converts a PxBounds to a AnimationVector4D, and vice versa.

TwoWayConverter<PxPosition, AnimationVector2D>

A type converter that converts a PxPosition to a AnimationVector2D, and vice versa.

TwoWayConverter<PxSize, AnimationVector2D>

A type converter that converts a PxSize to a AnimationVector2D, and vice versa.

TwoWayConverter<Px, AnimationVector1D>

A type converter that converts a Px to a AnimationVector1D, and vice versa.

TwoWayConverter<Rect, AnimationVector4D>

A type converter that converts a Rect to a AnimationVector4D, and vice versa.

TwoWayConverter<Size, AnimationVector2D>

A type converter that converts a Size to a AnimationVector2D, and vice versa.

Boolean

Stores the enabled state for Transition animations.

Extension functions summary

For AnimationClockObservable
DisposableAnimationClock

Return a new AnimationClockObservable wrapping this one that will auto-unsubscribe all AnimationClockObservers when this call leaves the composition, preventing clock subscriptions from persisting beyond the composition lifecycle.

Top-level functions

Crossfade

@Composable fun <T> Crossfade(
    current: T,
    animation: AnimationBuilder<Float> = TweenBuilder(),
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Unit

Crossfade allows to switch between two layouts with a crossfade animation.

import androidx.ui.animation.Crossfade
import androidx.ui.foundation.Text

Crossfade(current = "A") { screen ->
    when (screen) {
        "A" -> Text("Page A")
        "B" -> Text("Page B")
    }
}
Parameters
current: T is a key representing your current layout state. every time you change a key the animation will be triggered. The children called with the old key will be faded out while the children called with the new key will be faded in.
animation: AnimationBuilder<Float> = TweenBuilder() the AnimationBuilder to configure the animation.

Transition

@Composable fun <T> Transition(
    definition: TransitionDefinition<T>,
    toState: T,
    clock: AnimationClockObservable = AnimationClockAmbient.current,
    initState: T = toState,
    onStateChangeFinished: (T) -> Unit = null,
    children: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Unit

Transition composable creates a state-based transition using the animation configuration defined in TransitionDefinition. This can be especially useful when animating multiple values from a predefined set of values to another. For animating a single value, consider using animatedValue, animatedFloat, animatedColor or the more light-weight animate APIs.

Transition starts a new animation or changes the on-going animation when the toState parameter is changed to a different value. It dutifully ensures that the animation will head towards new toState regardless of what state (or in-between state) it’s currently in: If the transition is not currently animating, having a new toState value will start a new animation, otherwise the in-flight animation will correct course and animate towards the new toState based on the interruption handling logic.

Transition takes a transition definition, a target state and child composables. These child composables will be receiving a TransitionState object as an argument, which captures all the current values of the animation. Child composables should read the animation values from the TransitionState object, and apply the value wherever necessary.

import androidx.animation.transitionDefinition
import androidx.ui.animation.ColorPropKey
import androidx.ui.animation.DpPropKey
import androidx.ui.animation.Transition
import androidx.ui.foundation.Box
import androidx.ui.foundation.drawBackground
import androidx.ui.layout.preferredSize

val colorKey = ColorPropKey()
val widthKey = DpPropKey()
val heightKey = DpPropKey()

val definition = transitionDefinition {
    state(State.First) {
        this[colorKey] = Color.Red
        this[widthKey] = 200.dp
        this[heightKey] = 400.dp
    }
    state(State.Second) {
        this[colorKey] = Color.Green
        this[widthKey] = 300.dp
        this[heightKey] = 300.dp
    }
}

@Composable
fun TransitionBasedColoredRect() {
    // This puts the transition in State.First. Any subsequent state change will trigger a
    // transition animation, as defined in the transition definition.
    Transition(definition = definition, toState = State.First) { state ->
        Box(
            Modifier
                .preferredSize(state[widthKey], state[heightKey])
                .drawBackground(state[colorKey])
        )
    }
}

@Composable
fun ColorRectWithInitState() {
    // This starts the transition going from State.First to State.Second when this composable
    // gets composed for the first time.
    Transition(definition = definition, initState = State.First, toState = State.Second) {
            state ->
        Box(
            Modifier
                .preferredSize(state[widthKey], state[heightKey])
                .drawBackground(state[colorKey])
        )
    }
}
Parameters
definition: TransitionDefinition<T> Transition definition that defines states and transitions
toState: T New state to transition to
clock: AnimationClockObservable = AnimationClockAmbient.current Optional animation clock that pulses animations when time changes. By default, the system uses a choreographer based clock read from the AnimationClockAmbient. A custom implementation of the AnimationClockObservable (such as a androidx.animation.ManualAnimationClock) can be supplied here if there’s a need to manually control the clock (for example in tests).
initState: T = toState Optional initial state for the transition. When undefined, the initial state will be set to the first toState seen in the transition.
onStateChangeFinished: (T) -> Unit = null An optional listener to get notified when state change animation has completed
children: <ERROR CLASS> The children composables that will be animated

animate

@Composable fun animate(
    target: Float,
    animBuilder: AnimationBuilder<Float> = remember { PhysicsBuilder() },
    visibilityThreshold: Float = 0.01f,
    endListener: (Float) -> Unit = null
): Float

Fire-and-forget animation Composable for Float. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedFloat.

import androidx.ui.animation.animate
import androidx.ui.core.drawOpacity
import androidx.ui.foundation.Box
import androidx.ui.foundation.Text
import androidx.ui.layout.fillMaxSize

Box(Modifier.fillMaxSize(), gravity = ContentGravity.Center) {
    val opacity = animate(if (visibility == VisibilityState.Invisible) 0f else 1f)
    Text("Visibility Transition", modifier = Modifier.drawOpacity(opacity))
}
Parameters
target: Float Target value of the animation
animBuilder: AnimationBuilder<Float> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
visibilityThreshold: Float = 0.01f An optional threshold for deciding when the animation value is considered close enough to the target.
endListener: (Float) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: Color,
    animBuilder: AnimationBuilder<Color> = remember { PhysicsBuilder() },
    endListener: (Color) -> Unit = null
): Color

Fire-and-forget animation Composable for Color. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedColor.

import androidx.ui.animation.animate
import androidx.ui.foundation.Box
import androidx.ui.foundation.Text
import androidx.ui.layout.fillMaxSize

Box(Modifier.fillMaxSize(), gravity = ContentGravity.Center) {
    val textColor = animate(if (enabled) Color.Black else Color.Gray)
    Text("Visibility Transition", color = textColor)
}
Parameters
target: Color Target value of the animation
animBuilder: AnimationBuilder<Color> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (Color) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: Dp,
    animBuilder: AnimationBuilder<Dp> = remember { PhysicsBuilder() },
    endListener: (Dp) -> Unit = null
): Dp

Fire-and-forget animation Composable for Dp. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

    val height : Dp = animate(if (collapsed) 10.dp else 20.dp)
Parameters
target: Dp Target value of the animation
animBuilder: AnimationBuilder<Dp> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (Dp) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: Position,
    animBuilder: AnimationBuilder<Position> = remember { PhysicsBuilder() },
    endListener: (Position) -> Unit = null
): Position

Fire-and-forget animation Composable for Position. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

    val position : Position = animate(
        if (selected) Position(0.dp, 0.dp) else Position(20.dp, 20.dp))
Parameters
target: Position Target value of the animation
animBuilder: AnimationBuilder<Position> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (Position) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: Size,
    animBuilder: AnimationBuilder<Size> = remember { PhysicsBuilder() },
    endListener: (Size) -> Unit = null
): Size

Fire-and-forget animation Composable for Size. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

    val size : Size = animate(
        if (selected) Size(20f, 20f) else Size(10f, 10f))
Parameters
target: Size Target value of the animation
animBuilder: AnimationBuilder<Size> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (Size) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: Bounds,
    animBuilder: AnimationBuilder<Bounds> = remember { PhysicsBuilder() },
    endListener: (Bounds) -> Unit = null
): Bounds

Fire-and-forget animation Composable for Bounds. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

    val bounds : Bounds = animate(
        if (collapsed) Bounds(0.dp, 0.dp, 10.dp, 20.dp) else Bounds(0.dp, 0.dp, 100.dp, 200.dp))
Parameters
target: Bounds Target value of the animation
animBuilder: AnimationBuilder<Bounds> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (Bounds) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: Px,
    animBuilder: AnimationBuilder<Px> = remember { PhysicsBuilder() },
    endListener: (Px) -> Unit = null
): Px

Fire-and-forget animation Composable for Px. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

    val height : Px = animate(if (collapsed) 10.px else 20.px)
Parameters
target: Px Target value of the animation
animBuilder: AnimationBuilder<Px> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (Px) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: PxSize,
    animBuilder: AnimationBuilder<PxSize> = remember { PhysicsBuilder() },
    endListener: (PxSize) -> Unit = null
): PxSize

Fire-and-forget animation Composable for PxSize. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

    val size : PxSize = animate(if (selected) PxSize(20.px, 20.px) else PxSize(10.px, 10.px))
Parameters
target: PxSize Target value of the animation
animBuilder: AnimationBuilder<PxSize> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (PxSize) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: PxPosition,
    animBuilder: AnimationBuilder<PxPosition> = remember { PhysicsBuilder() },
    endListener: (PxPosition) -> Unit = null
): PxPosition

Fire-and-forget animation Composable for PxPosition. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

    val position : PxPosition = animate(
        if (selected) PxPosition(0.px, 0.px) else PxPosition(20.px, 20.px))
Parameters
target: PxPosition Target value of the animation
animBuilder: AnimationBuilder<PxPosition> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (PxPosition) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: PxBounds,
    animBuilder: AnimationBuilder<PxBounds> = remember { PhysicsBuilder() },
    endListener: (PxBounds) -> Unit = null
): PxBounds

Fire-and-forget animation Composable for PxBounds. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

    val bounds : PxBounds = animate(
        if (enabled) PxBounds(0.px, 0.px, 100.px, 100.px) else PxBounds(8.px, 8.px, 80.px, 80.px))
Parameters
target: PxBounds Target value of the animation
animBuilder: AnimationBuilder<PxBounds> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (PxBounds) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: IntPx,
    animBuilder: AnimationBuilder<IntPx> = remember { PhysicsBuilder() },
    endListener: (IntPx) -> Unit = null
): IntPx

Fire-and-forget animation Composable for IntPx. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

Parameters
target: IntPx Target value of the animation
animBuilder: AnimationBuilder<IntPx> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (IntPx) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: IntPxPosition,
    animBuilder: AnimationBuilder<IntPxPosition> = remember { PhysicsBuilder() },
    endListener: (IntPxPosition) -> Unit = null
): IntPxPosition

Fire-and-forget animation Composable for IntPxPosition. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

Parameters
target: IntPxPosition Target value of the animation
animBuilder: AnimationBuilder<IntPxPosition> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (IntPxPosition) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: IntPxSize,
    animBuilder: AnimationBuilder<IntPxSize> = remember { PhysicsBuilder() },
    endListener: (IntPxSize) -> Unit = null
): IntPxSize

Fire-and-forget animation Composable for IntPxSize. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

Parameters
target: IntPxSize Target value of the animation
animBuilder: AnimationBuilder<IntPxSize> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (IntPxSize) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun animate(
    target: IntPxBounds,
    animBuilder: AnimationBuilder<IntPxBounds> = remember { PhysicsBuilder() },
    endListener: (IntPxBounds) -> Unit = null
): IntPxBounds

Fire-and-forget animation Composable for IntPxBounds. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

Parameters
target: IntPxBounds Target value of the animation
animBuilder: AnimationBuilder<IntPxBounds> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
endListener: (IntPxBounds) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun <T : AnimationVector> animate(
    target: T,
    animBuilder: AnimationBuilder<T> = remember { PhysicsBuilder() },
    visibilityThreshold: T? = null,
    endListener: (T) -> Unit = null
): T

Fire-and-forget animation Composable for AnimationVector. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

Parameters
target: T Target value of the animation
animBuilder: AnimationBuilder<T> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
visibilityThreshold: T? = null An optional threshold to define when the animation value can be considered close enough to the target to end the animation.
endListener: (T) -> Unit = null An optional end listener to get notified when the animation is finished.

animate

@Composable fun <T, V : AnimationVector> animate(
    target: T,
    converter: TwoWayConverter<T, V>,
    animBuilder: AnimationBuilder<T> = remember { PhysicsBuilder() },
    visibilityThreshold: V? = null,
    endListener: (T) -> Unit = null
): T

Fire-and-forget animation Composable for any value. Once such an animation is created, it will be positionally memoized, like other @Composables. To trigger the animation, or alter the course of the animation, simply supply a different target to the Composable.

Note, animate is for simple animations that cannot be canceled. For cancellable animations see animatedValue.

import androidx.animation.AnimationVector2D
import androidx.animation.TwoWayConverter
import androidx.compose.remember
import androidx.ui.animation.animate
import androidx.ui.foundation.Box
import androidx.ui.foundation.drawBackground
import androidx.ui.layout.preferredSize

val mySize = remember(enabled) {
    if (enabled) {
        MySize(500.dp, 500.dp)
    } else {
        MySize(100.dp, 100.dp)
    }
}
val animSize = animate<MySize, AnimationVector2D>(mySize, TwoWayConverter(
    convertToVector = { AnimationVector2D(it.width.value, it.height.value) },
    convertFromVector = { MySize(it.v1.dp, it.v2.dp) }
))
Box(Modifier.preferredSize(animSize.width, animSize.height).drawBackground(Color.Red))
Parameters
target: T Target value of the animation
animBuilder: AnimationBuilder<T> = remember { PhysicsBuilder() } The animation that will be used to change the value through time. Physics animation will be used by default.
visibilityThreshold: V? = null An optional threshold to define when the animation value can be considered close enough to the target to end the animation.
endListener: (T) -> Unit = null An optional end listener to get notified when the animation is finished.

animatedColor

@Composable fun animatedColor(
    initVal: Color,
    clock: AnimationClockObservable = AnimationClockAmbient.current
): AnimatedValue<Color, AnimationVector4D>

The animatedValue effect creates an AnimatedValue of Color and positionally memoizes it. When the AnimatedValue object gets its value updated, components that rely on that value will be automatically recomposed.

Parameters
initVal: Color Initial value to set AnimatedValue to.

animatedFloat

@Composable fun animatedFloat(
    initVal: Float,
    visibilityThreshold: Float = Spring.DefaultDisplacementThreshold,
    clock: AnimationClockObservable = AnimationClockAmbient.current
): AnimatedFloat

The animatedValue effect creates an AnimatedFloat and positionally memoizes it. When the AnimatedFloat object gets its value updated, components that rely on that value will be automatically recomposed.

Parameters
initVal: Float Initial value to set AnimatedFloat to.

animatedValue

@Composable fun <T, V : AnimationVector> animatedValue(
    initVal: T,
    converter: TwoWayConverter<T, V>,
    visibilityThreshold: V? = null,
    clock: AnimationClockObservable = AnimationClockAmbient.current
): AnimatedValue<T, V>

The animatedValue effect creates an AnimatedValue and positionally memoizes it. When the AnimatedValue object gets its value updated, components that rely on that value will be automatically recomposed.

Parameters
initVal: T Initial value to set AnimatedValue to.
converter: TwoWayConverter<T, V> A value type converter for transforming any type T to an animatable type (i.e. Floats, Vector2D, Vector3D, etc)
visibilityThreshold: V? = null Visibility threshold for the animatedValue to consider itself finished.

Top-level properties

BoundsToVectorConverter

val BoundsToVectorConverter: TwoWayConverter<Bounds, AnimationVector4D>

A type converter that converts a Bounds to a AnimationVector4D, and vice versa.

ColorToVectorConverter

val ColorToVectorConverter: (colorSpace: ColorSpace) -> TwoWayConverter<Color, AnimationVector4D>

A lambda that takes a ColorSpace and returns a converter that can both convert a Color to a AnimationVector4D, and convert a AnimationVector4D) back to a Color in the given ColorSpace.

DpToVectorConverter

val DpToVectorConverter: TwoWayConverter<Dp, AnimationVector1D>

A type converter that converts a Dp to a AnimationVector1D, and vice versa.

IntPxBoundsToVectorConverter

val IntPxBoundsToVectorConverter: TwoWayConverter<IntPxBounds, AnimationVector4D>

A type converter that converts a IntPxBounds to a AnimationVector4D, and vice versa.

IntPxPositionToVectorConverter

val IntPxPositionToVectorConverter: TwoWayConverter<IntPxPosition, AnimationVector2D>

A type converter that converts a IntPxPosition to a AnimationVector2D, and vice versa.

IntPxSizeToVectorConverter

val IntPxSizeToVectorConverter: TwoWayConverter<IntPxSize, AnimationVector2D>

A type converter that converts a IntPxSize to a AnimationVector2D, and vice versa.

IntPxToVectorConverter

val IntPxToVectorConverter: TwoWayConverter<IntPx, AnimationVector1D>

A type converter that converts a Px to a AnimationVector1D, and vice versa.

PositionToVectorConverter

val PositionToVectorConverter: TwoWayConverter<Position, AnimationVector2D>

A type converter that converts a Position to a AnimationVector2D, and vice versa.

PxBoundsToVectorConverter

val PxBoundsToVectorConverter: TwoWayConverter<PxBounds, AnimationVector4D>

A type converter that converts a PxBounds to a AnimationVector4D, and vice versa.

PxPositionToVectorConverter

val PxPositionToVectorConverter: TwoWayConverter<PxPosition, AnimationVector2D>

A type converter that converts a PxPosition to a AnimationVector2D, and vice versa.

PxSizeToVectorConverter

val PxSizeToVectorConverter: TwoWayConverter<PxSize, AnimationVector2D>

A type converter that converts a PxSize to a AnimationVector2D, and vice versa.

PxToVectorConverter

val PxToVectorConverter: TwoWayConverter<Px, AnimationVector1D>

A type converter that converts a Px to a AnimationVector1D, and vice versa.

RectToVectorConverter

val RectToVectorConverter: TwoWayConverter<Rect, AnimationVector4D>

A type converter that converts a Rect to a AnimationVector4D, and vice versa.

SizeToVectorConverter

val SizeToVectorConverter: TwoWayConverter<Size, AnimationVector2D>

A type converter that converts a Size to a AnimationVector2D, and vice versa.

transitionsEnabled

var transitionsEnabled: Boolean

Stores the enabled state for Transition animations. Useful for tests to disable animations and have reliable screenshot tests.

Extension functions

asDisposableClock

@Composable fun AnimationClockObservable.asDisposableClock(): DisposableAnimationClock

Return a new AnimationClockObservable wrapping this one that will auto-unsubscribe all AnimationClockObservers when this call leaves the composition, preventing clock subscriptions from persisting beyond the composition lifecycle.

If you are creating an animation object during composition that will subscribe to an AnimationClockObservable or otherwise hold a long-lived reference to one to subscribe to later, create that object with a clock returned by this method.