I want my icon to be light/dark according to current system color theme, but I never seem to get the dark color image to show, its always the light image that shows up
MenuBarExtra("", image: "my image name") {
Text("some text")
}
also tried using label but the "MenuLogoView" does not get any callback while switching color mode:
MenuBarExtra {
MenuView(model: menuModel)
} label: {
MenuLogoView()
}
struct MenuLogoView: View {
@Environment(\.colorScheme) var colorScheme
...
but "colorScheme" never seems to change
if I use the same image resource in other places of my code it works well for both light/dark color theme modes
It appears that, indeed,
MenuBarExtra
s don't get theircolorScheme
environment set to the correct value. I'm not sure if this is intentional.One rather nasty trick is to get the "real" color scheme from one of your
View
s in a window.where
ContentView
is:An alternative way is to detect dark mode by reading
UserDefaults
with@AppStorage
, described here. This would work even if your app is only aMenuBarExtra
. The user defaults updates a bit more slowly than the@Environment
approach above though, from my experience.