diff --git a/apple/RNGestureHandlerButton.mm b/apple/RNGestureHandlerButton.mm index e98e538756..97cdc7556e 100644 --- a/apple/RNGestureHandlerButton.mm +++ b/apple/RNGestureHandlerButton.mm @@ -112,6 +112,34 @@ - (void)displayLayer:(CALayer *)layer const CGFloat currentBorderRadius = radius * scaleFactor; layer.cornerRadius = currentBorderRadius; } + +- (NSString *)accessibilityLabel +{ + NSString *label = super.accessibilityLabel; + if (label) { + return label; + } + return RNGHRecursiveAccessibilityLabel(self); +} + +// Vendored from RCTView.m to infer accessibility label from children +static NSString *RNGHRecursiveAccessibilityLabel(UIView *view) +{ + NSMutableString *str = [NSMutableString stringWithString:@""]; + for (UIView *subview in view.subviews) { + NSString *label = subview.accessibilityLabel; + if (!label) { + label = RNGHRecursiveAccessibilityLabel(subview); + } + if (label && label.length > 0) { + if (str.length > 0) { + [str appendString:@" "]; + } + [str appendString:label]; + } + } + return str.length == 0 ? nil : str; +} #endif #if TARGET_OS_OSX && RCT_NEW_ARCH_ENABLED diff --git a/src/components/GestureButtonsProps.ts b/src/components/GestureButtonsProps.ts index 480d28bea6..e5075a17da 100644 --- a/src/components/GestureButtonsProps.ts +++ b/src/components/GestureButtonsProps.ts @@ -1,8 +1,10 @@ import * as React from 'react'; -import { StyleProp, ViewStyle } from 'react-native'; +import { AccessibilityProps, StyleProp, ViewStyle } from 'react-native'; import type { NativeViewGestureHandlerProps } from '../handlers/NativeViewGestureHandler'; -export interface RawButtonProps extends NativeViewGestureHandlerProps { +export interface RawButtonProps + extends NativeViewGestureHandlerProps, + AccessibilityProps { /** * Defines if more than one button could be pressed simultaneously. By default * set true.