From 61c5e356cac844948383800dc64ed23c88181cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Lucas?= Date: Mon, 29 Apr 2019 03:16:37 -0700 Subject: [PATCH] Fix accessibility event properties for TextInput (#24641) Summary: When a `TextInput` receives any accessibility event prop (`onAccessibilityTap`, `onMagicTap`, `onAccessibilityEscape`, `onAccessibilityEscape`), causes a crash.

[iOS] [Fixed] - Fix accessibility event properties for `TextInput` Pull Request resolved: https://github.com/facebook/react-native/pull/24641 Differential Revision: D15120211 Pulled By: cpojer fbshipit-source-id: 7996ab9f9b78588fab4986c3de6114817ec37296 --- Libraries/Text/TextInput/RCTBaseTextInputView.m | 15 ++++----------- .../Text/TextInput/RCTBaseTextInputViewManager.m | 1 + 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 58b987aac83932..a6a15b37c39923 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -283,16 +283,16 @@ - (BOOL)secureTextEntry { - (void)setSecureTextEntry:(BOOL)secureTextEntry { UIView *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 @@ -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 { @@ -505,13 +505,6 @@ - (CGSize)sizeThatFits:(CGSize)size return fittingSize; } -#pragma mark - Accessibility - -- (UIView *)reactAccessibilityElement -{ - return self.backedTextInputView; -} - #pragma mark - Focus Control - (void)reactFocus diff --git a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m index d226782be62faa..63aa487492ed13 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -34,6 +34,7 @@ @implementation RCTBaseTextInputViewManager #pragma mark - Unified 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)