@@ -61,33 +61,38 @@ const Text: React.AbstractComponent<
61
61
62
62
const [ isHighlighted , setHighlighted ] = useState ( false ) ;
63
63
64
- let _accessibilityState ;
64
+ const _accessibilityLabel = ariaLabel ?? accessibilityLabel ;
65
+
66
+ let _accessibilityState : ?TextProps [ 'accessibilityState' ] =
67
+ accessibilityState ;
65
68
if (
66
- accessibilityState != null ||
67
69
ariaBusy != null ||
68
70
ariaChecked != null ||
69
71
ariaDisabled != null ||
70
72
ariaExpanded != null ||
71
73
ariaSelected != null
72
74
) {
73
- _accessibilityState = {
74
- busy : ariaBusy ?? accessibilityState ?. busy ,
75
- checked : ariaChecked ?? accessibilityState ?. checked ,
76
- disabled : ariaDisabled ?? accessibilityState ?. disabled ,
77
- expanded : ariaExpanded ?? accessibilityState ?. expanded ,
78
- selected : ariaSelected ?? accessibilityState ?. selected ,
79
- } ;
75
+ if ( _accessibilityState != null ) {
76
+ _accessibilityState = {
77
+ busy : ariaBusy ?? _accessibilityState . busy ,
78
+ checked : ariaChecked ?? _accessibilityState . checked ,
79
+ disabled : ariaDisabled ?? _accessibilityState . disabled ,
80
+ expanded : ariaExpanded ?? _accessibilityState . expanded ,
81
+ selected : ariaSelected ?? _accessibilityState . selected ,
82
+ } ;
83
+ } else {
84
+ _accessibilityState = {
85
+ busy : ariaBusy ,
86
+ checked : ariaChecked ,
87
+ disabled : ariaDisabled ,
88
+ expanded : ariaExpanded ,
89
+ selected : ariaSelected ,
90
+ } ;
91
+ }
80
92
}
81
93
82
- const _disabled =
83
- restProps . disabled != null
84
- ? restProps . disabled
85
- : _accessibilityState ?. disabled ;
86
-
87
- const nativeTextAccessibilityState =
88
- _disabled !== _accessibilityState ?. disabled
89
- ? { ..._accessibilityState , disabled : _disabled }
90
- : _accessibilityState ;
94
+ const _accessibilityStateDisabled = _accessibilityState ?. disabled ;
95
+ const _disabled = restProps . disabled ?? _accessibilityStateDisabled ;
91
96
92
97
const isPressable =
93
98
( onPress != null ||
@@ -190,7 +195,6 @@ const Text: React.AbstractComponent<
190
195
: processColor ( restProps . selectionColor ) ;
191
196
192
197
let style = restProps . style ;
193
-
194
198
if ( __DEV__ ) {
195
199
if ( PressabilityDebug . isEnabled ( ) && onPress != null ) {
196
200
style = [ restProps . style , { color : 'magenta' } ] ;
@@ -205,13 +209,6 @@ const Text: React.AbstractComponent<
205
209
numberOfLines = 0 ;
206
210
}
207
211
208
- const hasTextAncestor = useContext ( TextAncestor ) ;
209
-
210
- const _accessible = Platform . select ( {
211
- ios : accessible !== false ,
212
- default : accessible ,
213
- } ) ;
214
-
215
212
let _selectable = restProps . selectable ;
216
213
217
214
const processedStyle = flattenStyle ( style ) ;
@@ -236,41 +233,59 @@ const Text: React.AbstractComponent<
236
233
}
237
234
}
238
235
239
- const _hasOnPressOrOnLongPress =
240
- props . onPress != null || props . onLongPress != null ;
236
+ const _nativeID = id ?? nativeID ;
237
+
238
+ const hasTextAncestor = useContext ( TextAncestor ) ;
239
+ if ( hasTextAncestor ) {
240
+ return (
241
+ < NativeVirtualText
242
+ { ...restProps }
243
+ { ...eventHandlersForText }
244
+ accessibilityLabel = { _accessibilityLabel }
245
+ accessibilityState = { _accessibilityState }
246
+ isHighlighted = { isHighlighted }
247
+ isPressable = { isPressable }
248
+ nativeID = { _nativeID }
249
+ numberOfLines = { numberOfLines }
250
+ ref = { forwardedRef }
251
+ selectable = { _selectable }
252
+ selectionColor = { selectionColor }
253
+ style = { processedStyle }
254
+ />
255
+ ) ;
256
+ }
257
+
258
+ // If the disabled prop and accessibilityState.disabled are out of sync but not both in
259
+ // falsy states we need to update the accessibilityState object to use the disabled prop.
260
+ if (
261
+ _disabled !== _accessibilityStateDisabled &&
262
+ ( ( _disabled != null && _disabled !== false ) ||
263
+ ( _accessibilityStateDisabled != null &&
264
+ _accessibilityStateDisabled !== false ) )
265
+ ) {
266
+ _accessibilityState = { ..._accessibilityState , disabled : _disabled } ;
267
+ }
268
+
269
+ const _accessible = Platform . select ( {
270
+ ios : accessible !== false ,
271
+ android :
272
+ accessible == null ? onPress != null || onLongPress != null : accessible ,
273
+ default : accessible ,
274
+ } ) ;
241
275
242
- return hasTextAncestor ? (
243
- < NativeVirtualText
244
- { ...restProps }
245
- { ...eventHandlersForText }
246
- accessibilityLabel = { ariaLabel ?? accessibilityLabel }
247
- accessibilityState = { _accessibilityState }
248
- isHighlighted = { isHighlighted }
249
- isPressable = { isPressable }
250
- nativeID = { id ?? nativeID }
251
- numberOfLines = { numberOfLines }
252
- ref = { forwardedRef }
253
- selectable = { _selectable }
254
- selectionColor = { selectionColor }
255
- style = { processedStyle }
256
- />
257
- ) : (
276
+ return (
258
277
< TextAncestor . Provider value = { true } >
259
278
< NativeText
260
279
{ ...restProps }
261
280
{ ...eventHandlersForText }
262
- accessibilityLabel = { ariaLabel ?? accessibilityLabel }
263
- accessibilityState = { nativeTextAccessibilityState }
264
- accessible = {
265
- accessible == null && Platform . OS === 'android'
266
- ? _hasOnPressOrOnLongPress
267
- : _accessible
268
- }
281
+ accessibilityLabel = { _accessibilityLabel }
282
+ accessibilityState = { _accessibilityState }
283
+ accessible = { _accessible }
269
284
allowFontScaling = { allowFontScaling !== false }
270
285
disabled = { _disabled }
271
286
ellipsizeMode = { ellipsizeMode ?? 'tail' }
272
287
isHighlighted = { isHighlighted }
273
- nativeID = { id ?? nativeID }
288
+ nativeID = { _nativeID }
274
289
numberOfLines = { numberOfLines }
275
290
ref = { forwardedRef }
276
291
selectable = { _selectable }
0 commit comments