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

Commit

Permalink
Fix #8535: Fix toggling night mode (#8573)
Browse files Browse the repository at this point in the history
  • Loading branch information
nik3212 authored Dec 20, 2023
1 parent 6631937 commit 72bdc51
Showing 1 changed file with 9 additions and 1 deletion.
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
}
}
}

0 comments on commit 72bdc51

Please sign in to comment.