Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
[iOS] Fix for dictation not working properly (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 authored Nov 17, 2023
1 parent 628b612 commit 876f394
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public struct WysiwygComposerView: View {

@ViewBuilder
private var placeholderView: some View {
if viewModel.isContentEmpty {
if viewModel.isContentEmpty, !viewModel.textView.isDictationRunning {
Text(placeholder)
.font(Font(UIFont.preferredFont(forTextStyle: .body)))
.foregroundColor(placeholderColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ private extension WysiwygComposerViewModel {
/// Reconciliate the content of the model with the content of the text view.
func reconciliateIfNeeded() {
do {
guard let replacement = try StringDiffer.replacement(from: attributedContent.text.htmlChars,
guard !textView.isDictationRunning,
let replacement = try StringDiffer.replacement(from: attributedContent.text.htmlChars,
to: textView.attributedText.htmlChars) else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protocol WysiwygTextViewDelegate: AnyObject {
public protocol MentionDisplayHelper { }

public class WysiwygTextView: UITextView {
private(set) var isDictationRunning = false

/// Internal delegate for the text view.
weak var wysiwygDelegate: WysiwygTextViewDelegate?

Expand All @@ -53,12 +55,42 @@ public class WysiwygTextView: UITextView {

override public init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
contentMode = .redraw
commonInit()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
commonInit()
}

private func commonInit() {
contentMode = .redraw
NotificationCenter.default.addObserver(self,
selector: #selector(textInputCurrentInputModeDidChange),
name: UITextInputMode.currentInputModeDidChangeNotification,
object: nil)
}

@objc private func textInputCurrentInputModeDidChange(notification: Notification) {
// We don't care about the input mode if this is not the first responder
guard isFirstResponder else {
return
}

guard let inputMode = textInputMode?.primaryLanguage,
inputMode == "dictation" else {
isDictationRunning = false
return
}
isDictationRunning = true
}

override public func dictationRecordingDidEnd() {
isDictationRunning = false
}

override public func dictationRecognitionFailed() {
isDictationRunning = false
}

/// Register a pill view that has been added through `NSTextAttachmentViewProvider`.
Expand Down

0 comments on commit 876f394

Please sign in to comment.