Supporting extended text interactions
Share content, add replacement shortcuts, and perform other rich actions in browser text views.
Overview
When your browser’s text view conforms to the BETextInput protocol, it automatically also conforms to BEResponderEditActions. This protocol adds a collection of optional action methods your text view can implement to support extended text interactions.
To get the system’s standard behavior for an interaction, add a BETextInteraction to your custom view’s textInputView, and call the interaction’s methods in response to BEResponderEditActions.
Additionally, implement canPerformAction(_:withSender:), to return true in situations where the interaction is available, but false otherwise.
For example, to share the selected text using the standard share sheet:
class MyBrowserTextView: UIView, BETextInput, BEResponderEditActions {
func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if (action == #selector(share(_:))) {
return self.canShareSelection
}
}
func share(_ sender: Any?) {
self.textInteraction.shareText(self.selectedText, from:self.selectionRect)
}
}