Skip to content

Commit

Permalink
iOS - apply Paper improvements to Fabric
Browse files Browse the repository at this point in the history
1)The error is announced, but not with the character onChangeText
2)The error is announced multiple times

Test Case of this changes
fabOnReact/react-native-notes#12 (comment)
  • Loading branch information
fabOnReact committed Jun 17, 2022
1 parent e4a95c6 commit b53ed9d
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ @implementation RCTTextInputComponentView {
UIView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
NSUInteger _mostRecentEventCount;
NSAttributedString *_lastStringStateWasUpdatedWith;
NSString *_errorMessage;

/*
* UIKit uses either UITextField or UITextView as its UIKit element for <TextInput>. UITextField is for single line
Expand Down Expand Up @@ -134,13 +135,19 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
_backedTextInputView.editable = newTextInputProps.traits.editable;
}

NSString *error = RCTNSStringFromString(newTextInputProps.accessibilityErrorMessage);
NSString *text = RCTNSStringFromString(newTextInputProps.text);
if (newTextInputProps.accessibilityErrorMessage != oldTextInputProps.accessibilityErrorMessage || newTextInputProps.text != oldTextInputProps.text) {
NSString *errorWithText = [text length] == 0 ? error : [NSString stringWithFormat: @"%@ %@", text, error];
self.accessibilityElement.accessibilityValue = errorWithText;
if (newTextInputProps.accessibilityErrorMessage != oldTextInputProps.accessibilityErrorMessage) {
NSString *error = RCTNSStringFromString(newTextInputProps.accessibilityErrorMessage);
NSString *text = RCTNSStringFromString(newTextInputProps.text);
NSString *lastChar = [text length] == 0 ? @"" : [text substringFromIndex:[text length] - 1];
if ([error length] != 0) {
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, errorWithText);
NSString *errorWithLastCharacter = [NSString stringWithFormat: @"%@ %@", lastChar, error];
NSString *errorWithText = [NSString stringWithFormat: @"%@ %@", text, error];
self.accessibilityElement.accessibilityValue = errorWithText;
self->_errorMessage = errorWithText;
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, errorWithLastCharacter);
} else {
self.accessibilityElement.accessibilityValue = text;
self->_errorMessage = nil;
}
}

Expand Down Expand Up @@ -595,6 +602,13 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString
UITextRange *selectedRange = _backedTextInputView.selectedTextRange;
NSInteger oldTextLength = _backedTextInputView.attributedText.string.length;
_backedTextInputView.attributedText = attributedString;
if (self->_errorMessage == nil) {
NSString *lastChar = [attributedString.string substringFromIndex:[attributedString.string length] - 1];
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, lastChar);
}
if (self->_errorMessage == nil && ![_backedTextInputView.accessibilityValue isEqualToString: attributedString.string]) {
_backedTextInputView.accessibilityValue = attributedString.string;
}
if (selectedRange.empty) {
// Maintaining a cursor position relative to the end of the old text.
NSInteger offsetStart = [_backedTextInputView offsetFromPosition:_backedTextInputView.beginningOfDocument
Expand Down

0 comments on commit b53ed9d

Please sign in to comment.