From 72bdc51a80a1df6323bfff67f47672be57bba61d Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Wed, 20 Dec 2023 16:57:13 +0100 Subject: [PATCH] Fix #8535: Fix toggling night mode (#8573) --- .../BottomToolbar/Menu/NightModeMenuButton.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/NightModeMenuButton.swift b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/NightModeMenuButton.swift index 5801d18838d..134d6aaabdf 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/NightModeMenuButton.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/NightModeMenuButton.swift @@ -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( @@ -25,6 +26,7 @@ struct NightModeMenuButton: View { .labelsHidden() .toggleStyle(SwitchToggleStyle(tint: .accentColor)) .onChange(of: nightMode.value) { _ in + guard isViewDisplayed else { return } dismiss() } } @@ -42,5 +44,11 @@ struct NightModeMenuButton: View { .accessibilityElement() .accessibility(addTraits: .isButton) .accessibility(label: Text(Strings.NightMode.settingsTitle)) + .onAppear { + isViewDisplayed = true + } + .onDisappear { + isViewDisplayed = false + } } }