Skip to content

Commit d00de31

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Use setter for accessibilityElements (#52644)
Summary: Pull Request resolved: #52644 There have been some hard to find crashes with iOS outlined in https://fb.workplace.com/groups/3615245781855602/permalink/23898365966450285/. Talking with lenaic this may be due to us not using the setter to set this property. Let's try that Changelog: [Internal] Reviewed By: lenaic Differential Revision: D78413954 fbshipit-source-id: a68b90a2276805283082ceaf1020e13bd8ef8eb6
1 parent de67d6e commit d00de31

File tree

4 files changed

+22
-151
lines changed

4 files changed

+22
-151
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import "RCTParagraphComponentAccessibilityProvider.h"
1010

1111
#import <MobileCoreServices/UTCoreTypes.h>
12-
#import <React/RCTViewAccessibilityElement.h>
1312
#import <react/renderer/components/text/ParagraphComponentDescriptor.h>
1413
#import <react/renderer/components/text/ParagraphProps.h>
1514
#import <react/renderer/components/text/ParagraphState.h>
@@ -227,10 +226,6 @@ - (BOOL)isAccessibilityCoopted
227226
for (NSObject *element in elements) {
228227
if ([element isKindOfClass:[UIView class]] && [cooptingCandidates containsObject:((UIView *)element)]) {
229228
return YES;
230-
} else if (
231-
[element isKindOfClass:[RCTViewAccessibilityElement class]] &&
232-
[cooptingCandidates containsObject:((RCTViewAccessibilityElement *)element).view]) {
233-
return YES;
234229
}
235230
}
236231
}

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewAccessibilityElement.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewAccessibilityElement.mm

Lines changed: 0 additions & 83 deletions
This file was deleted.

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#import "RCTViewComponentView.h"
9-
#import "RCTViewAccessibilityElement.h"
109

1110
#import <CoreGraphics/CoreGraphics.h>
1211
#import <QuartzCore/QuartzCore.h>
@@ -51,8 +50,6 @@ @implementation RCTViewComponentView {
5150
UIView *_containerView;
5251
BOOL _useCustomContainerView;
5352
NSMutableSet<NSString *> *_accessibilityOrderNativeIDs;
54-
NSMutableArray<NSObject *> *_accessibilityElements;
55-
RCTViewAccessibilityElement *_axElementDescribingSelf;
5653
}
5754

5855
#ifdef RCT_DYNAMIC_FRAMEWORKS
@@ -405,7 +402,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
405402
[_accessibilityOrderNativeIDs addObject:RCTNSStringFromString(childId)];
406403
}
407404

408-
_accessibilityElements = [NSMutableArray new];
405+
// If we are prop updating and have children we can go ahead and assign this prop.
406+
// Otherwise, we might not have children attached yet and need to wait before then.
407+
if (self.currentContainerView.subviews.count > 0) {
408+
[self updateAccessibilityElements];
409+
}
409410
}
410411

411412
// `accessibilityTraits`
@@ -617,7 +618,6 @@ - (void)prepareForRecycle
617618
_isJSResponder = NO;
618619
_removeClippedSubviews = NO;
619620
_reactSubviews = [NSMutableArray new];
620-
_accessibilityElements = [NSMutableArray new];
621621
}
622622

623623
- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(NSSet<NSString *> *_Nullable)props
@@ -1149,43 +1149,37 @@ - (NSObject *)accessibilityElement
11491149
return self;
11501150
}
11511151

1152-
- (NSArray<NSObject *> *)accessibilityElements
1152+
- (void)didMoveToSuperview
11531153
{
1154-
if ([_accessibilityOrderNativeIDs count] <= 0) {
1155-
return super.accessibilityElements;
1154+
// At this point we are guaranteed to have subviews, if we are going to have them
1155+
if (ReactNativeFeatureFlags::enableAccessibilityOrder()) {
1156+
[self updateAccessibilityElements];
11561157
}
1158+
}
11571159

1158-
// TODO: Currently this ignores changes to descendant nativeID's. While that should rarely, if ever happen, it's an
1159-
// edge case we should address. Currently this fixes some app deaths so landing this without addressing that edge case
1160-
// for now.
1161-
if ([_accessibilityElements count] > 0) {
1162-
return _accessibilityElements;
1160+
- (void)updateAccessibilityElements
1161+
{
1162+
if ([_accessibilityOrderNativeIDs count] == 0) {
1163+
self.accessibilityElements = nil;
1164+
return;
11631165
}
11641166

11651167
NSMutableDictionary<NSString *, UIView *> *nativeIdToView = [NSMutableDictionary new];
1166-
11671168
[RCTViewComponentView collectAccessibilityElements:self
11681169
intoDictionary:nativeIdToView
11691170
nativeIds:_accessibilityOrderNativeIDs];
11701171

1171-
for (auto childId : _props->accessibilityOrder) {
1172+
NSMutableArray *accessibilityElements = [NSMutableArray new];
1173+
for (const auto &childId : _props->accessibilityOrder) {
11721174
NSString *nsStringChildId = RCTNSStringFromString(childId);
1173-
// Special case to allow for self-referencing with accessibilityOrder
1174-
if ([nsStringChildId isEqualToString:self.nativeId]) {
1175-
if (!_axElementDescribingSelf) {
1176-
_axElementDescribingSelf = [[RCTViewAccessibilityElement alloc] initWithView:self];
1177-
}
1178-
_axElementDescribingSelf.isAccessibilityElement = [super isAccessibilityElement];
1179-
[_accessibilityElements addObject:_axElementDescribingSelf];
1180-
} else {
1181-
UIView *viewWithMatchingNativeId = [nativeIdToView objectForKey:nsStringChildId];
1182-
if (viewWithMatchingNativeId) {
1183-
[_accessibilityElements addObject:viewWithMatchingNativeId];
1184-
}
1175+
1176+
UIView *viewWithMatchingNativeId = [nativeIdToView objectForKey:nsStringChildId];
1177+
if (viewWithMatchingNativeId != nil) {
1178+
[accessibilityElements addObject:viewWithMatchingNativeId];
11851179
}
11861180
}
11871181

1188-
return _accessibilityElements;
1182+
self.accessibilityElements = accessibilityElements;
11891183
}
11901184

11911185
+ (void)collectAccessibilityElements:(UIView *)view
@@ -1252,13 +1246,6 @@ - (BOOL)isAccessibilityElement
12521246
return self.contentView.isAccessibilityElement;
12531247
}
12541248

1255-
// If we reference ourselves in accessibilityOrder then we will make a
1256-
// UIAccessibilityElement object to represent ourselves since returning YES
1257-
// here would mean iOS would not call into accessibilityElements
1258-
if ([_accessibilityOrderNativeIDs containsObject:self.nativeId]) {
1259-
return NO;
1260-
}
1261-
12621249
return [super isAccessibilityElement];
12631250
}
12641251

0 commit comments

Comments
 (0)