Hi all,
Is there a way to be notified when the SwiftUI ColorPicker presents and/or dismisses its popover?
The standard .onAppear() and .onDisappear() on the ColorPicker() get called when the BUTTON for the colorpicker is presented, rather than when the popover is presented.
ColorPicker("Mine", selection: $colorValue)
.onAppear(perform: {
// Do something when the popover is presented
})
.onDisappear(perform: {
// Do something when the popover is dismissed
})
The .onAppear()
and .onDisappear()
in this code get called when the ColorPicker BUTTON appears, which is not what I'm wanting.
I'm using the .onAppear()
and .onDisappear()
with the standard .popover(isPresented: ...)
view modifier to begin/end undo grouping elsewhere in my View which works well.
Button(...)
.popover(isPresented: $showWidthSlider) {
HStack(spacing: 0) {
...
}
.onAppear(perform: {
self.model.beginUndoGrouping()
})
.onDisappear(perform: {
self.model.endUndoGrouping()
})
I'm relatively new to SwiftUI so I'm hoping I'm just missing something obvious.
Cheers!