@office-iss/react-native-win32 0.0.0-canary.270 → 0.0.0-canary.271

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.json +16 -1
  2. package/CHANGELOG.md +12 -4
  3. package/Libraries/Animated/animations/Animation.js +63 -24
  4. package/Libraries/Animated/animations/DecayAnimation.js +26 -38
  5. package/Libraries/Animated/animations/SpringAnimation.js +33 -39
  6. package/Libraries/Animated/animations/TimingAnimation.js +34 -42
  7. package/Libraries/Animated/createAnimatedComponent.js +46 -32
  8. package/Libraries/Animated/nodes/AnimatedProps.js +16 -10
  9. package/Libraries/Animated/nodes/AnimatedStyle.js +4 -0
  10. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +19 -3
  11. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +61 -3
  12. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +61 -3
  13. package/Libraries/Components/Button.js +6 -4
  14. package/Libraries/Components/Button.win32.js +9 -4
  15. package/Libraries/Components/ScrollView/ScrollView.js +5 -5
  16. package/Libraries/Components/Switch/Switch.js +8 -6
  17. package/Libraries/Components/TextInput/TextInput.d.ts +4 -4
  18. package/Libraries/Components/TextInput/TextInput.flow.js +7 -10
  19. package/Libraries/Components/TextInput/TextInput.js +7 -7
  20. package/Libraries/Components/TextInput/TextInput.win32.js +7 -7
  21. package/Libraries/Components/TextInput/TextInputState.js +11 -13
  22. package/Libraries/Components/TextInput/TextInputState.win32.js +13 -16
  23. package/Libraries/Components/View/ReactNativeStyleAttributes.js +1 -0
  24. package/Libraries/Components/View/ViewNativeComponent.js +3 -10
  25. package/Libraries/Core/ReactNativeVersion.js +1 -1
  26. package/Libraries/Core/setUpBatchedBridge.js +1 -10
  27. package/Libraries/Core/setUpReactDevTools.js +3 -3
  28. package/Libraries/Core/setUpSegmentFetcher.js +1 -0
  29. package/Libraries/Core/setUpTimers.js +8 -8
  30. package/Libraries/Image/ImageBackground.js +2 -5
  31. package/Libraries/Image/ImageProps.js +1 -1
  32. package/Libraries/Image/ImageViewNativeComponent.js +2 -2
  33. package/Libraries/Inspector/ReactDevToolsOverlay.js +0 -1
  34. package/Libraries/Inspector/getInspectorDataForViewAtPoint.js +3 -5
  35. package/Libraries/JSInspector/NetworkAgent.js +1 -1
  36. package/Libraries/Lists/FlatList.d.ts +1 -2
  37. package/Libraries/Lists/__flowtests__/FlatList-flowtest.js +2 -2
  38. package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +1 -1
  39. package/Libraries/LogBox/Data/LogBoxData.js +1 -1
  40. package/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +1 -1
  41. package/Libraries/LogBox/UI/LogBoxMessage.js +2 -2
  42. package/Libraries/NativeComponent/BaseViewConfig.android.js +1 -0
  43. package/Libraries/NativeComponent/BaseViewConfig.ios.js +1 -0
  44. package/Libraries/NativeComponent/BaseViewConfig.win32.js +1 -0
  45. package/Libraries/Network/XMLHttpRequest.js +26 -1
  46. package/Libraries/Pressability/HoverState.js +2 -0
  47. package/Libraries/Pressability/HoverState.win32.js +2 -0
  48. package/Libraries/Pressability/Pressability.js +2 -3
  49. package/Libraries/Pressability/Pressability.win32.js +2 -3
  50. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +2 -3
  51. package/Libraries/ReactNative/RendererImplementation.js +4 -3
  52. package/Libraries/Renderer/shims/ReactNativeTypes.js +13 -18
  53. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -0
  54. package/Libraries/StyleSheet/StyleSheetTypes.js +13 -0
  55. package/Libraries/StyleSheet/processTransform.js +3 -34
  56. package/Libraries/Text/Text.js +251 -249
  57. package/Libraries/Text/Text.win32.js +285 -295
  58. package/Libraries/Types/CoreEventTypes.d.ts +3 -10
  59. package/Libraries/Types/CoreEventTypes.js +4 -6
  60. package/Libraries/Types/CoreEventTypes.win32.js +4 -6
  61. package/Libraries/Utilities/Platform.flow.js +2 -2
  62. package/Libraries/Utilities/Platform.flow.win32.js +2 -2
  63. package/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +5 -4
  64. package/index.js +5 -2
  65. package/index.win32.js +5 -2
  66. package/jest/setup.js +30 -0
  67. package/overrides.json +18 -17
  68. package/package.json +13 -13
  69. package/src/private/animated/NativeAnimatedHelper.js +2 -4
  70. package/src/private/animated/NativeAnimatedHelper.win32.js +2 -3
  71. package/src/private/components/HScrollViewNativeComponents.js +4 -5
  72. package/src/private/{fusebox → debugging}/setUpFuseboxReactDevToolsDispatcher.js +6 -0
  73. package/src/private/featureflags/ReactNativeFeatureFlags.js +14 -23
  74. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +2 -5
  75. package/src/private/specs/modules/NativeAccessibilityInfo.js +3 -0
  76. package/src/private/specs/modules/NativeAccessibilityInfoWin32.js +3 -0
  77. package/src/private/specs/modules/NativeAccessibilityManager.js +4 -0
  78. package/src/private/webapis/dom/nodes/ReactNativeElement.js +2 -3
  79. package/src/private/webapis/performance/EventTiming.js +13 -8
  80. package/src/private/webapis/performance/Performance.js +30 -40
  81. package/src/private/webapis/performance/PerformanceEntry.js +2 -5
  82. package/src/private/webapis/performance/PerformanceObserver.js +20 -32
  83. package/src/private/webapis/performance/RawPerformanceEntry.js +1 -1
  84. package/src/private/webapis/performance/UserTiming.js +6 -2
  85. package/src/private/webapis/performance/Utilities.js +0 -7
  86. package/src/private/webapis/performance/specs/NativePerformance.js +53 -0
  87. package/src/private/webapis/performance/specs/__mocks__/NativePerformanceMock.js +247 -0
  88. package/src-win/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +19 -3
  89. package/types/public/ReactNativeTypes.d.ts +4 -4
  90. package/src/private/webapis/performance/specs/NativePerformanceObserver.js +0 -69
  91. package/src/private/webapis/performance/specs/__mocks__/NativePerformance.js +0 -69
  92. package/src/private/webapis/performance/specs/__mocks__/NativePerformanceObserver.js +0 -154
  93. /package/src/private/{fusebox → debugging}/FuseboxSessionObserver.js +0 -0
  94. /package/src/private/{reactdevtools → debugging}/ReactDevToolsSettingsManager.android.js +0 -0
  95. /package/src/private/{reactdevtools → debugging}/ReactDevToolsSettingsManager.ios.js +0 -0
  96. /package/src/private/{reactdevtools → debugging}/ReactDevToolsSettingsManager.win32.js +0 -0
@@ -33,231 +33,156 @@ type TextForwardRef = React.ElementRef<
33
33
  *
34
34
  * @see https://reactnative.dev/docs/text
35
35
  */
36
- const Text: React.AbstractComponent<TextProps, TextForwardRef> =
37
- React.forwardRef(
38
- (
39
- {
40
- accessible,
41
- accessibilityLabel,
42
- accessibilityState,
43
- allowFontScaling,
44
- 'aria-busy': ariaBusy,
45
- 'aria-checked': ariaChecked,
46
- 'aria-disabled': ariaDisabled,
47
- 'aria-expanded': ariaExpanded,
48
- 'aria-label': ariaLabel,
49
- 'aria-selected': ariaSelected,
50
- children,
51
- ellipsizeMode,
52
- disabled,
53
- id,
54
- nativeID,
55
- numberOfLines,
56
- onLongPress,
57
- onPress,
58
- onPressIn,
59
- onPressOut,
60
- onResponderGrant,
61
- onResponderMove,
62
- onResponderRelease,
63
- onResponderTerminate,
64
- onResponderTerminationRequest,
65
- onStartShouldSetResponder,
66
- pressRetentionOffset,
67
- selectable,
68
- selectionColor,
69
- suppressHighlighting,
70
- style,
71
- ...restProps
72
- }: TextProps,
73
- forwardedRef,
74
- ) => {
75
- const _accessibilityLabel = ariaLabel ?? accessibilityLabel;
76
-
77
- let _accessibilityState: ?TextProps['accessibilityState'] =
78
- accessibilityState;
79
- if (
80
- ariaBusy != null ||
81
- ariaChecked != null ||
82
- ariaDisabled != null ||
83
- ariaExpanded != null ||
84
- ariaSelected != null
85
- ) {
86
- if (_accessibilityState != null) {
87
- _accessibilityState = {
88
- busy: ariaBusy ?? _accessibilityState.busy,
89
- checked: ariaChecked ?? _accessibilityState.checked,
90
- disabled: ariaDisabled ?? _accessibilityState.disabled,
91
- expanded: ariaExpanded ?? _accessibilityState.expanded,
92
- selected: ariaSelected ?? _accessibilityState.selected,
93
- };
94
- } else {
95
- _accessibilityState = {
96
- busy: ariaBusy,
97
- checked: ariaChecked,
98
- disabled: ariaDisabled,
99
- expanded: ariaExpanded,
100
- selected: ariaSelected,
101
- };
102
- }
36
+ const Text: component(
37
+ ref: React.RefSetter<TextForwardRef>,
38
+ ...props: TextProps
39
+ ) = React.forwardRef(
40
+ (
41
+ {
42
+ accessible,
43
+ accessibilityLabel,
44
+ accessibilityState,
45
+ allowFontScaling,
46
+ 'aria-busy': ariaBusy,
47
+ 'aria-checked': ariaChecked,
48
+ 'aria-disabled': ariaDisabled,
49
+ 'aria-expanded': ariaExpanded,
50
+ 'aria-label': ariaLabel,
51
+ 'aria-selected': ariaSelected,
52
+ children,
53
+ ellipsizeMode,
54
+ disabled,
55
+ id,
56
+ nativeID,
57
+ numberOfLines,
58
+ onLongPress,
59
+ onPress,
60
+ onPressIn,
61
+ onPressOut,
62
+ onResponderGrant,
63
+ onResponderMove,
64
+ onResponderRelease,
65
+ onResponderTerminate,
66
+ onResponderTerminationRequest,
67
+ onStartShouldSetResponder,
68
+ pressRetentionOffset,
69
+ selectable,
70
+ selectionColor,
71
+ suppressHighlighting,
72
+ style,
73
+ ...restProps
74
+ }: TextProps,
75
+ forwardedRef,
76
+ ) => {
77
+ const _accessibilityLabel = ariaLabel ?? accessibilityLabel;
78
+
79
+ let _accessibilityState: ?TextProps['accessibilityState'] =
80
+ accessibilityState;
81
+ if (
82
+ ariaBusy != null ||
83
+ ariaChecked != null ||
84
+ ariaDisabled != null ||
85
+ ariaExpanded != null ||
86
+ ariaSelected != null
87
+ ) {
88
+ if (_accessibilityState != null) {
89
+ _accessibilityState = {
90
+ busy: ariaBusy ?? _accessibilityState.busy,
91
+ checked: ariaChecked ?? _accessibilityState.checked,
92
+ disabled: ariaDisabled ?? _accessibilityState.disabled,
93
+ expanded: ariaExpanded ?? _accessibilityState.expanded,
94
+ selected: ariaSelected ?? _accessibilityState.selected,
95
+ };
96
+ } else {
97
+ _accessibilityState = {
98
+ busy: ariaBusy,
99
+ checked: ariaChecked,
100
+ disabled: ariaDisabled,
101
+ expanded: ariaExpanded,
102
+ selected: ariaSelected,
103
+ };
103
104
  }
105
+ }
104
106
 
105
- const _accessibilityStateDisabled = _accessibilityState?.disabled;
106
- const _disabled = disabled ?? _accessibilityStateDisabled;
107
+ const _accessibilityStateDisabled = _accessibilityState?.disabled;
108
+ const _disabled = disabled ?? _accessibilityStateDisabled;
107
109
 
108
- const isPressable =
109
- (onPress != null ||
110
- onLongPress != null ||
111
- onStartShouldSetResponder != null) &&
112
- _disabled !== true;
110
+ const isPressable =
111
+ (onPress != null ||
112
+ onLongPress != null ||
113
+ onStartShouldSetResponder != null) &&
114
+ _disabled !== true;
113
115
 
114
- // TODO: Move this processing to the view configuration.
115
- const _selectionColor =
116
- selectionColor == null ? null : processColor(selectionColor);
116
+ // TODO: Move this processing to the view configuration.
117
+ const _selectionColor =
118
+ selectionColor == null ? null : processColor(selectionColor);
117
119
 
118
- let _style = style;
119
- if (__DEV__) {
120
- if (PressabilityDebug.isEnabled() && onPress != null) {
121
- _style = [style, {color: 'magenta'}];
122
- }
120
+ let _style = style;
121
+ if (__DEV__) {
122
+ if (PressabilityDebug.isEnabled() && onPress != null) {
123
+ _style = [style, {color: 'magenta'}];
123
124
  }
125
+ }
124
126
 
125
- let _numberOfLines = numberOfLines;
126
- if (_numberOfLines != null && !(_numberOfLines >= 0)) {
127
- if (__DEV__) {
128
- console.error(
129
- `'numberOfLines' in <Text> must be a non-negative number, received: ${_numberOfLines}. The value will be set to 0.`,
130
- );
131
- }
132
- _numberOfLines = 0;
127
+ let _numberOfLines = numberOfLines;
128
+ if (_numberOfLines != null && !(_numberOfLines >= 0)) {
129
+ if (__DEV__) {
130
+ console.error(
131
+ `'numberOfLines' in <Text> must be a non-negative number, received: ${_numberOfLines}. The value will be set to 0.`,
132
+ );
133
133
  }
134
+ _numberOfLines = 0;
135
+ }
134
136
 
135
- let _selectable = selectable;
136
-
137
- let processedStyle = flattenStyle<TextStyleProp>(_style);
138
- if (processedStyle != null) {
139
- let overrides: ?{...TextStyleInternal} = null;
140
- if (typeof processedStyle.fontWeight === 'number') {
141
- overrides = overrides || ({}: {...TextStyleInternal});
142
- overrides.fontWeight =
143
- // $FlowFixMe[incompatible-cast]
144
- (processedStyle.fontWeight.toString(): TextStyleInternal['fontWeight']);
145
- }
146
-
147
- if (processedStyle.userSelect != null) {
148
- _selectable = userSelectToSelectableMap[processedStyle.userSelect];
149
- overrides = overrides || ({}: {...TextStyleInternal});
150
- overrides.userSelect = undefined;
151
- }
152
-
153
- if (processedStyle.verticalAlign != null) {
154
- overrides = overrides || ({}: {...TextStyleInternal});
155
- overrides.textAlignVertical =
156
- verticalAlignToTextAlignVerticalMap[processedStyle.verticalAlign];
157
- overrides.verticalAlign = undefined;
158
- }
137
+ let _selectable = selectable;
159
138
 
160
- if (overrides != null) {
161
- // $FlowFixMe[incompatible-type]
162
- _style = [_style, overrides];
163
- }
139
+ let processedStyle = flattenStyle<TextStyleProp>(_style);
140
+ if (processedStyle != null) {
141
+ let overrides: ?{...TextStyleInternal} = null;
142
+ if (typeof processedStyle.fontWeight === 'number') {
143
+ overrides = overrides || ({}: {...TextStyleInternal});
144
+ overrides.fontWeight =
145
+ // $FlowFixMe[incompatible-cast]
146
+ (processedStyle.fontWeight.toString(): TextStyleInternal['fontWeight']);
164
147
  }
165
148
 
166
- const _nativeID = id ?? nativeID;
167
-
168
- const hasTextAncestor = useContext(TextAncestor);
169
- if (hasTextAncestor) {
170
- if (isPressable) {
171
- return (
172
- <NativePressableVirtualText
173
- ref={forwardedRef}
174
- textProps={{
175
- ...restProps,
176
- accessibilityLabel: _accessibilityLabel,
177
- accessibilityState: _accessibilityState,
178
- nativeID: _nativeID,
179
- numberOfLines: _numberOfLines,
180
- selectable: _selectable,
181
- selectionColor: _selectionColor,
182
- style: _style,
183
- disabled: disabled,
184
- children,
185
- }}
186
- textPressabilityProps={{
187
- onLongPress,
188
- onPress,
189
- onPressIn,
190
- onPressOut,
191
- onResponderGrant,
192
- onResponderMove,
193
- onResponderRelease,
194
- onResponderTerminate,
195
- onResponderTerminationRequest,
196
- onStartShouldSetResponder,
197
- pressRetentionOffset,
198
- suppressHighlighting,
199
- }}
200
- />
201
- );
202
- }
149
+ if (processedStyle.userSelect != null) {
150
+ _selectable = userSelectToSelectableMap[processedStyle.userSelect];
151
+ overrides = overrides || ({}: {...TextStyleInternal});
152
+ overrides.userSelect = undefined;
153
+ }
203
154
 
204
- return (
205
- <NativeVirtualText
206
- {...restProps}
207
- accessibilityLabel={_accessibilityLabel}
208
- accessibilityState={_accessibilityState}
209
- isHighlighted={false}
210
- isPressable={false}
211
- nativeID={_nativeID}
212
- numberOfLines={_numberOfLines}
213
- ref={forwardedRef}
214
- selectable={_selectable}
215
- selectionColor={_selectionColor}
216
- style={_style}
217
- disabled={disabled}>
218
- {children}
219
- </NativeVirtualText>
220
- );
155
+ if (processedStyle.verticalAlign != null) {
156
+ overrides = overrides || ({}: {...TextStyleInternal});
157
+ overrides.textAlignVertical =
158
+ verticalAlignToTextAlignVerticalMap[processedStyle.verticalAlign];
159
+ overrides.verticalAlign = undefined;
221
160
  }
222
161
 
223
- // If the disabled prop and accessibilityState.disabled are out of sync but not both in
224
- // falsy states we need to update the accessibilityState object to use the disabled prop.
225
- if (
226
- _disabled !== _accessibilityStateDisabled &&
227
- ((_disabled != null && _disabled !== false) ||
228
- (_accessibilityStateDisabled != null &&
229
- _accessibilityStateDisabled !== false))
230
- ) {
231
- _accessibilityState = {..._accessibilityState, disabled: _disabled};
162
+ if (overrides != null) {
163
+ // $FlowFixMe[incompatible-type]
164
+ _style = [_style, overrides];
232
165
  }
166
+ }
233
167
 
234
- const _accessible = Platform.select({
235
- ios: accessible !== false,
236
- android:
237
- accessible == null
238
- ? onPress != null || onLongPress != null
239
- : accessible,
240
- default: accessible,
241
- });
168
+ const _nativeID = id ?? nativeID;
242
169
 
243
- let nativeText = null;
170
+ const hasTextAncestor = useContext(TextAncestor);
171
+ if (hasTextAncestor) {
244
172
  if (isPressable) {
245
- nativeText = (
246
- <NativePressableText
173
+ return (
174
+ <NativePressableVirtualText
247
175
  ref={forwardedRef}
248
176
  textProps={{
249
177
  ...restProps,
250
178
  accessibilityLabel: _accessibilityLabel,
251
179
  accessibilityState: _accessibilityState,
252
- accessible: _accessible,
253
- allowFontScaling: allowFontScaling !== false,
254
- disabled: _disabled,
255
- ellipsizeMode: ellipsizeMode ?? 'tail',
256
180
  nativeID: _nativeID,
257
181
  numberOfLines: _numberOfLines,
258
182
  selectable: _selectable,
259
183
  selectionColor: _selectionColor,
260
184
  style: _style,
185
+ disabled: disabled,
261
186
  children,
262
187
  }}
263
188
  textPressabilityProps={{
@@ -276,58 +201,135 @@ const Text: React.AbstractComponent<TextProps, TextForwardRef> =
276
201
  }}
277
202
  />
278
203
  );
279
- } else {
280
- nativeText = (
281
- <NativeText
282
- {...restProps}
283
- accessibilityLabel={_accessibilityLabel}
284
- accessibilityState={_accessibilityState}
285
- accessible={_accessible}
286
- allowFontScaling={allowFontScaling !== false}
287
- disabled={_disabled}
288
- ellipsizeMode={ellipsizeMode ?? 'tail'}
289
- isHighlighted={false}
290
- nativeID={_nativeID}
291
- numberOfLines={_numberOfLines}
292
- ref={forwardedRef}
293
- selectable={_selectable}
294
- selectionColor={_selectionColor}
295
- style={_style}>
296
- {children}
297
- </NativeText>
298
- );
299
204
  }
300
205
 
301
- if (children == null) {
302
- return nativeText;
303
- }
206
+ return (
207
+ <NativeVirtualText
208
+ {...restProps}
209
+ accessibilityLabel={_accessibilityLabel}
210
+ accessibilityState={_accessibilityState}
211
+ isHighlighted={false}
212
+ isPressable={false}
213
+ nativeID={_nativeID}
214
+ numberOfLines={_numberOfLines}
215
+ ref={forwardedRef}
216
+ selectable={_selectable}
217
+ selectionColor={_selectionColor}
218
+ style={_style}
219
+ disabled={disabled}>
220
+ {children}
221
+ </NativeVirtualText>
222
+ );
223
+ }
304
224
 
305
- // If the children do not contain a JSX element it would not be possible to have a
306
- // nested `Text` component so we can skip adding the `TextAncestor` context wrapper
307
- // which has a performance overhead. Since we do this for performance reasons we need
308
- // to keep the check simple to avoid regressing overall perf. For this reason the
309
- // `children.length` constant is set to `3`, this should be a reasonable tradeoff
310
- // to capture the majority of `Text` uses but also not make this check too expensive.
311
- if (Array.isArray(children) && children.length <= 3) {
312
- let hasNonTextChild = false;
313
- for (let child of children) {
314
- if (child != null && typeof child === 'object') {
315
- hasNonTextChild = true;
316
- break;
317
- }
318
- }
319
- if (!hasNonTextChild) {
320
- return nativeText;
225
+ // If the disabled prop and accessibilityState.disabled are out of sync but not both in
226
+ // falsy states we need to update the accessibilityState object to use the disabled prop.
227
+ if (
228
+ _disabled !== _accessibilityStateDisabled &&
229
+ ((_disabled != null && _disabled !== false) ||
230
+ (_accessibilityStateDisabled != null &&
231
+ _accessibilityStateDisabled !== false))
232
+ ) {
233
+ _accessibilityState = {..._accessibilityState, disabled: _disabled};
234
+ }
235
+
236
+ const _accessible = Platform.select({
237
+ ios: accessible !== false,
238
+ android:
239
+ accessible == null
240
+ ? onPress != null || onLongPress != null
241
+ : accessible,
242
+ default: accessible,
243
+ });
244
+
245
+ let nativeText = null;
246
+ if (isPressable) {
247
+ nativeText = (
248
+ <NativePressableText
249
+ ref={forwardedRef}
250
+ textProps={{
251
+ ...restProps,
252
+ accessibilityLabel: _accessibilityLabel,
253
+ accessibilityState: _accessibilityState,
254
+ accessible: _accessible,
255
+ allowFontScaling: allowFontScaling !== false,
256
+ disabled: _disabled,
257
+ ellipsizeMode: ellipsizeMode ?? 'tail',
258
+ nativeID: _nativeID,
259
+ numberOfLines: _numberOfLines,
260
+ selectable: _selectable,
261
+ selectionColor: _selectionColor,
262
+ style: _style,
263
+ children,
264
+ }}
265
+ textPressabilityProps={{
266
+ onLongPress,
267
+ onPress,
268
+ onPressIn,
269
+ onPressOut,
270
+ onResponderGrant,
271
+ onResponderMove,
272
+ onResponderRelease,
273
+ onResponderTerminate,
274
+ onResponderTerminationRequest,
275
+ onStartShouldSetResponder,
276
+ pressRetentionOffset,
277
+ suppressHighlighting,
278
+ }}
279
+ />
280
+ );
281
+ } else {
282
+ nativeText = (
283
+ <NativeText
284
+ {...restProps}
285
+ accessibilityLabel={_accessibilityLabel}
286
+ accessibilityState={_accessibilityState}
287
+ accessible={_accessible}
288
+ allowFontScaling={allowFontScaling !== false}
289
+ disabled={_disabled}
290
+ ellipsizeMode={ellipsizeMode ?? 'tail'}
291
+ isHighlighted={false}
292
+ nativeID={_nativeID}
293
+ numberOfLines={_numberOfLines}
294
+ ref={forwardedRef}
295
+ selectable={_selectable}
296
+ selectionColor={_selectionColor}
297
+ style={_style}>
298
+ {children}
299
+ </NativeText>
300
+ );
301
+ }
302
+
303
+ if (children == null) {
304
+ return nativeText;
305
+ }
306
+
307
+ // If the children do not contain a JSX element it would not be possible to have a
308
+ // nested `Text` component so we can skip adding the `TextAncestor` context wrapper
309
+ // which has a performance overhead. Since we do this for performance reasons we need
310
+ // to keep the check simple to avoid regressing overall perf. For this reason the
311
+ // `children.length` constant is set to `3`, this should be a reasonable tradeoff
312
+ // to capture the majority of `Text` uses but also not make this check too expensive.
313
+ if (Array.isArray(children) && children.length <= 3) {
314
+ let hasNonTextChild = false;
315
+ for (let child of children) {
316
+ if (child != null && typeof child === 'object') {
317
+ hasNonTextChild = true;
318
+ break;
321
319
  }
322
- } else if (typeof children !== 'object') {
320
+ }
321
+ if (!hasNonTextChild) {
323
322
  return nativeText;
324
323
  }
324
+ } else if (typeof children !== 'object') {
325
+ return nativeText;
326
+ }
325
327
 
326
- return (
327
- <TextAncestor.Provider value={true}>{nativeText}</TextAncestor.Provider>
328
- );
329
- },
330
- );
328
+ return (
329
+ <TextAncestor.Provider value={true}>{nativeText}</TextAncestor.Provider>
330
+ );
331
+ },
332
+ );
331
333
 
332
334
  Text.displayName = 'Text';
333
335
 
@@ -476,10 +478,10 @@ type NativePressableTextProps = $ReadOnly<{
476
478
  * This logic is split out from the main Text component to enable the more
477
479
  * expensive pressability logic to be only initialized when needed.
478
480
  */
479
- const NativePressableVirtualText: React.AbstractComponent<
480
- NativePressableTextProps,
481
- TextForwardRef,
482
- > = React.forwardRef(({textProps, textPressabilityProps}, forwardedRef) => {
481
+ const NativePressableVirtualText: component(
482
+ ref: React.RefSetter<TextForwardRef>,
483
+ ...props: NativePressableTextProps
484
+ ) = React.forwardRef(({textProps, textPressabilityProps}, forwardedRef) => {
483
485
  const [isHighlighted, eventHandlersForText] = useTextPressability(
484
486
  textPressabilityProps,
485
487
  );
@@ -501,10 +503,10 @@ const NativePressableVirtualText: React.AbstractComponent<
501
503
  * This logic is split out from the main Text component to enable the more
502
504
  * expensive pressability logic to be only initialized when needed.
503
505
  */
504
- const NativePressableText: React.AbstractComponent<
505
- NativePressableTextProps,
506
- TextForwardRef,
507
- > = React.forwardRef(({textProps, textPressabilityProps}, forwardedRef) => {
506
+ const NativePressableText: component(
507
+ ref: React.RefSetter<TextForwardRef>,
508
+ ...props: NativePressableTextProps
509
+ ) = React.forwardRef(({textProps, textPressabilityProps}, forwardedRef) => {
508
510
  const [isHighlighted, eventHandlersForText] = useTextPressability(
509
511
  textPressabilityProps,
510
512
  );