Skip to content

Commit

Permalink
Merge pull request #1540 from wordpress-mobile/fix/ios13-link-tap-bug
Browse files Browse the repository at this point in the history
Fix iOS13 link tap bug
  • Loading branch information
koke authored Nov 6, 2019
2 parents ceb190d + e2056bb commit 0f0fa1c
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions react-native-aztec/ios/RNTAztecView/RCTAztecView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class RCTAztecView: Aztec.TextView {
textDragInteraction?.isEnabled = false
storage.htmlConverter.characterToReplaceLastEmptyLine = Character(.zeroWidthSpace)
shouldNotifyOfNonUserChanges = false
disableLinkTapRecognizer()
}

func addPlaceholder() {
Expand All @@ -147,6 +148,22 @@ class RCTAztecView: Aztec.TextView {
])
}

/**
This handles a bug introduced by iOS 13.0 (tested up to 13.2) where link interactions don't respect what the documentation says.

The documenatation for textView(_:shouldInteractWith:in:interaction:) says:

> Links in text views are interactive only if the text view is selectable but noneditable.

Our Aztec Text views are selectable and editable, and yet iOS was opening links on Safari when tapped.
*/
func disableLinkTapRecognizer() {
guard let recognizer = gestureRecognizers?.first(where: { $0.name == "UITextInteractionNameLinkTap" }) else {
return
}
recognizer.isEnabled = false
}

// MARK - View Height: Match to content height

override func layoutSubviews() {
Expand Down Expand Up @@ -627,20 +644,4 @@ extension RCTAztecView: UITextViewDelegate {
func textViewDidEndEditing(_ textView: UITextView) {
onBlur?([:])
}

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if #available(iOS 13.1, *) {
return false
} else if #available(iOS 13.0.0, *) {
// Sergio Estevao: This shouldn't happen in an editable textView, but it looks we have a system bug in iOS13 so we need this workaround
let position = characterRange.location
textView.selectedRange = NSRange(location: position, length: 0)
textView.typingAttributes = textView.attributedText.attributes(at: position, effectiveRange: nil)
textView.delegate?.textViewDidChangeSelection?(textView)
} else {
return false
}

return false
}
}

0 comments on commit 0f0fa1c

Please sign in to comment.