I noticed that in my current macOS SwiftUI App setup in which a popover occurs when a button is pressed, the content of the popover appears a little pale:
In contrast, when I click into the popover, the content gets its correct color:
This seems to be corrected when I get rid of the HStack which embeds the button and the Image. Here is the code that generates the app:
import SwiftUI
struct ContentView: View {
@State var showPopup: Bool = false
@State private var users: [User] = [User(name: "Peter"), User(name: "Paul"), User(name: "Martha")]
@State var selectedUserIndex: Int = 0
var body: some View {
NavigationView {
List {
HStack {
Button(action: {
self.showPopup.toggle()
}) {
Image(systemName: "house")
Text(users[selectedUserIndex].name)
}
.popover(isPresented: $showPopup) {
List {
ForEach(users, id: \.id) { user in
Button(action: {
self.selectedUserIndex = users.firstIndex(where: {$0 === user}) ?? 0
self.showPopup.toggle()
}, label: {
Label(user.name, systemImage: "house")
})
.buttonStyle(PlainButtonStyle())
}
.onMove(perform: { indices, newOffset in
move(from: indices, to: newOffset)
})
}
}
.padding()
.frame(maxWidth: .infinity)
Image(systemName: "clock")
}
Divider()
}
Text("Detail View")
}
}
func move(from source: IndexSet, to destination: Int) {
let selected_user = users[selectedUserIndex]
users.move(fromOffsets: source, toOffset: destination)
selectedUserIndex = users.firstIndex(of: selected_user)!
}
}
class User: Identifiable, Equatable {
var id = UUID()
var name: String = ""
init(name: String) {
self.name = name
}
static func == (lhs: User, rhs: User) -> Bool {
return lhs.id == rhs.id
}
}

