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

Fix: VortexViewReader sometimes can't extract VortexSystem #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jackynb
Copy link

@jackynb jackynb commented Jan 31, 2025

Issue:

VortexViewReader cannot extract VortexSystem when VortexView has a sibling of ForEach view that is inside a layout container (for example, HStack { ForEach... }) or a TextField view (Mentioned in #20), which causes functions on VortexProxy fail to run (for example, VortexProxy.burst()).

This issue was addressed by #19 but wasn't merged because it will cause VortexViewReader to read the last VortexSystem rather than the first when it contains multiple VortexView.

Minimal Reproducible Example

struct VortexViewReaderTestView: View {
    var body: some View {
        VortexViewReader { vortexView in
            VStack {
                ZStack {
                    //  Remove `TextField` and `ForEach` for `VortexViewReader` to work again.
                    TextField("", text: .constant("Hello"))
                    HStack {
                        ForEach(0..<3) { _ in
                            Text("Hello")
                        }
                    }
                    
                    VortexView(.confetti) {
                        Rectangle()
                            .fill(.white)
                            .frame(width: 16, height: 16)
                            .tag("square")

                        Circle()
                            .fill(.white)
                            .frame(width: 16)
                            .tag("circle")
                    }
                }
                
                Button("Burst") {
                    print("Particle System: \(String(describing: vortexView.particleSystem))")
                    vortexView.burst()  //  This will fail.
                }
            }
        }
    }
}

#Preview {
    VortexViewReaderTestView()
}

Result

This slightly modified pull request allows VortexViewReader to extract the first VortexSystem in the above situation.

And thanks for making this awesome library :D

@jackynb jackynb marked this pull request as ready for review January 31, 2025 15:35
@jackynb jackynb changed the title Fix: VortexViewReader can't extract VortexSystem Fix: VortexViewReader sometimes can't extract VortexSystem Jan 31, 2025
This occurs when `VortexView` has a sibling of `ForEach` view that is inside a layout container (for example, `HStack { ForEach... }`) or a `TextField` view.
@jackynb jackynb force-pushed the fix/vortex-view-reader-cannot-read branch from 9709fdc to 906dcda Compare January 31, 2025 16:20
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

Successfully merging this pull request may close these issues.

1 participant