From 4e37d37cbff27e61659440094a662e00eafd8fc4 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 9 May 2019 12:06:43 -0700 Subject: [PATCH] Fixed accesibility problem with 's Clear Button Summary: UITextView is accessible by default (some nested views are) and disabling that is not supported. The problem happened because JS side sets `isAccessible` flag for UITextView and UITextField to `true` (with good intent!), which actually disables (surprise!) bult-in accessibility of TextInput on iOS. On iOS accessible elements cannot be nested, so enabling accessibily for some container view (even in a case where this is view is a public API of TextInput on iOS) shadows some features implemented inside the component. (Disabling accessibility of TextInput via `accessible=false` was never supported.) Reviewed By: JoshuaGross Differential Revision: D15280667 fbshipit-source-id: 72509b40383db6ef66c4263bd920f5ee56a42fc1 --- Libraries/Text/TextInput/Multiline/RCTUITextView.m | 9 +++++++++ Libraries/Text/TextInput/Singleline/RCTUITextField.m | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/Libraries/Text/TextInput/Multiline/RCTUITextView.m index 4ff8cc90ef4..96e7867c92c 100644 --- a/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -58,6 +58,15 @@ static UIColor *defaultPlaceholderColor() [[NSNotificationCenter defaultCenter] removeObserver:self]; } +#pragma mark - Accessibility + +- (void)setIsAccessibilityElement:(BOOL)isAccessibilityElement +{ + // UITextView is accessible by default (some nested views are) and disabling that is not supported. + // On iOS accessible elements cannot be nested, therefore enabling accessibility for some container view + // (even in a case where this view is a part of public API of TextInput on iOS) shadows some features implemented inside the component. +} + - (NSString *)accessibilityLabel { NSMutableString *accessibilityLabel = [NSMutableString new]; diff --git a/Libraries/Text/TextInput/Singleline/RCTUITextField.m b/Libraries/Text/TextInput/Singleline/RCTUITextField.m index 92db734ce7c..3d1af3d3539 100644 --- a/Libraries/Text/TextInput/Singleline/RCTUITextField.m +++ b/Libraries/Text/TextInput/Singleline/RCTUITextField.m @@ -43,6 +43,15 @@ _textWasPasted = NO; } +#pragma mark - Accessibility + +- (void)setIsAccessibilityElement:(BOOL)isAccessibilityElement +{ + // UITextField is accessible by default (some nested views are) and disabling that is not supported. + // On iOS accessible elements cannot be nested, therefore enabling accessibility for some container view + // (even in a case where this view is a part of public API of TextInput on iOS) shadows some features implemented inside the component. +} + #pragma mark - Properties - (void)setTextContainerInset:(UIEdgeInsets)textContainerInset