From 43b8db22352871fcfb7dea9a813f0dedc1689bf3 Mon Sep 17 00:00:00 2001 From: Siobhan Bamber Date: Thu, 16 Mar 2023 08:56:09 +0000 Subject: [PATCH] fix: Prevent old hack causing dictation issues (#49056) By confining the hack to iOS 16 or above, we fix an issue with dictation causing content loss in later versions of iOS. --- .../ios/RNTAztecView/RCTAztecView.swift | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift b/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift index cc87ef29e9704b..dab1733c07dead 100644 --- a/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift +++ b/packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift @@ -100,8 +100,14 @@ class RCTAztecView: Aztec.TextView { /// the dictation engine refreshes the TextView with an empty string when the dictation finishes. /// This helps to avoid propagating that unwanted empty string to RN. (Solving #606) /// on `textViewDidChange` and `textViewDidChangeSelection` - private var isInsertingDictationResult = false - + private var isInsertingDictationResult: Bool = { + if #available(iOS 16, *) { + return true; + } else { + return false; + } + }() + // MARK: - Font /// Flag to enable using the defaultFont in Aztec for specific blocks @@ -358,10 +364,14 @@ class RCTAztecView: Aztec.TextView { } public override func insertDictationResult(_ dictationResult: [UIDictationPhrase]) { - let objectPlaceholder = "\u{FFFC}" let dictationText = dictationResult.reduce("") { $0 + $1.text } - isInsertingDictationResult = false - self.text = self.text?.replacingOccurrences(of: objectPlaceholder, with: dictationText) + if #available(iOS 16, *) { + insertText(dictationText) + } else { + let objectPlaceholder = "\u{FFFC}" + isInsertingDictationResult = false + self.text = self.text?.replacingOccurrences(of: objectPlaceholder, with: dictationText) + } } // MARK: - Custom Edit Intercepts