Popovers
Popovers copied to clipboard
Popover doesn't re-render its view when identity changes
Let's say I have a custom-made text field that updates its content binding on every user keystroke. Let's also say I have a popover that displays some options based on what the user has typed into that text field:
let states = ["Alabama", "Alaska", ... ]
CustomTextField("US State", $selectedState)
.popover(present: .constant(true)) {
VStack {
ForEach(states.map({ state in state.hasPrefix(selectedState) })) { state in
Text(state)
}
}
}
I would expect that the list of states displayed in the popover would update with every keystroke, but that doesn't seem to be the case. Strategically inserting debugger statements shows that the $selectedState
is definitely getting updated for every keystroke, but the view that the popover renders never updates to include the narrowed list of possible states. How can I get it to update whenever its displayed view's identity changes so I can make something like this work?