Skip to content

Unable to set position in onAppear() #13

@BeBeBerr

Description

@BeBeBerr

Hi, thanks for the great library.

I found when calling the proxy.move function in onAppear, it doesn't correctly set the position. My code is like this:

struct ConfettiView: View {
    var body: some View {
        VortexViewReader { proxy in
            ZStack {
                Text("Tap anywhere to create confetti.")

                VortexView(.confetti.makeUniqueCopy()) {
                    Rectangle()
                        .fill(.white)
                        .frame(width: 16, height: 16)
                        .tag("square")

                    Circle()
                        .fill(.white)
                        .frame(width: 16)
                        .tag("circle")
                }
                .onTapGesture { location in
                    proxy.move(to: location) // works fine
                    proxy.burst()
                }
                .onAppear {
                    proxy.move(to: CGPoint(x: 0, y: 0)) // doesn't work
                    proxy.burst()
                }
            }
        }
        .navigationSubtitle("Demonstrates on-demand particle bursting")
        .ignoresSafeArea(edges: .top)
    }
}

I think the reason is that the nearestVortexSystem has not been set during onAppear.

What I want is to set an initial position for burst. Is there any workaround? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions