Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8535: Fix toggling night mode #8573

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import Preferences
/// A menu button that provides a shortcut to toggling Night Mode
struct NightModeMenuButton: View {
@ObservedObject private var nightMode = Preferences.General.nightModeEnabled
@State private var isViewDisplayed = false

var dismiss: () -> Void

var body: some View {
HStack {
MenuItemHeaderView(
Expand All @@ -25,6 +26,7 @@ struct NightModeMenuButton: View {
.labelsHidden()
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.onChange(of: nightMode.value) { _ in
guard isViewDisplayed else { return }
dismiss()
}
}
Expand All @@ -42,5 +44,11 @@ struct NightModeMenuButton: View {
.accessibilityElement()
.accessibility(addTraits: .isButton)
.accessibility(label: Text(Strings.NightMode.settingsTitle))
.onAppear {
isViewDisplayed = true
}
.onDisappear {
isViewDisplayed = false
}
}
}