Popovers
Popovers copied to clipboard
Support stateful popovers
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