Skip to content

Commit 3096eb5

Browse files
authored
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 facebook#21830, facebook#25963, facebook#24113, facebook#24118, appium/appium#10654, possibly facebook#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.
1 parent 8ce57ec commit 3096eb5

File tree

1 file changed

+1
-19
lines changed

1 file changed

+1
-19
lines changed

React/Views/RCTView.m

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,6 @@ - (UIView *)react_findClipView
8080

8181
@end
8282

83-
static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
84-
{
85-
NSMutableString *str = [NSMutableString stringWithString:@""];
86-
for (UIView *subview in view.subviews) {
87-
NSString *label = subview.accessibilityLabel;
88-
if (!label) {
89-
label = RCTRecursiveAccessibilityLabel(subview);
90-
}
91-
if (label && label.length > 0) {
92-
if (str.length > 0) {
93-
[str appendString:@" "];
94-
}
95-
[str appendString:label];
96-
}
97-
}
98-
return str.length == 0 ? nil : str;
99-
}
100-
10183
@implementation RCTView {
10284
UIColor *_backgroundColor;
10385
NSMutableDictionary<NSString *, NSDictionary *> *accessibilityActionsNameMap;
@@ -223,7 +205,7 @@ - (NSString *)accessibilityLabel
223205
if (label) {
224206
return label;
225207
}
226-
return RCTRecursiveAccessibilityLabel(self);
208+
return nil;
227209
}
228210

229211
- (NSArray<UIAccessibilityCustomAction *> *)accessibilityCustomActions

0 commit comments

Comments
 (0)