Skip to content

Commit

Permalink
Fix brave/brave-ios#8535: Fix toggling night mode (brave/brave-ios#8573)
Browse files Browse the repository at this point in the history
  • Loading branch information
nik3212 authored Dec 20, 2023
1 parent 94870c2 commit 54dc34c
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 54dc34c

Please sign in to comment.