Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accessibility event properties for TextInput #24641

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions Libraries/Text/TextInput/RCTBaseTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,16 @@ - (BOOL)secureTextEntry {

- (void)setSecureTextEntry:(BOOL)secureTextEntry {
UIView<RCTBackedTextInputViewProtocol> *textInputView = self.backedTextInputView;

if (textInputView.secureTextEntry != secureTextEntry) {
textInputView.secureTextEntry = secureTextEntry;

// Fix #5859, see https://stackoverflow.com/questions/14220187/uitextfield-has-trailing-whitespace-after-securetextentry-toggle/22537788#22537788
NSAttributedString *originalText = [textInputView.attributedText copy];
self.backedTextInputView.attributedText = [NSAttributedString new];
self.backedTextInputView.attributedText = originalText;
}

}

#pragma mark - RCTBackedTextInputDelegate
Expand Down Expand Up @@ -399,7 +399,7 @@ - (BOOL)textInputShouldChangeTextInRange:(NSRange)range replacementText:(NSStrin
}

NSString *previousText = backedTextInputView.attributedText.string ?: @"";

if (range.location + range.length > backedTextInputView.attributedText.string.length) {
_predictedText = backedTextInputView.attributedText.string;
} else {
Expand Down Expand Up @@ -505,13 +505,6 @@ - (CGSize)sizeThatFits:(CGSize)size
return fittingSize;
}

#pragma mark - Accessibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid this particular change is simply wrong/unreasonable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear: Removing this turns off all accessibility props of (by redirecting them to the wrapper view).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shergin my idea of deleting this reactAccessibilityElement was to make RCTBaseTextInputView use reactAccessibilityElement inherited from RCTView (the wrapper).

When I opened this PR I tested TextField passing those events set from RCTViewManager, and it was working. But I might have missed something :-/.

Now I'll need to make more tests, especially because I this commit needed to be reverted (probably because of this detox failure https://circleci.com/gh/facebook/react-native/88586, right @grabbou?). I just don't know yet why this commit caused a regression into Switch component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think Detox couldn't find a TextInput on the top of the app (by its accessibility label), to type <switch /> and select that example.

So definitely related.


- (UIView *)reactAccessibilityElement
{
return self.backedTextInputView;
}

#pragma mark - Focus Control

- (void)reactFocus
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ @implementation RCTBaseTextInputViewManager

#pragma mark - Unified <TextInput> properties

RCT_REMAP_VIEW_PROPERTY(accessibilityLabel, reactAccessibilityElement.accessibilityLabel, NSString)
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType)
RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType)
RCT_REMAP_VIEW_PROPERTY(contextMenuHidden, backedTextInputView.contextMenuHidden, BOOL)
Expand Down