From b5c8a38b9b90092914a2c05c0cc87bac6b93aa5a Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 22 Nov 2022 11:06:21 -0500 Subject: [PATCH] Add preference for using twitter-style keyboard --- Tusker/Preferences/Preferences.swift | 4 ++++ Tusker/Screens/Compose/MainComposeTextView.swift | 2 ++ Tusker/Screens/Preferences/ComposingPrefsView.swift | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 1f68f7b589..5f380d14bf 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -50,6 +50,7 @@ class Preferences: Codable, ObservableObject { self.requireAttachmentDescriptions = try container.decode(Bool.self, forKey: .requireAttachmentDescriptions) self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode) self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger) + self.useTwitterKeyboard = try container.decodeIfPresent(Bool.self, forKey: .useTwitterKeyboard) ?? false self.blurAllMedia = try container.decode(Bool.self, forKey: .blurAllMedia) self.blurMediaBehindContentWarning = try container.decodeIfPresent(Bool.self, forKey: .blurMediaBehindContentWarning) ?? true @@ -91,6 +92,7 @@ class Preferences: Codable, ObservableObject { try container.encode(requireAttachmentDescriptions, forKey: .requireAttachmentDescriptions) try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode) try container.encode(mentionReblogger, forKey: .mentionReblogger) + try container.encode(useTwitterKeyboard, forKey: .useTwitterKeyboard) try container.encode(blurAllMedia, forKey: .blurAllMedia) try container.encode(blurMediaBehindContentWarning, forKey: .blurMediaBehindContentWarning) @@ -131,6 +133,7 @@ class Preferences: Codable, ObservableObject { @Published var requireAttachmentDescriptions = false @Published var contentWarningCopyMode = ContentWarningCopyMode.asIs @Published var mentionReblogger = false + @Published var useTwitterKeyboard = false // MARK: Media @Published var blurAllMedia = false { @@ -181,6 +184,7 @@ class Preferences: Codable, ObservableObject { case requireAttachmentDescriptions case contentWarningCopyMode case mentionReblogger + case useTwitterKeyboard case blurAllMedia case blurMediaBehindContentWarning diff --git a/Tusker/Screens/Compose/MainComposeTextView.swift b/Tusker/Screens/Compose/MainComposeTextView.swift index 63617f3399..7bef6b67ba 100644 --- a/Tusker/Screens/Compose/MainComposeTextView.swift +++ b/Tusker/Screens/Compose/MainComposeTextView.swift @@ -79,6 +79,7 @@ struct MainComposeWrappedTextView: UIViewRepresentable { @EnvironmentObject var uiState: ComposeUIState @EnvironmentObject var mastodonController: MastodonController + @ObservedObject var preferences = Preferences.shared @Environment(\.isEnabled) var isEnabled: Bool func makeUIView(context: Context) -> UITextView { @@ -101,6 +102,7 @@ struct MainComposeWrappedTextView: UIViewRepresentable { } uiView.isEditable = isEnabled + uiView.keyboardType = preferences.useTwitterKeyboard ? .twitter : .default context.coordinator.text = $text context.coordinator.didChange = textDidChange diff --git a/Tusker/Screens/Preferences/ComposingPrefsView.swift b/Tusker/Screens/Preferences/ComposingPrefsView.swift index ef7f35aef6..a6a6c13726 100644 --- a/Tusker/Screens/Preferences/ComposingPrefsView.swift +++ b/Tusker/Screens/Preferences/ComposingPrefsView.swift @@ -17,6 +17,7 @@ struct ComposingPrefsView: View { visibilitySection composingSection replyingSection + writingSection } .listStyle(InsetGroupedListStyle()) .navigationBarTitle("Composing") @@ -75,6 +76,14 @@ struct ComposingPrefsView: View { } } } + + var writingSection: some View { + Section { + Toggle(isOn: $preferences.useTwitterKeyboard) { + Text("Show @ and # on Keyboard") + } + } + } }