From 4d8088d0d0e6e52e5c1cecf00f4417ee5e2b250f Mon Sep 17 00:00:00 2001 From: Jonathan Milligan Date: Sat, 7 Jan 2023 13:21:15 -0700 Subject: [PATCH] feat: Add left handed option for post button Added a left handed toggle in the app configuration section to turn on left handed mode which moves the post button to the left side. Nearly done. May just need to fix an initialization bug. Closes: #282 Changelog-Added: Left hand option for post button --- damus/ContentView.swift | 2 +- damus/Models/UserSettingsStore.swift | 15 ++++++++++++--- damus/Views/ConfigView.swift | 9 +++++++-- damus/Views/PostButton.swift | 14 ++++++++++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index b51ada2a..90b4c1cc 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -121,7 +121,7 @@ struct ContentView: View { TimelineView(events: $home.events, loading: $home.loading, damus: damus, show_friend_icon: false, filter: filter) } if privkey != nil { - PostButtonContainer { + PostButtonContainer(userSettings: user_settings) { self.active_sheet = .post } } diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift index afd2efde..fd09d3d2 100644 --- a/damus/Models/UserSettingsStore.swift +++ b/damus/Models/UserSettingsStore.swift @@ -20,13 +20,22 @@ class UserSettingsStore: ObservableObject { } } + @Published var left_handed: Bool { + didSet { + UserDefaults.standard.set(left_handed, forKey: "left_handed") + } + } + init() { if let defaultWalletName = UserDefaults.standard.string(forKey: "default_wallet"), - let default_wallet = Wallet(rawValue: defaultWalletName) { + let default_wallet = Wallet(rawValue: defaultWalletName) + { self.default_wallet = default_wallet } else { - self.default_wallet = .system_default_wallet + default_wallet = .system_default_wallet } - self.show_wallet_selector = UserDefaults.standard.object(forKey: "show_wallet_selector") as? Bool ?? true + show_wallet_selector = UserDefaults.standard.object(forKey: "show_wallet_selector") as? Bool ?? true + + left_handed = UserDefaults.standard.object(forKey: "left_handed") as? Bool ?? false } } diff --git a/damus/Views/ConfigView.swift b/damus/Views/ConfigView.swift index d74cbeb0..2ae2b319 100644 --- a/damus/Views/ConfigView.swift +++ b/damus/Views/ConfigView.swift @@ -115,7 +115,12 @@ struct ConfigView: View { } } } - + + Section(NSLocalizedString("Left Handed", comment: "Moves the post button to the left side of the screen")) { + Toggle(NSLocalizedString("Left Handed", comment: "Moves the post button to the left side of the screen"), isOn: $user_settings.left_handed) + .toggleStyle(.switch) + } + Section(NSLocalizedString("Clear Cache", comment: "Section title for clearing cached data.")) { Button(NSLocalizedString("Clear", comment: "Button for clearing cached data.")) { KingfisherManager.shared.cache.clearMemoryCache() @@ -123,7 +128,7 @@ struct ConfigView: View { KingfisherManager.shared.cache.cleanExpiredDiskCache() } } - + Section(NSLocalizedString("Reset", comment: "Section title for resetting the user")) { Button(NSLocalizedString("Logout", comment: "Button to logout the user.")) { confirm_logout = true diff --git a/damus/Views/PostButton.swift b/damus/Views/PostButton.swift index 14d1fd91..4e220815 100644 --- a/damus/Views/PostButton.swift +++ b/damus/Views/PostButton.swift @@ -34,14 +34,20 @@ func PostButton(action: @escaping () -> ()) -> some View { .keyboardShortcut("n", modifiers: [.command, .shift]) } -func PostButtonContainer(action: @escaping () -> ()) -> some View { +func PostButtonContainer(userSettings: UserSettingsStore, action: @escaping () -> Void) -> some View { + let is_left_handed = userSettings.left_handed.self return VStack { Spacer() HStack { - Spacer() - PostButton(action: action) + if is_left_handed != true { + Spacer() + + PostButton(action: action) + } else { + PostButton(action: action) + Spacer() + } } } } -