Skip to content

Commit 3184c18

Browse files
Fixed a bug with predictive keyboard text
1 parent 2cf25f1 commit 3184c18

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ open class MessageComposerViewModel: ObservableObject {
9696
didSet {
9797
if oldValue?.id != composerCommand?.id &&
9898
composerCommand?.displayInfo?.isInstant == true {
99-
// This is needed because of autocompleting text from the keyboard.
100-
// The update of the text is done in the next cycle, so it overrides
101-
// the setting of this value to empty string.
102-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { [weak self] in
103-
self?.text = ""
104-
}
99+
clearText()
105100
}
106101
if oldValue != nil && composerCommand == nil {
107102
pickerTypeState = .expanded(.none)
@@ -422,6 +417,7 @@ open class MessageComposerViewModel: ObservableObject {
422417
addedFileURLs = []
423418
addedCustomAttachments = []
424419
composerCommand = nil
420+
clearText()
425421
}
426422

427423
private func checkPickerSelectionState() {
@@ -495,4 +491,13 @@ open class MessageComposerViewModel: ObservableObject {
495491
timer?.fire()
496492
}
497493
}
494+
495+
private func clearText() {
496+
// This is needed because of autocompleting text from the keyboard.
497+
// The update of the text is done in the next cycle, so it overrides
498+
// the setting of this value to empty string.
499+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
500+
self?.text = ""
501+
}
502+
}
498503
}

0 commit comments

Comments
 (0)