Skip to content

Commit

Permalink
fix: Prevent old hack causing dictation issues (#49056)
Browse files Browse the repository at this point in the history
By confining the hack to iOS 16 or above, we fix an issue with dictation causing content loss in later versions of iOS.
  • Loading branch information
Siobhan Bamber authored Mar 16, 2023
1 parent 8ac3b00 commit 43b8db2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/react-native-aztec/ios/RNTAztecView/RCTAztecView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit 43b8db2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 43b8db2.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4435218324
📝 Reported issues:

Please sign in to comment.