Skip to content

Commit 7feab6e

Browse files
authored
[iOS] Fix duplicated testID (#4186)
## Description This PR fixes duplicated `testID` prop on iOS. Same `accessibilityLabel` was assigned to both, wrapper and button, therefore frameworks like `Detox` failed due to multiple elements with the same ID. Fixes #3698 ## Test plan Tested on branch with e2e tests.
1 parent 3846335 commit 7feab6e

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,19 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
360360
}
361361

362362
[super updateProps:props oldProps:oldProps];
363+
364+
#if !TARGET_OS_TV && !TARGET_OS_OSX
365+
// super's updateProps sets self.accessibilityIdentifier from testID via the
366+
// standard Fabric mechanism. However, setAccessibilityProps already forwards
367+
// testID to _buttonView.accessibilityIdentifier (the actual button element).
368+
// Having the identifier on both views causes testing frameworks (e.g. Detox)
369+
// to report multiple matches for the same testID. Clear it from the wrapper so
370+
// only _buttonView carries the identifier.
371+
if (!newProps.testId.empty()) {
372+
self.accessibilityIdentifier = nil;
373+
}
374+
#endif
375+
363376
if (shouldApplyStartAnimationState) {
364377
[_buttonView applyStartAnimationState];
365378
}

0 commit comments

Comments
 (0)