Skip to content

Start playing the full animation after setting the ColorValueProvider at the last frame #2645

@Med1D

Description

@Med1D

I have playOnce animation with context:
playFrom = 0
playTo = 30

When I set the ColorValueProvider with currentFrame = 29.5..<30.0, the layer starts playing the full animation.

In my point of view, there should be trunc or floor. What do you think about it?

// The animation should start playing from the `currentFrame`,
// if `currentFrame` is included in the time range being played.
let lowerBoundTime = min(animationContext.playFrom, animationContext.playTo)
let upperBoundTime = max(animationContext.playFrom, animationContext.playTo)
if (lowerBoundTime ..< upperBoundTime).contains(round(currentFrame)) {
// We have to configure this differently depending on the loop mode:
switch loopMode {
// When playing exactly once (and not looping), we can just set the
// `playFrom` time to be the `currentFrame`. Since the animation duration
// is based on `playFrom` and `playTo`, this automatically truncates the
// duration (so the animation stops playing at `playFrom`).
// - Don't do this if the animation is already at that frame
// (e.g. playing from 100% to 0% when the animation is already at 0%)
// since that would cause the animation to not play at all.
case .playOnce:
if animationContext.playTo != currentFrame {
animationContext.playFrom = currentFrame
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions