-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: key commands for external keyboards #243
base: master
Are you sure you want to change the base?
Conversation
|
||
@objc private func didDetectKeyCommand(_ keyCommand: UIKeyCommand) { | ||
if keyCommand.input == nil { return } | ||
let key = "\(String(describing: keyCommand.input!))_\(keyCommand.modifierFlags)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of this force unwrap - can we figure out better way for the key?
In my app I made it so pressing physical return key sends message and shift+return adds a new line. I believe this is how other chat apps work too. If interested I can show code of how I achieved this. |
I think this will break https://developer.apple.com/documentation/uikit/uiviewcontroller/1621439-addkeycommand I don't think this change is necessary, since key commands can already be adde |
@Janneman84 can you show me how to achieved it? |
extension InputTextView {
open override var keyCommands: [UIKeyCommand]? {
return [
//hitting return on hardware keyboard will send the message instead of carriage return
//to go to next line press shift+return
UIKeyCommand(input: "\r", modifierFlags: [], action: #selector(keyCommand_return)),
]
}
@objc private func keyCommand_return() {
//trigger send press here
}
} I use an extension but you can probably implement the override directly in InputTextView. However if you plan on it calling |
@@ -187,7 +187,6 @@ open class KeyboardManager: NSObject, UIGestureRecognizerDelegate { | |||
} | |||
} | |||
callbacks[.willHide] = { [weak self] (notification) in | |||
guard notification.isForCurrentApp else { return } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for removing this?
@@ -344,7 +344,7 @@ open class InputBarAccessoryView: UIView { | |||
// MARK: - Auto-Layout Constraint Sets | |||
|
|||
private var middleContentViewLayoutSet: NSLayoutConstraintSet? | |||
private var textViewHeightAnchor: NSLayoutConstraint? | |||
open var textViewHeightAnchor: NSLayoutConstraint? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintentional change as well?
# Conflicts: # Sources/KeyboardManager/KeyboardManager.swift
What does this implement/fix? Explain your changes.
Support for external keyboard to send messages by pressing command + enter.
On the Mac catalyst, it also supports keyboard shortcuts.
Does this close any currently open issues?
No
Where has this been tested?
Devices/Simulators: …
iPad mini 6
iOS Version: …
iOS 16.2
Swift Version: …
5.7
How to use: