Skip to content

Commit 4df9132

Browse files
committed
Change typingAttributesBeforeInsertion to dictationRecordingDidEnd
1 parent 4e86f50 commit 4df9132

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

Libraries/Text/TextInput/Multiline/RCTUITextView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
2424

2525
@property (nonatomic, assign) BOOL contextMenuHidden;
2626
@property (nonatomic, assign, readonly) BOOL textWasPasted;
27+
@property (nonatomic, assign, readonly) BOOL dictationRecognizing;
2728
@property (nonatomic, copy, nullable) NSString *placeholder;
2829
@property (nonatomic, strong, nullable) UIColor *placeholderColor;
2930

Libraries/Text/TextInput/Multiline/RCTUITextView.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
257257
return [super canPerformAction:action withSender:sender];
258258
}
259259

260+
#pragma mark - Dictation
261+
262+
- (void)dictationRecordingDidEnd {
263+
_dictationRecognizing = YES;
264+
}
265+
266+
- (void)removeDictationResultPlaceholder:(id)placeholder willInsertResult:(BOOL)willInsertResult {
267+
[super removeDictationResultPlaceholder:placeholder willInsertResult:willInsertResult];
268+
_dictationRecognizing = NO;
269+
}
270+
260271
#pragma mark - Placeholder
261272

262273
- (void)_invalidatePlaceholderVisibility

Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
1818
@property (nonatomic, copy, nullable) NSString *placeholder;
1919
@property (nonatomic, strong, nullable) UIColor *placeholderColor;
2020
@property (nonatomic, assign, readonly) BOOL textWasPasted;
21+
@property (nonatomic, assign, readonly) BOOL dictationRecognizing;
2122
@property (nonatomic, assign) UIEdgeInsets textContainerInset;
2223
@property (nonatomic, strong, nullable) UIView *inputAccessoryView;
2324
@property (nonatomic, strong, nullable) UIView *inputView;

Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,20 @@ - (BOOL)textOf:(NSAttributedString*)newText equals:(NSAttributedString*)oldText{
108108
// If the user added an emoji, the system adds a font attribute for the emoji and stores the original font in
109109
// NSOriginalFont. Lastly, when entering a password, etc., there will be additional styling on the field as the native
110110
// text view handles showing the last character for a split second.
111-
__block BOOL isDictationRunning = false;
112-
[oldText enumerateAttribute:NSAttachmentAttributeName
113-
inRange:NSMakeRange(0, oldText.length)
114-
options:kNilOptions
115-
usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
116-
if ([value respondsToSelector:NSSelectorFromString(@"typingAttributesBeforeInsertion")]) {
117-
isDictationRunning = true;
118-
*stop = true;
119-
}
120-
}];
121111
__block BOOL fontHasBeenUpdatedBySystem = false;
122112
[oldText enumerateAttribute:@"NSOriginalFont" inRange:NSMakeRange(0, oldText.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
123113
if (value){
124114
fontHasBeenUpdatedBySystem = true;
125115
}
126116
}];
127117

118+
BOOL shouldFallbackDictation = [self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"];
119+
if (@available(iOS 16.0, *)) {
120+
shouldFallbackDictation = self.backedTextInputView.dictationRecognizing;
121+
}
122+
128123
BOOL shouldFallbackToBareTextComparison =
129-
isDictationRunning ||
124+
shouldFallbackDictation ||
130125
[self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"ko-KR"] ||
131126
self.backedTextInputView.markedTextRange || self.backedTextInputView.isSecureTextEntry ||
132127
fontHasBeenUpdatedBySystem;

Libraries/Text/TextInput/Singleline/RCTUITextField.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
2424
@property (nonatomic, assign) BOOL caretHidden;
2525
@property (nonatomic, assign) BOOL contextMenuHidden;
2626
@property (nonatomic, assign, readonly) BOOL textWasPasted;
27+
@property (nonatomic, assign, readonly) BOOL dictationRecognizing;
2728
@property (nonatomic, strong, nullable) UIColor *placeholderColor;
2829
@property (nonatomic, assign) UIEdgeInsets textContainerInset;
2930
@property (nonatomic, assign, getter=isEditable) BOOL editable;

Libraries/Text/TextInput/Singleline/RCTUITextField.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
140140
return [super canPerformAction:action withSender:sender];
141141
}
142142

143+
#pragma mark - Dictation
144+
145+
- (void)dictationRecordingDidEnd {
146+
_dictationRecognizing = YES;
147+
}
148+
149+
- (void)removeDictationResultPlaceholder:(id)placeholder willInsertResult:(BOOL)willInsertResult {
150+
[super removeDictationResultPlaceholder:placeholder willInsertResult:willInsertResult];
151+
_dictationRecognizing = NO;
152+
}
153+
143154
#pragma mark - Caret Manipulation
144155

145156
- (CGRect)caretRectForPosition:(UITextPosition *)position

0 commit comments

Comments
 (0)