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

Commit

Permalink
Fix #8535: Code review edits
Browse files Browse the repository at this point in the history
  • Loading branch information
nik3212 committed Dec 19, 2023
1 parent 5a6580a commit bddcf50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ extension BrowserViewController {
browserViewController.dismiss(animated: true)
browserViewController.tabToolbarDidPressShare()
}
NightModeMenuButton()
NightModeMenuButton(dismiss: {
browserViewController.dismiss(animated: true)
})
MenuItemButton(icon: Image(braveSystemName: "leo.browser.bookmark-add"), title: Strings.addToMenuItem) {
browserViewController.dismiss(animated: true) {
browserViewController.openAddBookmark()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +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 @@ -22,12 +25,17 @@ struct NightModeMenuButton: View {
Toggle("", isOn: $nightMode.value)
.labelsHidden()
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.onChange(of: nightMode.value) { _ in
guard isViewDisplayed else { return }
dismiss()
}
}
.padding(.horizontal, 14)
.frame(maxWidth: .infinity, minHeight: 48.0)
.background(
Button(action: {
Preferences.General.nightModeEnabled.value.toggle()
dismiss()
}) {
Color.clear
}
Expand All @@ -36,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 bddcf50

Please sign in to comment.