mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:02:10 +00:00
Autofocus emoji search and send the first result with the return key on macOS. (#3644)
* Autofocus emoji search and send the first result with the return key on macOS. * Add an extra condition to make sure the user has entered a search string before sending.
This commit is contained in:
@@ -51,6 +51,8 @@ struct EmojiPickerScreen: View {
|
||||
.toolbar { toolbar }
|
||||
.isSearching($isSearching)
|
||||
.searchable(text: $searchString, placement: .navigationBarDrawer(displayMode: .always))
|
||||
.focusSearchIfHardwareKeyboardAvailable()
|
||||
.onSubmit(of: .search, sendFirstEmojiOnMac)
|
||||
.compoundSearchField()
|
||||
}
|
||||
.presentationDetents([.medium, .large])
|
||||
@@ -76,6 +78,15 @@ struct EmojiPickerScreen: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sendFirstEmojiOnMac() {
|
||||
// No sure-fire way to detect that the submit came from a h/w keyboard on iOS/iPadOS.
|
||||
guard ProcessInfo.processInfo.isiOSAppOnMac else { return }
|
||||
|
||||
if !searchString.isBlank, let emoji = context.viewState.categories.first?.emojis.first {
|
||||
context.send(viewAction: .emojiTapped(emoji: emoji))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
Reference in New Issue
Block a user