Skip to content

Commit f05684c

Browse files
authored
Merge pull request #53 from hellohublot/Fix_iOS_Dictation_Extra_Character_Expensify
2 parents dd492a1 + dbcfdf8 commit f05684c

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

packages/react-native/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

packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,19 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
261261
return [super canPerformAction:action withSender:sender];
262262
}
263263

264+
#pragma mark - Dictation
265+
266+
- (void)dictationRecordingDidEnd
267+
{
268+
_dictationRecognizing = YES;
269+
}
270+
271+
- (void)removeDictationResultPlaceholder:(id)placeholder willInsertResult:(BOOL)willInsertResult
272+
{
273+
[super removeDictationResultPlaceholder:placeholder willInsertResult:willInsertResult];
274+
_dictationRecognizing = NO;
275+
}
276+
264277
#pragma mark - Placeholder
265278

266279
- (void)_invalidatePlaceholderVisibility

packages/react-native/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;

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ - (BOOL)textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTex
119119
}
120120
}];
121121

122-
BOOL shouldFallbackToBareTextComparison =
123-
[self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"] ||
122+
BOOL shouldFallbackDictation = [self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"];
123+
if (@available(iOS 16.0, *)) {
124+
shouldFallbackDictation = self.backedTextInputView.dictationRecognizing;
125+
}
126+
127+
BOOL shouldFallbackToBareTextComparison = shouldFallbackDictation ||
124128
[self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"ko-KR"] ||
125129
self.backedTextInputView.markedTextRange || self.backedTextInputView.isSecureTextEntry ||
126130
fontHasBeenUpdatedBySystem;

packages/react-native/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;

packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
142142
return [super canPerformAction:action withSender:sender];
143143
}
144144

145+
#pragma mark - Dictation
146+
147+
- (void)dictationRecordingDidEnd
148+
{
149+
_dictationRecognizing = YES;
150+
}
151+
152+
- (void)removeDictationResultPlaceholder:(id)placeholder willInsertResult:(BOOL)willInsertResult
153+
{
154+
[super removeDictationResultPlaceholder:placeholder willInsertResult:willInsertResult];
155+
_dictationRecognizing = NO;
156+
}
157+
145158
#pragma mark - Caret Manipulation
146159

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

0 commit comments

Comments
 (0)