-
Notifications
You must be signed in to change notification settings - Fork 101
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
Using ForEach, the view on the interface shows the same two sets #6
Comments
Looks like a state re-rendering problem: see here. You might need to move everything in your popover into a separate .popover(present: $present) {
PopoverView(sk_current: $sk_current)
}
/// ...
struct PopoverView: View {
@Binding var sk_current: WhateverSK_CurrentIs
var body: some View {
VStack(spacing: CGFloat.bl_4.double) {
Text("📅 日历")
.modifier(SK_16(textColor: Color.t_p_c, weight: .bold))
DatePicker("",
selection: $sk_current.selectedDate, displayedComponents: .date)
.datePickerStyle(GraphicalDatePickerStyle())
.accentColor(.blue_c)
}
.frame(maxWidth: 320)
.padding(.top, CGFloat.bl_4.custom(num: 5))
.padding(.horizontal, CGFloat.bl_4.custom(num: 5))
.background(.bar)
.cornerRadius(12)
.shadow(radius: 20)
.scaleEffect(expanding ? 0.95 : 1)
}
} |
@wisepmlin if that doesn't work, can you show a image of what you're getting currently? Thanks. |
Ah, I see. When you set @State var present = false /// you have 1 single property for all the popovers! Here's a simplified example of what you're doing currently. struct ContentView: View {
@State var present = false
var body: some View {
VStack(spacing: 80) {
ForEach(0..<3) { index in
Button {
present = true /// when you set this to `true`, all the popovers will present
} label: {
Text("Button #\(index)")
}
.popover(present: $present) { /// all of the popovers use the same property
Text("Popover #\(index)")
.padding()
.background(Color.blue)
.cornerRadius(16)
}
}
}
}
} Instead, since you have multiple popovers, you'll need to use the struct ContentView: View {
@State var selection: String? /// keeps track of which popover is being presented.
var body: some View {
VStack(spacing: 80) {
ForEach(0..<3) { index in
Button {
selection = "\(index)" /// set `selection` to the current iteration's tag
} label: {
Text("Button #\(index)")
}
/// will be presented when `selection` == `tag`
.popover(selection: $selection, tag: "\(index)") {
Text("Popover #\(index)")
.padding()
.background(Color.blue)
.cornerRadius(16)
}
}
}
}
} More info if you're interested
|
First of all, your toolkit is great! Thanks for the open source |
Thanks! Yeah that would work too, glad you found a solution. |
Using ForEach, the view on the interface shows the same two sets
The text was updated successfully, but these errors were encountered: