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

Support stateful popovers #73

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

Conversation

raysarebest
Copy link

Let's say I have a popover that looks like this:

import Popovers
import SwiftUI

struct BasicView: View {
    @State var present = false

    var body: some View {
        ExampleRow(
            image: "square",
            title: "Basic",
            color: 0x00AEEF
        ) {
            present.toggle()
        }
        .popover(present: $present) {
            TimedRenderingView()
                .background(.thinMaterial)
        }

    }
    
    struct TimedRenderingView: View {
        @State private var data = ["Example"]
        let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
        
        var body: some View {
            VStack {
                ForEach(data, id: \.self) { line in
                    Text(line)
                }
            }
            .onReceive(timer) { _ in
                data = Array(repeating: "Example", count: .random(in: 1...10))
            }
        }
    }
}

Currently, once the popover is presented, it will never be updated, even as the data changes. This PR adds support for re-rendering the popover view when SwiftUI decides it's appropriate, such as when one or more of its state, binding, or environment properties change. This represents a partial fix for #72, specifically for cases where popover views maintain some kind of internal properties to signal the need for a re-render

This work was done as part of my day job at Chariot Solutions, LLC to help support projects for ourselves and our clients

@aheze
Copy link
Owner

aheze commented Mar 20, 2023

Interesting — sorry for getting back so late. Testing rn.

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.

None yet

3 participants