@@ -101,13 +101,108 @@ + (ComponentDescriptorProvider)componentDescriptorProvider
101
101
return concreteComponentDescriptorProvider<RNGestureHandlerButtonComponentDescriptor>();
102
102
}
103
103
104
+ #if TARGET_OS_IOS
105
+ // Taken from
106
+ // https://github.com/facebook/react-native/blob/b226049a4a28ea3f7f32266269fb76340c324d42/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm#L343
107
+ - (void )setAccessibilityProps : (const Props::Shared &)props oldProps : (const Props::Shared &)oldProps
108
+ {
109
+ const auto &oldButtonProps = *std::static_pointer_cast<const RNGestureHandlerButtonProps>(oldProps);
110
+ const auto &newButtonProps = *std::static_pointer_cast<const RNGestureHandlerButtonProps>(props);
111
+
112
+ if (!oldProps || oldButtonProps.accessible != newButtonProps.accessible ) {
113
+ _buttonView.isAccessibilityElement = newButtonProps.accessible ;
114
+ }
115
+
116
+ if (!oldProps || oldButtonProps.accessibilityLabel != newButtonProps.accessibilityLabel ) {
117
+ _buttonView.accessibilityLabel = RCTNSStringFromStringNilIfEmpty (newButtonProps.accessibilityLabel );
118
+ }
119
+
120
+ if (!oldProps || oldButtonProps.accessibilityLanguage != newButtonProps.accessibilityLanguage ) {
121
+ _buttonView.accessibilityLanguage = RCTNSStringFromStringNilIfEmpty (newButtonProps.accessibilityLanguage );
122
+ }
123
+
124
+ if (!oldProps || oldButtonProps.accessibilityHint != newButtonProps.accessibilityHint ) {
125
+ _buttonView.accessibilityHint = RCTNSStringFromStringNilIfEmpty (newButtonProps.accessibilityHint );
126
+ }
127
+
128
+ if (!oldProps || oldButtonProps.accessibilityViewIsModal != newButtonProps.accessibilityViewIsModal ) {
129
+ _buttonView.accessibilityViewIsModal = newButtonProps.accessibilityViewIsModal ;
130
+ }
131
+
132
+ if (!oldProps || oldButtonProps.accessibilityElementsHidden != newButtonProps.accessibilityElementsHidden ) {
133
+ _buttonView.accessibilityElementsHidden = newButtonProps.accessibilityElementsHidden ;
134
+ }
135
+
136
+ if (!oldProps ||
137
+ oldButtonProps.accessibilityShowsLargeContentViewer != newButtonProps.accessibilityShowsLargeContentViewer ) {
138
+ if (@available (iOS 13.0 , *)) {
139
+ if (newButtonProps.accessibilityShowsLargeContentViewer ) {
140
+ _buttonView.showsLargeContentViewer = YES ;
141
+ UILargeContentViewerInteraction *interaction = [[UILargeContentViewerInteraction alloc ] init ];
142
+ [_buttonView addInteraction: interaction];
143
+ } else {
144
+ _buttonView.showsLargeContentViewer = NO ;
145
+ }
146
+ }
147
+ }
148
+
149
+ if (!oldProps || oldButtonProps.accessibilityLargeContentTitle != newButtonProps.accessibilityLargeContentTitle ) {
150
+ if (@available (iOS 13.0 , *)) {
151
+ _buttonView.largeContentTitle = RCTNSStringFromStringNilIfEmpty (newButtonProps.accessibilityLargeContentTitle );
152
+ }
153
+ }
154
+
155
+ if (!oldProps || oldButtonProps.accessibilityTraits != newButtonProps.accessibilityTraits ) {
156
+ _buttonView.accessibilityTraits =
157
+ RCTUIAccessibilityTraitsFromAccessibilityTraits (newButtonProps.accessibilityTraits );
158
+ }
159
+
160
+ if (!oldProps || oldButtonProps.accessibilityState != newButtonProps.accessibilityState ) {
161
+ _buttonView.accessibilityTraits &= ~(UIAccessibilityTraitNotEnabled | UIAccessibilityTraitSelected);
162
+ const auto accessibilityState = newButtonProps.accessibilityState .value_or (AccessibilityState{});
163
+ if (accessibilityState.selected ) {
164
+ _buttonView.accessibilityTraits |= UIAccessibilityTraitSelected;
165
+ }
166
+ if (accessibilityState.disabled ) {
167
+ _buttonView.accessibilityTraits |= UIAccessibilityTraitNotEnabled;
168
+ }
169
+ }
170
+
171
+ if (!oldProps || oldButtonProps.accessibilityIgnoresInvertColors != newButtonProps.accessibilityIgnoresInvertColors ) {
172
+ _buttonView.accessibilityIgnoresInvertColors = newButtonProps.accessibilityIgnoresInvertColors ;
173
+ }
174
+
175
+ if (!oldProps || oldButtonProps.accessibilityValue != newButtonProps.accessibilityValue ) {
176
+ if (newButtonProps.accessibilityValue .text .has_value ()) {
177
+ _buttonView.accessibilityValue = RCTNSStringFromStringNilIfEmpty (newButtonProps.accessibilityValue .text .value ());
178
+ } else if (
179
+ newButtonProps.accessibilityValue .now .has_value () && newButtonProps.accessibilityValue .min .has_value () &&
180
+ newButtonProps.accessibilityValue .max .has_value ()) {
181
+ CGFloat val = (CGFloat)(newButtonProps.accessibilityValue .now .value ()) /
182
+ (newButtonProps.accessibilityValue .max .value () - newButtonProps.accessibilityValue .min .value ());
183
+ _buttonView.accessibilityValue = [NSNumberFormatter localizedStringFromNumber: @(val)
184
+ numberStyle: NSNumberFormatterPercentStyle];
185
+ ;
186
+ } else {
187
+ _buttonView.accessibilityValue = nil ;
188
+ }
189
+ }
190
+
191
+ if (!oldProps || oldButtonProps.testId != newButtonProps.testId ) {
192
+ UIView *accessibilityView = (UIView *)_buttonView;
193
+ accessibilityView.accessibilityIdentifier = RCTNSStringFromString (newButtonProps.testId );
194
+ }
195
+ }
196
+ #endif
197
+
104
198
- (void )updateProps : (const Props::Shared &)props oldProps : (const Props::Shared &)oldProps
105
199
{
106
200
const auto &newProps = *std::static_pointer_cast<const RNGestureHandlerButtonProps>(props);
107
201
108
202
_buttonView.userEnabled = newProps.enabled ;
109
203
#if !TARGET_OS_TV && !TARGET_OS_OSX
110
204
_buttonView.exclusiveTouch = newProps.exclusive ;
205
+ [self setAccessibilityProps: props oldProps: oldProps];
111
206
#endif
112
207
_buttonView.hitTestEdgeInsets = UIEdgeInsetsMake (
113
208
-newProps.hitSlop .top , -newProps.hitSlop .left , -newProps.hitSlop .bottom , -newProps.hitSlop .right );
0 commit comments