From 3096eb5c0d1f967940cbd97477d08f7e00ef381c Mon Sep 17 00:00:00 2001 From: Nathan Friedly Date: Tue, 25 Aug 2020 14:32:02 -0400 Subject: [PATCH 1/2] Fix duplicate accessibilityLabels on iOS I came across this because one of my customer's apps was freezing the UI and crashing after spending ~10 seconds when trying to read the accessibilityLabel of a view with a "particularly complex and dynamic view hierarchy". I'm still not entirely sure what the app was doing, but I believe this will sidestep the issue entirely. I believe this change will also improve both the accessibility and the testability of RN apps, in addition to fixing that crash. This PR supersedes or fixes #21830, #25963, #24113, #24118, https://github.com/appium/appium/issues/10654, possibly #25220, and probably a few other tickets I haven't identified. Also worth mentioning that there is very similar code in https://github.com/facebook/react-native/blob/master/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm#L489-L515 - I haven't dug into that as much, but I suspect it should probably get the same treatment. If anyone wants, I can include it in this PR. --- React/Views/RCTView.m | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/React/Views/RCTView.m b/React/Views/RCTView.m index 91e28ab95ec664..02cead6558baff 100644 --- a/React/Views/RCTView.m +++ b/React/Views/RCTView.m @@ -80,24 +80,6 @@ - (UIView *)react_findClipView @end -static NSString *RCTRecursiveAccessibilityLabel(UIView *view) -{ - NSMutableString *str = [NSMutableString stringWithString:@""]; - for (UIView *subview in view.subviews) { - NSString *label = subview.accessibilityLabel; - if (!label) { - label = RCTRecursiveAccessibilityLabel(subview); - } - if (label && label.length > 0) { - if (str.length > 0) { - [str appendString:@" "]; - } - [str appendString:label]; - } - } - return str.length == 0 ? nil : str; -} - @implementation RCTView { UIColor *_backgroundColor; NSMutableDictionary *accessibilityActionsNameMap; @@ -223,7 +205,7 @@ - (NSString *)accessibilityLabel if (label) { return label; } - return RCTRecursiveAccessibilityLabel(self); + return nil; } - (NSArray *)accessibilityCustomActions From 6f8faf5365d2f0e018aec60f2a40bac9a48ee1e0 Mon Sep 17 00:00:00 2001 From: Nathan Friedly Date: Fri, 28 Aug 2020 16:55:06 -0400 Subject: [PATCH 2/2] remove accessibilityLabel wrapper Let calls to accessibilityLabel go directly to the one inherited from the base class. Fixes the behavior for code like this that wouldn't normally call it in the first place. ```objective-c if ([view respondsToSelector:@selector(accessibilityLabel)]) return view.accessibilityLabel; ``` --- React/Views/RCTView.m | 9 --------- 1 file changed, 9 deletions(-) diff --git a/React/Views/RCTView.m b/React/Views/RCTView.m index 02cead6558baff..7ac0e327ce794d 100644 --- a/React/Views/RCTView.m +++ b/React/Views/RCTView.m @@ -199,15 +199,6 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event #pragma mark - Accessibility -- (NSString *)accessibilityLabel -{ - NSString *label = super.accessibilityLabel; - if (label) { - return label; - } - return nil; -} - - (NSArray *)accessibilityCustomActions { if (!self.accessibilityActions.count) {