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,
MenuBarExtras don't get theircolorSchemeenvironment 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
Views in a window.where
ContentViewis:An alternative way is to detect dark mode by reading
UserDefaultswith@AppStorage, described here. This would work even if your app is only aMenuBarExtra. The user defaults updates a bit more slowly than the@Environmentapproach above though, from my experience.