Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation must have a non-nil value before starting. #33

Open
DamilolaDami opened this issue Mar 29, 2023 · 0 comments
Open

Animation must have a non-nil value before starting. #33

DamilolaDami opened this issue Mar 29, 2023 · 0 comments

Comments

@DamilolaDami
Copy link

DamilolaDami commented Mar 29, 2023

I get this error when I try to use this in swiftui: "Animation must have a non-nil value before starting."
my code is here:

`.onAppear {
offsetAnimator.value = .zero

        // The offset animator's callback will update the `offset` state variable.
        offsetAnimator.valueChanged = { newValue in
            boxOffset = newValue
        }
    }
    .offset(x: boxOffset.x, y: boxOffset.y)
    .gesture(
        DragGesture()
            .onChanged { value in
                // Update the animator's target to the new drag translation.
                offsetAnimator.target = CGPoint(x: value.translation.width, y: value.translation.height)

                // Don't animate the box's position when we're dragging it.
                offsetAnimator.mode = .nonAnimated
                offsetAnimator.start()
            }
            .onEnded { value in
                // Animate the box to its original location (i.e. with zero translation).
                offsetAnimator.target = .zero

                // We want the box to animate to its original location, so use an `animated` mode.
                // This is different than the
                offsetAnimator.mode = .animated

                // Take the velocity of the gesture, and give it to the animator.
                // This makes the throw animation feel natural and continuous.
                offsetAnimator.velocity = CGPoint(x: value.velocity.width, y: value.velocity.height)
                offsetAnimator.start()
            }
    )`

thank you for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant