From 4a21c47f4fa88003a9496b0b9c3ce17d71699af6 Mon Sep 17 00:00:00 2001 From: Jorge Bernal Date: Tue, 5 Nov 2019 12:54:39 +0100 Subject: [PATCH 1/2] Avoid buggy shouldInteractWith delegate method and disable link tap recognizer directly --- .../ios/RNTAztecView/RCTAztecView.swift | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift b/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift index 03b446dcaecee..4d5e541460700 100644 --- a/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift +++ b/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift @@ -135,6 +135,7 @@ class RCTAztecView: Aztec.TextView { textDragInteraction?.isEnabled = false storage.htmlConverter.characterToReplaceLastEmptyLine = Character(.zeroWidthSpace) shouldNotifyOfNonUserChanges = false + disableLinkTapRecognizer() } func addPlaceholder() { @@ -147,6 +148,13 @@ class RCTAztecView: Aztec.TextView { ]) } + 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() { @@ -625,20 +633,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 - } } From e2056bb5be4c0857b692c3b6cdd8548ed7599034 Mon Sep 17 00:00:00 2001 From: Jorge Bernal Date: Tue, 5 Nov 2019 13:01:49 +0100 Subject: [PATCH 2/2] Adds documentation --- react-native-aztec/ios/RNTAztecView/RCTAztecView.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift b/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift index 4d5e541460700..8cfda284f3161 100644 --- a/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift +++ b/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift @@ -148,6 +148,15 @@ 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