diff --git a/Tusker/Screens/Compose/ComposeAutocompleteView.swift b/Tusker/Screens/Compose/ComposeAutocompleteView.swift index 07672a106e..5792624b69 100644 --- a/Tusker/Screens/Compose/ComposeAutocompleteView.swift +++ b/Tusker/Screens/Compose/ComposeAutocompleteView.swift @@ -234,6 +234,12 @@ struct ComposeAutocompleteEmojisView: View { } else { horizontalScrollView .onReceive(uiState.$autocompleteState, perform: queryChanged) + .onAppear { + if uiState.shouldEmojiAutocompletionBeginExpanded { + expanded = true + uiState.shouldEmojiAutocompletionBeginExpanded = false + } + } } } diff --git a/Tusker/Screens/Compose/ComposeEmojiTextField.swift b/Tusker/Screens/Compose/ComposeEmojiTextField.swift index 0517ea0945..d003f5eb35 100644 --- a/Tusker/Screens/Compose/ComposeEmojiTextField.swift +++ b/Tusker/Screens/Compose/ComposeEmojiTextField.swift @@ -84,7 +84,7 @@ struct ComposeEmojiTextField: UIViewRepresentable { var skipSettingTextOnNextUpdate = false var toolbarElements: [ComposeUIState.ToolbarElement] { - [] + [.emojiPicker] } @objc func didChange(_ textField: UITextField) { @@ -108,6 +108,10 @@ struct ComposeEmojiTextField: UIViewRepresentable { self.updateAutocompleteState(textField: textField) } + func beginAutocompletingEmoji() { + textField?.insertText(":") + } + func applyFormat(_ format: StatusFormat) { } diff --git a/Tusker/Screens/Compose/ComposeHostingController.swift b/Tusker/Screens/Compose/ComposeHostingController.swift index e4f8d68eb3..d3c31b9257 100644 --- a/Tusker/Screens/Compose/ComposeHostingController.swift +++ b/Tusker/Screens/Compose/ComposeHostingController.swift @@ -145,6 +145,10 @@ class ComposeHostingController: UIHostingController { localOnlyChanged(draft.localOnly) } + if input?.toolbarElements.contains(.emojiPicker) == true { + items.append(UIBarButtonItem(image: UIImage(systemName: "face.smiling"), style: .plain, target: self, action: #selector(emojiPickerButtonPressed))) + } + items.append(UIBarButtonItem(systemItem: .flexibleSpace)) if input?.toolbarElements.contains(.formattingButtons) == true, @@ -311,6 +315,14 @@ class ComposeHostingController: UIHostingController { uiState.currentInput?.applyFormat(format) } + @objc func emojiPickerButtonPressed() { + guard uiState.autocompleteState == nil else { + return + } + uiState.shouldEmojiAutocompletionBeginExpanded = true + uiState.currentInput?.beginAutocompletingEmoji() + } + @objc func draftsButtonPresed() { let draftsVC = DraftsTableViewController(account: mastodonController.accountInfo!, exclude: draft) draftsVC.delegate = self diff --git a/Tusker/Screens/Compose/ComposeUIState.swift b/Tusker/Screens/Compose/ComposeUIState.swift index 9e625324e9..0e038b73c6 100644 --- a/Tusker/Screens/Compose/ComposeUIState.swift +++ b/Tusker/Screens/Compose/ComposeUIState.swift @@ -31,6 +31,7 @@ class ComposeUIState: ObservableObject { var composeDrawingMode: ComposeDrawingMode? + var shouldEmojiAutocompletionBeginExpanded = false @Published var currentInput: ComposeInput? init(draft: Draft) { @@ -66,10 +67,13 @@ protocol ComposeInput: AnyObject { func autocomplete(with string: String) func applyFormat(_ format: StatusFormat) + + func beginAutocompletingEmoji() } extension ComposeUIState { enum ToolbarElement { + case emojiPicker case formattingButtons } } diff --git a/Tusker/Screens/Compose/MainComposeTextView.swift b/Tusker/Screens/Compose/MainComposeTextView.swift index 3795a6b632..2ab8b872d7 100644 --- a/Tusker/Screens/Compose/MainComposeTextView.swift +++ b/Tusker/Screens/Compose/MainComposeTextView.swift @@ -139,7 +139,7 @@ struct MainComposeWrappedTextView: UIViewRepresentable { var skipSettingTextOnNextUpdate = false var toolbarElements: [ComposeUIState.ToolbarElement] { - [.formattingButtons] + [.emojiPicker, .formattingButtons] } init(text: Binding, uiState: ComposeUIState, didChange: @escaping (UITextView) -> Void) { @@ -193,6 +193,10 @@ struct MainComposeWrappedTextView: UIViewRepresentable { self.updateAutocompleteState() } + func beginAutocompletingEmoji() { + textView?.insertText(":") + } + func autocomplete(with string: String) { guard let textView = textView, let text = textView.text,