Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Fix dictation regression on iOS #49056

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note, I had originally attempted to call super.insertDictationResult(), so that we could rely on the default function, but this caused a crash.

} else {
let objectPlaceholder = "\u{FFFC}"
isInsertingDictationResult = false
self.text = self.text?.replacingOccurrences(of: objectPlaceholder, with: dictationText)
Copy link
Contributor Author

@SiobhyB SiobhyB Mar 15, 2023

Choose a reason for hiding this comment

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

It's necessary to keep this in place for older version, as without it an obj icon is added along with dictated text.

Screenshot taken from an iPhone 6s (iOS 15.5) emulator with the hack removed:

Simulator Screen Shot - iPhone 6s (15 5) - 2023-03-15 at 17 33 15

}
}

// MARK: - Custom Edit Intercepts
Expand Down