@office-iss/react-native-win32 0.81.2 → 0.82.0-preview.2

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 (209) hide show
  1. package/.flowconfig +3 -11
  2. package/CHANGELOG.json +118 -43
  3. package/CHANGELOG.md +45 -27
  4. package/IntegrationTests/IntegrationTestsApp.js +2 -2
  5. package/IntegrationTests/LayoutEventsTest.js +3 -3
  6. package/Libraries/ActionSheetIOS/ActionSheetIOS.js +7 -3
  7. package/Libraries/Alert/RCTAlertManager.android.js +4 -2
  8. package/Libraries/Animated/Animated.d.ts +2 -0
  9. package/Libraries/Animated/AnimatedEvent.js +1 -1
  10. package/Libraries/Animated/AnimatedExports.js.flow +1 -0
  11. package/Libraries/Animated/AnimatedImplementation.js +4 -2
  12. package/Libraries/Animated/AnimatedMock.js +1 -1
  13. package/Libraries/Animated/Easing.js +2 -0
  14. package/Libraries/Animated/NativeAnimatedAllowlist.js +1 -0
  15. package/Libraries/Animated/animations/Animation.js +19 -20
  16. package/Libraries/Animated/animations/TimingAnimation.js +2 -0
  17. package/Libraries/Animated/components/AnimatedScrollView.js +3 -2
  18. package/Libraries/Animated/components/AnimatedSectionList.js +1 -1
  19. package/Libraries/Animated/nodes/AnimatedColor.js +9 -9
  20. package/Libraries/Animated/nodes/AnimatedInterpolation.js +4 -4
  21. package/Libraries/Animated/nodes/AnimatedNode.js +14 -7
  22. package/Libraries/Animated/nodes/AnimatedObject.js +7 -7
  23. package/Libraries/Animated/nodes/AnimatedProps.js +32 -32
  24. package/Libraries/Animated/nodes/AnimatedStyle.js +23 -21
  25. package/Libraries/Animated/nodes/AnimatedTransform.js +6 -6
  26. package/Libraries/Animated/nodes/AnimatedValue.js +18 -26
  27. package/Libraries/AppState/AppState.js +8 -4
  28. package/Libraries/BatchedBridge/BatchedBridge.js +1 -0
  29. package/Libraries/BatchedBridge/MessageQueue.js +5 -0
  30. package/Libraries/BatchedBridge/NativeModules.js +1 -1
  31. package/Libraries/Blob/BlobManager.js +1 -1
  32. package/Libraries/Blob/URLSearchParams.js +2 -0
  33. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +2 -2
  34. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +2 -2
  35. package/Libraries/Components/Button.js +1 -1
  36. package/Libraries/Components/Button.win32.js +1 -1
  37. package/Libraries/Components/Pressable/Pressable.js +10 -1
  38. package/Libraries/Components/Pressable/Pressable.win32.js +9 -0
  39. package/Libraries/Components/Pressable/useAndroidRippleForView.js +2 -2
  40. package/Libraries/Components/ScrollView/ScrollView.js +13 -4
  41. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +1 -1
  42. package/Libraries/Components/StatusBar/StatusBar.js +2 -2
  43. package/Libraries/Components/Switch/Switch.js +1 -1
  44. package/Libraries/Components/TextInput/TextInput.flow.js +12 -5
  45. package/Libraries/Components/TextInput/TextInput.flow.win32.js +12 -5
  46. package/Libraries/Components/TextInput/TextInput.js +14 -5
  47. package/Libraries/Components/TextInput/TextInput.win32.js +15 -7
  48. package/Libraries/Components/TextInput/TextInputState.js +1 -1
  49. package/Libraries/Components/TextInput/TextInputState.win32.js +1 -1
  50. package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +2 -3
  51. package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
  52. package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
  53. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +1 -1
  54. package/Libraries/Components/Touchable/TouchableOpacity.js +1 -1
  55. package/Libraries/Components/Touchable/TouchableWin32.js +1 -1
  56. package/Libraries/Components/Touchable/TouchableWin32.js.map +1 -1
  57. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +3 -3
  58. package/Libraries/Components/View/View.js +81 -167
  59. package/Libraries/Components/View/View.win32.js +3 -1
  60. package/Libraries/Core/Devtools/loadBundleFromServer.js +1 -1
  61. package/Libraries/Core/Devtools/loadBundleFromServer.win32.js +1 -1
  62. package/Libraries/Core/ExceptionsManager.js +4 -2
  63. package/Libraries/Core/ReactFiberErrorDialog.js +3 -3
  64. package/Libraries/Core/ReactNativeVersion.js +37 -10
  65. package/Libraries/Core/Timers/JSTimers.js +4 -1
  66. package/Libraries/Core/Timers/NativeTiming.js +1 -0
  67. package/Libraries/Core/Timers/immediateShim.js +2 -1
  68. package/Libraries/Core/Timers/queueMicrotask.js +1 -0
  69. package/Libraries/Core/setUpPerformance.js +3 -4
  70. package/Libraries/Debugging/DebuggingOverlayRegistry.js +5 -3
  71. package/Libraries/Image/Image.android.js +327 -111
  72. package/Libraries/Image/Image.ios.js +6 -1
  73. package/Libraries/Image/Image.win32.js +6 -1
  74. package/Libraries/Image/ImageSourceUtils.js +8 -2
  75. package/Libraries/Image/assetPaths.js +1 -1
  76. package/Libraries/Image/resolveAssetSource.js +1 -1
  77. package/Libraries/Image/resolveAssetSource.win32.js +6 -7
  78. package/Libraries/Interaction/InteractionManager.js +118 -167
  79. package/Libraries/Interaction/PanResponder.js +7 -52
  80. package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -0
  81. package/Libraries/Lists/FlatList.js +5 -6
  82. package/Libraries/LogBox/Data/LogBoxData.js +5 -2
  83. package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
  84. package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +2 -2
  85. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +1 -1
  86. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.win32.js +1 -1
  87. package/Libraries/Modal/Modal.js +3 -3
  88. package/Libraries/NativeComponent/NativeComponentRegistry.js +1 -1
  89. package/Libraries/NativeComponent/ViewConfig.js +2 -2
  90. package/Libraries/Network/RCTNetworking.android.js +1 -1
  91. package/Libraries/Network/RCTNetworking.ios.js +1 -1
  92. package/Libraries/Network/RCTNetworking.win32.js +1 -1
  93. package/Libraries/Network/XMLHttpRequest.js +20 -5
  94. package/Libraries/Network/convertRequestBody.js +1 -1
  95. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +10 -9
  96. package/Libraries/Pressability/HoverState.js +2 -0
  97. package/Libraries/Pressability/HoverState.win32.js +2 -0
  98. package/Libraries/Pressability/Pressability.js +1 -1
  99. package/Libraries/Pressability/Pressability.win32.js +1 -1
  100. package/Libraries/PushNotificationIOS/PushNotificationIOS.js +2 -2
  101. package/Libraries/ReactNative/AppRegistryImpl.js +4 -2
  102. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +2 -0
  103. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +3 -3
  104. package/Libraries/ReactNative/RendererImplementation.js +116 -116
  105. package/Libraries/ReactNative/UIManager.js +3 -3
  106. package/Libraries/ReactNative/renderApplication.js +1 -0
  107. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +1 -1
  108. package/Libraries/Renderer/implementations/ReactFabric-dev.js +38 -35
  109. package/Libraries/Renderer/implementations/ReactFabric-prod.js +51 -22
  110. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +54 -24
  111. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +36 -33
  112. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +5 -5
  113. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +5 -5
  114. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -1
  115. package/Libraries/Share/Share.js +4 -0
  116. package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +2 -2
  117. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +2 -2
  118. package/Libraries/StyleSheet/PlatformColorValueTypes.win32.js +4 -0
  119. package/Libraries/StyleSheet/StyleSheet.d.ts +7 -22
  120. package/Libraries/StyleSheet/StyleSheetExports.js +2 -8
  121. package/Libraries/StyleSheet/StyleSheetExports.js.flow +11 -18
  122. package/Libraries/StyleSheet/flattenStyle.js +2 -2
  123. package/Libraries/StyleSheet/processAspectRatio.js +2 -0
  124. package/Libraries/StyleSheet/processFilter.js +5 -5
  125. package/Libraries/StyleSheet/splitLayoutProps.js +2 -2
  126. package/Libraries/Text/Text.js +534 -234
  127. package/Libraries/Text/Text.win32.js +647 -274
  128. package/Libraries/Text/TextNativeComponent.js +2 -2
  129. package/Libraries/Text/TextNativeComponent.win32.js +2 -2
  130. package/Libraries/Utilities/Appearance.d.ts +3 -5
  131. package/Libraries/Utilities/Appearance.js +5 -17
  132. package/Libraries/Utilities/HMRClient.js +2 -1
  133. package/Libraries/Utilities/Platform.android.js +3 -3
  134. package/Libraries/Utilities/Platform.d.ts +1 -0
  135. package/Libraries/Utilities/Platform.ios.js +1 -1
  136. package/Libraries/Utilities/Platform.win32.js +3 -3
  137. package/Libraries/Utilities/PlatformTypes.js +1 -1
  138. package/Libraries/Utilities/ReactNativeTestTools.js +12 -0
  139. package/Libraries/Utilities/SceneTracker.js +1 -1
  140. package/Libraries/Utilities/codegenNativeCommands.js +1 -1
  141. package/Libraries/Utilities/codegenNativeComponent.js +1 -1
  142. package/Libraries/Utilities/createPerformanceLogger.js +32 -0
  143. package/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +2 -0
  144. package/Libraries/Utilities/differ/pointsDiffer.js +1 -1
  145. package/Libraries/Utilities/useMergeRefs.js +1 -1
  146. package/Libraries/WebSocket/WebSocketInterceptor.js +2 -0
  147. package/Libraries/promiseRejectionTrackingOptions.js +17 -31
  148. package/Libraries/vendor/emitter/EventEmitter.js +1 -1
  149. package/flow/bom.js.flow +223 -1
  150. package/flow/prettier.js.flow +14 -0
  151. package/index.js +14 -2
  152. package/index.win32.js +16 -2
  153. package/jest/local-setup.js +2 -2
  154. package/jest/mock.js +1 -1
  155. package/jest/mockComponent.js +9 -9
  156. package/jest/mockNativeComponent.js +3 -2
  157. package/jest/mocks/Modal.js +1 -1
  158. package/jest/mocks/ScrollView.js +1 -1
  159. package/jest/mocks/ViewNativeComponent.js +1 -1
  160. package/jest/setup.js +23 -12
  161. package/overrides.json +23 -23
  162. package/package.json +28 -27
  163. package/saveAssetPlugin.js +2 -2
  164. package/src/private/animated/NativeAnimatedHelper.js +16 -5
  165. package/src/private/animated/NativeAnimatedHelper.win32.js +16 -5
  166. package/src/private/animated/createAnimatedPropsHook.js +11 -60
  167. package/src/private/animated/createAnimatedPropsMemoHook.js +8 -54
  168. package/src/private/components/virtualview/VirtualView.js +43 -12
  169. package/src/private/components/virtualview/VirtualViewExperimentalNativeComponent.js +93 -0
  170. package/src/private/components/virtualview/VirtualViewNativeComponent.js +6 -0
  171. package/src/private/devsupport/devmenu/elementinspector/Inspector.js +2 -2
  172. package/src/private/devsupport/devmenu/elementinspector/ReactDevToolsOverlay.js +2 -2
  173. package/src/private/featureflags/ReactNativeFeatureFlags.js +85 -52
  174. package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +23 -4
  175. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +15 -6
  176. package/src/private/renderer/errorhandling/ErrorHandlers.js +3 -3
  177. package/src/private/setup/{setUpPerformanceObserver.js → setUpPerformanceModern.js} +43 -18
  178. package/src/private/specs_DEPRECATED/modules/NativeTiming.js +1 -0
  179. package/src/private/types/HostInstance.js +4 -1
  180. package/src/private/webapis/dom/nodes/ReactNativeDocument.js +22 -2
  181. package/src/private/webapis/dom/nodes/ReactNativeElement.js +1 -1
  182. package/src/private/webapis/dom/nodes/ReadOnlyElement.js +5 -3
  183. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +16 -13
  184. package/src/private/webapis/dom/nodes/internals/NodeInternals.js +45 -22
  185. package/src/private/webapis/dom/nodes/internals/ReactNativeDocumentInstanceHandle.js +1 -1
  186. package/src/private/webapis/dom/nodes/specs/NativeDOM.js +26 -192
  187. package/src/private/webapis/dom/oldstylecollections/HTMLCollection.js +15 -12
  188. package/src/private/webapis/dom/oldstylecollections/NodeList.js +14 -11
  189. package/src/private/webapis/geometry/DOMRectList.js +2 -2
  190. package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +19 -74
  191. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +0 -4
  192. package/src/private/webapis/mutationobserver/internals/MutationObserverManager.js +1 -1
  193. package/src/private/webapis/performance/EventTiming.js +40 -25
  194. package/src/private/webapis/performance/LongTasks.js +35 -2
  195. package/src/private/webapis/performance/Performance.js +347 -166
  196. package/src/private/webapis/performance/PerformanceEntry.js +40 -23
  197. package/src/private/webapis/performance/PerformanceObserver.js +37 -29
  198. package/src/private/webapis/performance/ReactNativeStartupTiming.js +3 -24
  199. package/src/private/webapis/performance/ResourceTiming.js +29 -18
  200. package/src/private/webapis/performance/UserTiming.js +92 -34
  201. package/src/private/webapis/performance/UserTimingExtensibility.js.flow +38 -0
  202. package/src/private/webapis/performance/internals/RawPerformanceEntry.js +3 -4
  203. package/src/private/webapis/performance/internals/Utilities.js +9 -0
  204. package/src/private/webapis/performance/specs/NativePerformance.js +23 -23
  205. package/src/private/webapis/structuredClone/structuredClone.js +10 -10
  206. package/src-win/Libraries/Components/Touchable/TouchableWin32.tsx +1 -1
  207. package/Libraries/Interaction/InteractionManagerStub.js +0 -184
  208. package/Libraries/Interaction/TaskQueue.js +0 -183
  209. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +0 -31
@@ -14,6 +14,7 @@ import type {GestureResponderEvent} from '../Types/CoreEventTypes';
14
14
  import type {NativeTextProps} from './TextNativeComponent';
15
15
  import type {PressRetentionOffset, TextProps} from './TextProps';
16
16
 
17
+ import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';
17
18
  import * as PressabilityDebug from '../Pressability/PressabilityDebug';
18
19
  import usePressability from '../Pressability/usePressability';
19
20
  import flattenStyle from '../StyleSheet/flattenStyle';
@@ -35,156 +36,519 @@ type TextForwardRef = React.ElementRef<
35
36
  *
36
37
  * @see https://reactnative.dev/docs/text
37
38
  */
38
- const TextImpl: component(
39
- ref?: React.RefSetter<TextForwardRef>,
40
- ...props: TextProps
41
- ) = ({
42
- ref: forwardedRef,
43
- accessible,
44
- accessibilityLabel,
45
- accessibilityState,
46
- allowFontScaling,
47
- 'aria-busy': ariaBusy,
48
- 'aria-checked': ariaChecked,
49
- 'aria-disabled': ariaDisabled,
50
- 'aria-expanded': ariaExpanded,
51
- 'aria-label': ariaLabel,
52
- 'aria-selected': ariaSelected,
53
- children,
54
- ellipsizeMode,
55
- disabled,
56
- id,
57
- nativeID,
58
- numberOfLines,
59
- onLongPress,
60
- onPress,
61
- onPressIn,
62
- onPressOut,
63
- onResponderGrant,
64
- onResponderMove,
65
- onResponderRelease,
66
- onResponderTerminate,
67
- onResponderTerminationRequest,
68
- onStartShouldSetResponder,
69
- pressRetentionOffset,
70
- selectable,
71
- selectionColor,
72
- suppressHighlighting,
73
- style,
74
- ...restProps
75
- }: {
76
- ref?: React.RefSetter<TextForwardRef>,
77
- ...TextProps,
78
- }) => {
79
- const _accessibilityLabel = ariaLabel ?? accessibilityLabel;
80
-
81
- let _accessibilityState: ?TextProps['accessibilityState'] =
82
- accessibilityState;
83
- if (
84
- ariaBusy != null ||
85
- ariaChecked != null ||
86
- ariaDisabled != null ||
87
- ariaExpanded != null ||
88
- ariaSelected != null
89
- ) {
90
- if (_accessibilityState != null) {
91
- _accessibilityState = {
92
- busy: ariaBusy ?? _accessibilityState.busy,
93
- checked: ariaChecked ?? _accessibilityState.checked,
94
- disabled: ariaDisabled ?? _accessibilityState.disabled,
95
- expanded: ariaExpanded ?? _accessibilityState.expanded,
96
- selected: ariaSelected ?? _accessibilityState.selected,
39
+ let _TextImpl;
40
+ if (ReactNativeFeatureFlags.reduceDefaultPropsInText()) {
41
+ const TextImplNoDefaultProps: component(
42
+ ref?: React.RefSetter<TextForwardRef>,
43
+ ...props: TextProps
44
+ ) = ({
45
+ ref: forwardedRef,
46
+ accessible,
47
+ accessibilityLabel,
48
+ accessibilityState,
49
+ allowFontScaling,
50
+ 'aria-busy': ariaBusy,
51
+ 'aria-checked': ariaChecked,
52
+ 'aria-disabled': ariaDisabled,
53
+ 'aria-expanded': ariaExpanded,
54
+ 'aria-hidden': ariaHidden,
55
+ 'aria-label': ariaLabel,
56
+ 'aria-selected': ariaSelected,
57
+ children,
58
+ ellipsizeMode,
59
+ disabled,
60
+ id,
61
+ nativeID,
62
+ numberOfLines,
63
+ onLongPress,
64
+ onPress,
65
+ onPressIn,
66
+ onPressOut,
67
+ onResponderGrant,
68
+ onResponderMove,
69
+ onResponderRelease,
70
+ onResponderTerminate,
71
+ onResponderTerminationRequest,
72
+ onStartShouldSetResponder,
73
+ pressRetentionOffset,
74
+ selectable,
75
+ selectionColor,
76
+ suppressHighlighting,
77
+ style,
78
+ ...restProps
79
+ }: {
80
+ ref?: React.RefSetter<TextForwardRef>,
81
+ ...TextProps,
82
+ }) => {
83
+ const processedProps = restProps as {
84
+ ...NativeTextProps,
85
+ };
86
+ const _accessibilityLabel = ariaLabel ?? accessibilityLabel;
87
+ let _accessibilityState: ?TextProps['accessibilityState'] =
88
+ accessibilityState;
89
+ if (
90
+ ariaBusy != null ||
91
+ ariaChecked != null ||
92
+ ariaDisabled != null ||
93
+ ariaExpanded != null ||
94
+ ariaSelected != null
95
+ ) {
96
+ if (_accessibilityState != null) {
97
+ _accessibilityState = {
98
+ busy: ariaBusy ?? _accessibilityState.busy,
99
+ checked: ariaChecked ?? _accessibilityState.checked,
100
+ disabled: ariaDisabled ?? _accessibilityState.disabled,
101
+ expanded: ariaExpanded ?? _accessibilityState.expanded,
102
+ selected: ariaSelected ?? _accessibilityState.selected,
103
+ };
104
+ } else {
105
+ _accessibilityState = {
106
+ busy: ariaBusy,
107
+ checked: ariaChecked,
108
+ disabled: ariaDisabled,
109
+ expanded: ariaExpanded,
110
+ selected: ariaSelected,
111
+ };
112
+ }
113
+ }
114
+
115
+ const _accessibilityStateDisabled = _accessibilityState?.disabled;
116
+ const _disabled = disabled ?? _accessibilityStateDisabled;
117
+
118
+ // If the disabled prop and accessibilityState.disabled are out of sync but not both in
119
+ // falsy states we need to update the accessibilityState object to use the disabled prop.
120
+ if (
121
+ _accessibilityState != null &&
122
+ _disabled !== _accessibilityStateDisabled &&
123
+ ((_disabled != null && _disabled !== false) ||
124
+ (_accessibilityStateDisabled != null &&
125
+ _accessibilityStateDisabled !== false))
126
+ ) {
127
+ _accessibilityState.disabled = _disabled;
128
+ }
129
+
130
+ if (ariaHidden !== undefined) {
131
+ processedProps.accessibilityElementsHidden = ariaHidden;
132
+ if (ariaHidden === true) {
133
+ processedProps.importantForAccessibility = 'no-hide-descendants';
134
+ }
135
+ }
136
+
137
+ const _accessible = Platform.select({
138
+ ios: accessible !== false,
139
+ android:
140
+ accessible == null
141
+ ? onPress != null || onLongPress != null
142
+ : accessible,
143
+ default: accessible,
144
+ });
145
+
146
+ const isPressable =
147
+ (onPress != null ||
148
+ onLongPress != null ||
149
+ onStartShouldSetResponder != null) &&
150
+ _disabled !== true;
151
+
152
+ // TODO: Move this processing to the view configuration.
153
+ const _selectionColor =
154
+ selectionColor != null ? processColor(selectionColor) : undefined;
155
+
156
+ let _style = style;
157
+ if (__DEV__) {
158
+ if (PressabilityDebug.isEnabled() && onPress != null) {
159
+ _style = [style, {color: 'magenta'}];
160
+ }
161
+ }
162
+
163
+ let _numberOfLines = numberOfLines;
164
+ if (_numberOfLines != null && !(_numberOfLines >= 0)) {
165
+ if (__DEV__) {
166
+ console.error(
167
+ `'numberOfLines' in <Text> must be a non-negative number, received: ${_numberOfLines}. The value will be set to 0.`,
168
+ );
169
+ }
170
+ _numberOfLines = 0;
171
+ }
172
+
173
+ let _selectable = selectable;
174
+
175
+ let processedStyle = flattenStyle<TextStyleProp>(_style);
176
+ if (processedStyle != null) {
177
+ let overrides: ?{...TextStyleInternal} = null;
178
+ if (typeof processedStyle.fontWeight === 'number') {
179
+ overrides = overrides || ({}: {...TextStyleInternal});
180
+ overrides.fontWeight =
181
+ // $FlowFixMe[incompatible-type]
182
+ (String(processedStyle.fontWeight): TextStyleInternal['fontWeight']);
183
+ }
184
+
185
+ if (processedStyle.userSelect != null) {
186
+ _selectable = userSelectToSelectableMap[processedStyle.userSelect];
187
+ overrides = overrides || ({}: {...TextStyleInternal});
188
+ overrides.userSelect = undefined;
189
+ }
190
+
191
+ if (processedStyle.verticalAlign != null) {
192
+ overrides = overrides || ({}: {...TextStyleInternal});
193
+ overrides.textAlignVertical =
194
+ verticalAlignToTextAlignVerticalMap[processedStyle.verticalAlign];
195
+ overrides.verticalAlign = undefined;
196
+ }
197
+
198
+ if (overrides != null) {
199
+ // $FlowFixMe[incompatible-type]
200
+ _style = [_style, overrides];
201
+ }
202
+ }
203
+
204
+ const _nativeID = id ?? nativeID;
205
+
206
+ if (_accessibilityLabel !== undefined) {
207
+ processedProps.accessibilityLabel = _accessibilityLabel;
208
+ }
209
+ if (_accessibilityState !== undefined) {
210
+ processedProps.accessibilityState = _accessibilityState;
211
+ }
212
+ if (_nativeID !== undefined) {
213
+ processedProps.nativeID = _nativeID;
214
+ }
215
+ if (_numberOfLines !== undefined) {
216
+ processedProps.numberOfLines = _numberOfLines;
217
+ }
218
+ if (_selectable !== undefined) {
219
+ processedProps.selectable = _selectable;
220
+ }
221
+ if (_style !== undefined) {
222
+ processedProps.style = _style;
223
+ }
224
+ if (_selectionColor !== undefined) {
225
+ processedProps.selectionColor = _selectionColor;
226
+ }
227
+
228
+ let textPressabilityProps: ?TextPressabilityProps;
229
+ if (isPressable) {
230
+ textPressabilityProps = {
231
+ onLongPress,
232
+ onPress,
233
+ onPressIn,
234
+ onPressOut,
235
+ onResponderGrant,
236
+ onResponderMove,
237
+ onResponderRelease,
238
+ onResponderTerminate,
239
+ onResponderTerminationRequest,
240
+ onStartShouldSetResponder,
241
+ pressRetentionOffset,
242
+ suppressHighlighting,
97
243
  };
244
+ }
245
+
246
+ const hasTextAncestor = useContext(TextAncestorContext);
247
+ if (hasTextAncestor) {
248
+ processedProps.disabled = disabled;
249
+ processedProps.children = children;
250
+ if (isPressable) {
251
+ return (
252
+ <NativePressableVirtualText
253
+ ref={forwardedRef}
254
+ textProps={processedProps}
255
+ textPressabilityProps={textPressabilityProps ?? {}}
256
+ />
257
+ );
258
+ }
259
+ return <NativeVirtualText {...processedProps} ref={forwardedRef} />;
260
+ }
261
+
262
+ let nativeText = null;
263
+
264
+ processedProps.accessible = _accessible;
265
+ processedProps.allowFontScaling = allowFontScaling !== false;
266
+ processedProps.disabled = _disabled;
267
+ processedProps.ellipsizeMode = ellipsizeMode ?? 'tail';
268
+ processedProps.children = children;
269
+
270
+ if (isPressable) {
271
+ nativeText = (
272
+ <NativePressableText
273
+ ref={forwardedRef}
274
+ textProps={processedProps}
275
+ textPressabilityProps={textPressabilityProps ?? {}}
276
+ />
277
+ );
98
278
  } else {
99
- _accessibilityState = {
100
- busy: ariaBusy,
101
- checked: ariaChecked,
102
- disabled: ariaDisabled,
103
- expanded: ariaExpanded,
104
- selected: ariaSelected,
105
- };
279
+ nativeText = <NativeText {...processedProps} ref={forwardedRef} />;
106
280
  }
107
- }
108
281
 
109
- const _accessibilityStateDisabled = _accessibilityState?.disabled;
110
- const _disabled = disabled ?? _accessibilityStateDisabled;
282
+ if (children == null) {
283
+ return nativeText;
284
+ }
111
285
 
112
- const isPressable =
113
- (onPress != null ||
114
- onLongPress != null ||
115
- onStartShouldSetResponder != null) &&
116
- _disabled !== true;
286
+ // If the children do not contain a JSX element it would not be possible to have a
287
+ // nested `Text` component so we can skip adding the `TextAncestorContext` context wrapper
288
+ // which has a performance overhead. Since we do this for performance reasons we need
289
+ // to keep the check simple to avoid regressing overall perf. For this reason the
290
+ // `children.length` constant is set to `3`, this should be a reasonable tradeoff
291
+ // to capture the majority of `Text` uses but also not make this check too expensive.
292
+ if (Array.isArray(children) && children.length <= 3) {
293
+ let hasNonTextChild = false;
294
+ for (let child of children) {
295
+ if (child != null && typeof child === 'object') {
296
+ hasNonTextChild = true;
297
+ break;
298
+ }
299
+ }
300
+ if (!hasNonTextChild) {
301
+ return nativeText;
302
+ }
303
+ } else if (typeof children !== 'object') {
304
+ return nativeText;
305
+ }
117
306
 
118
- // TODO: Move this processing to the view configuration.
119
- const _selectionColor =
120
- selectionColor != null ? processColor(selectionColor) : undefined;
307
+ return <TextAncestorContext value={true}>{nativeText}</TextAncestorContext>;
308
+ };
309
+ _TextImpl = TextImplNoDefaultProps;
310
+ } else {
311
+ const TextImplLegacy: component(
312
+ ref?: React.RefSetter<TextForwardRef>,
313
+ ...props: TextProps
314
+ ) = ({
315
+ ref: forwardedRef,
316
+ accessible,
317
+ accessibilityElementsHidden,
318
+ importantForAccessibility,
319
+ accessibilityLabel,
320
+ accessibilityState,
321
+ allowFontScaling,
322
+ 'aria-busy': ariaBusy,
323
+ 'aria-checked': ariaChecked,
324
+ 'aria-disabled': ariaDisabled,
325
+ 'aria-expanded': ariaExpanded,
326
+ 'aria-hidden': ariaHidden,
327
+ 'aria-label': ariaLabel,
328
+ 'aria-selected': ariaSelected,
329
+ children,
330
+ ellipsizeMode,
331
+ disabled,
332
+ id,
333
+ nativeID,
334
+ numberOfLines,
335
+ onLongPress,
336
+ onPress,
337
+ onPressIn,
338
+ onPressOut,
339
+ onResponderGrant,
340
+ onResponderMove,
341
+ onResponderRelease,
342
+ onResponderTerminate,
343
+ onResponderTerminationRequest,
344
+ onStartShouldSetResponder,
345
+ pressRetentionOffset,
346
+ selectable,
347
+ selectionColor,
348
+ suppressHighlighting,
349
+ style,
350
+ ...restProps
351
+ }: {
352
+ ref?: React.RefSetter<TextForwardRef>,
353
+ ...TextProps,
354
+ }) => {
355
+ const _accessibilityLabel = ariaLabel ?? accessibilityLabel;
356
+
357
+ let _accessibilityState: ?TextProps['accessibilityState'] =
358
+ accessibilityState;
359
+ if (
360
+ ariaBusy != null ||
361
+ ariaChecked != null ||
362
+ ariaDisabled != null ||
363
+ ariaExpanded != null ||
364
+ ariaSelected != null
365
+ ) {
366
+ if (_accessibilityState != null) {
367
+ _accessibilityState = {
368
+ busy: ariaBusy ?? _accessibilityState.busy,
369
+ checked: ariaChecked ?? _accessibilityState.checked,
370
+ disabled: ariaDisabled ?? _accessibilityState.disabled,
371
+ expanded: ariaExpanded ?? _accessibilityState.expanded,
372
+ selected: ariaSelected ?? _accessibilityState.selected,
373
+ };
374
+ } else {
375
+ _accessibilityState = {
376
+ busy: ariaBusy,
377
+ checked: ariaChecked,
378
+ disabled: ariaDisabled,
379
+ expanded: ariaExpanded,
380
+ selected: ariaSelected,
381
+ };
382
+ }
383
+ }
121
384
 
122
- let _style = style;
123
- if (__DEV__) {
124
- if (PressabilityDebug.isEnabled() && onPress != null) {
125
- _style = [style, {color: 'magenta'}];
385
+ const _accessibilityStateDisabled = _accessibilityState?.disabled;
386
+ const _disabled = disabled ?? _accessibilityStateDisabled;
387
+
388
+ let _accessibilityElementsHidden =
389
+ ariaHidden ?? accessibilityElementsHidden;
390
+ let _importantForAccessibility = importantForAccessibility;
391
+ if (ariaHidden === true) {
392
+ _importantForAccessibility = 'no-hide-descendants';
126
393
  }
127
- }
128
394
 
129
- let _numberOfLines = numberOfLines;
130
- if (_numberOfLines != null && !(_numberOfLines >= 0)) {
395
+ const isPressable =
396
+ (onPress != null ||
397
+ onLongPress != null ||
398
+ onStartShouldSetResponder != null) &&
399
+ _disabled !== true;
400
+
401
+ // TODO: Move this processing to the view configuration.
402
+ const _selectionColor =
403
+ selectionColor != null ? processColor(selectionColor) : undefined;
404
+
405
+ let _style = style;
131
406
  if (__DEV__) {
132
- console.error(
133
- `'numberOfLines' in <Text> must be a non-negative number, received: ${_numberOfLines}. The value will be set to 0.`,
134
- );
407
+ if (PressabilityDebug.isEnabled() && onPress != null) {
408
+ _style = [style, {color: 'magenta'}];
409
+ }
135
410
  }
136
- _numberOfLines = 0;
137
- }
138
-
139
- let _selectable = selectable;
140
-
141
- let processedStyle = flattenStyle<TextStyleProp>(_style);
142
- if (processedStyle != null) {
143
- let overrides: ?{...TextStyleInternal} = null;
144
- if (typeof processedStyle.fontWeight === 'number') {
145
- overrides = overrides || ({}: {...TextStyleInternal});
146
- overrides.fontWeight =
147
- // $FlowFixMe[incompatible-cast]
148
- (processedStyle.fontWeight.toString(): TextStyleInternal['fontWeight']);
411
+
412
+ let _numberOfLines = numberOfLines;
413
+ if (_numberOfLines != null && !(_numberOfLines >= 0)) {
414
+ if (__DEV__) {
415
+ console.error(
416
+ `'numberOfLines' in <Text> must be a non-negative number, received: ${_numberOfLines}. The value will be set to 0.`,
417
+ );
418
+ }
419
+ _numberOfLines = 0;
149
420
  }
150
421
 
151
- if (processedStyle.userSelect != null) {
152
- _selectable = userSelectToSelectableMap[processedStyle.userSelect];
153
- overrides = overrides || ({}: {...TextStyleInternal});
154
- overrides.userSelect = undefined;
422
+ let _selectable = selectable;
423
+
424
+ let processedStyle = flattenStyle<TextStyleProp>(_style);
425
+ if (processedStyle != null) {
426
+ let overrides: ?{...TextStyleInternal} = null;
427
+ if (typeof processedStyle.fontWeight === 'number') {
428
+ overrides = overrides || ({}: {...TextStyleInternal});
429
+ overrides.fontWeight =
430
+ // $FlowFixMe[incompatible-type]
431
+ (processedStyle.fontWeight.toString(): TextStyleInternal['fontWeight']);
432
+ }
433
+
434
+ if (processedStyle.userSelect != null) {
435
+ _selectable = userSelectToSelectableMap[processedStyle.userSelect];
436
+ overrides = overrides || ({}: {...TextStyleInternal});
437
+ overrides.userSelect = undefined;
438
+ }
439
+
440
+ if (processedStyle.verticalAlign != null) {
441
+ overrides = overrides || ({}: {...TextStyleInternal});
442
+ overrides.textAlignVertical =
443
+ verticalAlignToTextAlignVerticalMap[processedStyle.verticalAlign];
444
+ overrides.verticalAlign = undefined;
445
+ }
446
+
447
+ if (overrides != null) {
448
+ // $FlowFixMe[incompatible-type]
449
+ _style = [_style, overrides];
450
+ }
155
451
  }
156
452
 
157
- if (processedStyle.verticalAlign != null) {
158
- overrides = overrides || ({}: {...TextStyleInternal});
159
- overrides.textAlignVertical =
160
- verticalAlignToTextAlignVerticalMap[processedStyle.verticalAlign];
161
- overrides.verticalAlign = undefined;
453
+ const _nativeID = id ?? nativeID;
454
+
455
+ const hasTextAncestor = useContext(TextAncestorContext);
456
+ if (hasTextAncestor) {
457
+ if (isPressable) {
458
+ return (
459
+ <NativePressableVirtualText
460
+ ref={forwardedRef}
461
+ textProps={{
462
+ ...restProps,
463
+ accessibilityElementsHidden: _accessibilityElementsHidden,
464
+ accessibilityLabel: _accessibilityLabel,
465
+ accessibilityState: _accessibilityState,
466
+ importantForAccessibility: _importantForAccessibility,
467
+ nativeID: _nativeID,
468
+ numberOfLines: _numberOfLines,
469
+ selectable: _selectable,
470
+ selectionColor: _selectionColor,
471
+ style: _style,
472
+ disabled: disabled,
473
+ children,
474
+ }}
475
+ textPressabilityProps={{
476
+ onLongPress,
477
+ onPress,
478
+ onPressIn,
479
+ onPressOut,
480
+ onResponderGrant,
481
+ onResponderMove,
482
+ onResponderRelease,
483
+ onResponderTerminate,
484
+ onResponderTerminationRequest,
485
+ onStartShouldSetResponder,
486
+ pressRetentionOffset,
487
+ suppressHighlighting,
488
+ }}
489
+ />
490
+ );
491
+ }
492
+
493
+ return (
494
+ <NativeVirtualText
495
+ {...restProps}
496
+ accessibilityElementsHidden={_accessibilityElementsHidden}
497
+ accessibilityLabel={_accessibilityLabel}
498
+ accessibilityState={_accessibilityState}
499
+ importantForAccessibility={_importantForAccessibility}
500
+ nativeID={_nativeID}
501
+ numberOfLines={_numberOfLines}
502
+ ref={forwardedRef}
503
+ selectable={_selectable}
504
+ selectionColor={_selectionColor}
505
+ style={_style}
506
+ disabled={disabled}>
507
+ {children}
508
+ </NativeVirtualText>
509
+ );
162
510
  }
163
511
 
164
- if (overrides != null) {
165
- // $FlowFixMe[incompatible-type]
166
- _style = [_style, overrides];
512
+ // If the disabled prop and accessibilityState.disabled are out of sync but not both in
513
+ // falsy states we need to update the accessibilityState object to use the disabled prop.
514
+ if (
515
+ _disabled !== _accessibilityStateDisabled &&
516
+ ((_disabled != null && _disabled !== false) ||
517
+ (_accessibilityStateDisabled != null &&
518
+ _accessibilityStateDisabled !== false))
519
+ ) {
520
+ _accessibilityState = {..._accessibilityState, disabled: _disabled};
167
521
  }
168
- }
169
522
 
170
- const _nativeID = id ?? nativeID;
523
+ const _accessible = Platform.select({
524
+ ios: accessible !== false,
525
+ android:
526
+ accessible == null
527
+ ? onPress != null || onLongPress != null
528
+ : accessible,
529
+ default: accessible,
530
+ });
171
531
 
172
- const hasTextAncestor = useContext(TextAncestorContext);
173
- if (hasTextAncestor) {
532
+ let nativeText = null;
174
533
  if (isPressable) {
175
- return (
176
- <NativePressableVirtualText
534
+ nativeText = (
535
+ <NativePressableText
177
536
  ref={forwardedRef}
178
537
  textProps={{
179
538
  ...restProps,
539
+ accessibilityElementsHidden: _accessibilityElementsHidden,
180
540
  accessibilityLabel: _accessibilityLabel,
181
541
  accessibilityState: _accessibilityState,
542
+ accessible: _accessible,
543
+ allowFontScaling: allowFontScaling !== false,
544
+ disabled: _disabled,
545
+ ellipsizeMode: ellipsizeMode ?? 'tail',
546
+ importantForAccessibility: _importantForAccessibility,
182
547
  nativeID: _nativeID,
183
548
  numberOfLines: _numberOfLines,
184
549
  selectable: _selectable,
185
550
  selectionColor: _selectionColor,
186
551
  style: _style,
187
- disabled: disabled,
188
552
  children,
189
553
  }}
190
554
  textPressabilityProps={{
@@ -203,127 +567,63 @@ const TextImpl: component(
203
567
  }}
204
568
  />
205
569
  );
570
+ } else {
571
+ nativeText = (
572
+ <NativeText
573
+ {...restProps}
574
+ accessibilityElementsHidden={_accessibilityElementsHidden}
575
+ accessibilityLabel={_accessibilityLabel}
576
+ accessibilityState={_accessibilityState}
577
+ accessible={_accessible}
578
+ allowFontScaling={allowFontScaling !== false}
579
+ disabled={_disabled}
580
+ ellipsizeMode={ellipsizeMode ?? 'tail'}
581
+ importantForAccessibility={_importantForAccessibility}
582
+ nativeID={_nativeID}
583
+ numberOfLines={_numberOfLines}
584
+ ref={forwardedRef}
585
+ selectable={_selectable}
586
+ selectionColor={_selectionColor}
587
+ style={_style}>
588
+ {children}
589
+ </NativeText>
590
+ );
206
591
  }
207
592
 
208
- return (
209
- <NativeVirtualText
210
- {...restProps}
211
- accessibilityLabel={_accessibilityLabel}
212
- accessibilityState={_accessibilityState}
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
- }
224
-
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 ? onPress != null || onLongPress != null : accessible,
240
- default: accessible,
241
- });
242
-
243
- let nativeText = null;
244
- if (isPressable) {
245
- nativeText = (
246
- <NativePressableText
247
- ref={forwardedRef}
248
- textProps={{
249
- ...restProps,
250
- accessibilityLabel: _accessibilityLabel,
251
- accessibilityState: _accessibilityState,
252
- accessible: _accessible,
253
- allowFontScaling: allowFontScaling !== false,
254
- disabled: _disabled,
255
- ellipsizeMode: ellipsizeMode ?? 'tail',
256
- nativeID: _nativeID,
257
- numberOfLines: _numberOfLines,
258
- selectable: _selectable,
259
- selectionColor: _selectionColor,
260
- style: _style,
261
- children,
262
- }}
263
- textPressabilityProps={{
264
- onLongPress,
265
- onPress,
266
- onPressIn,
267
- onPressOut,
268
- onResponderGrant,
269
- onResponderMove,
270
- onResponderRelease,
271
- onResponderTerminate,
272
- onResponderTerminationRequest,
273
- onStartShouldSetResponder,
274
- pressRetentionOffset,
275
- suppressHighlighting,
276
- }}
277
- />
278
- );
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
- nativeID={_nativeID}
290
- numberOfLines={_numberOfLines}
291
- ref={forwardedRef}
292
- selectable={_selectable}
293
- selectionColor={_selectionColor}
294
- style={_style}>
295
- {children}
296
- </NativeText>
297
- );
298
- }
299
-
300
- if (children == null) {
301
- return nativeText;
302
- }
303
-
304
- // If the children do not contain a JSX element it would not be possible to have a
305
- // nested `Text` component so we can skip adding the `TextAncestorContext` context wrapper
306
- // which has a performance overhead. Since we do this for performance reasons we need
307
- // to keep the check simple to avoid regressing overall perf. For this reason the
308
- // `children.length` constant is set to `3`, this should be a reasonable tradeoff
309
- // to capture the majority of `Text` uses but also not make this check too expensive.
310
- if (Array.isArray(children) && children.length <= 3) {
311
- let hasNonTextChild = false;
312
- for (let child of children) {
313
- if (child != null && typeof child === 'object') {
314
- hasNonTextChild = true;
315
- break;
316
- }
593
+ if (children == null) {
594
+ return nativeText;
317
595
  }
318
- if (!hasNonTextChild) {
596
+
597
+ // If the children do not contain a JSX element it would not be possible to have a
598
+ // nested `Text` component so we can skip adding the `TextAncestorContext` context wrapper
599
+ // which has a performance overhead. Since we do this for performance reasons we need
600
+ // to keep the check simple to avoid regressing overall perf. For this reason the
601
+ // `children.length` constant is set to `3`, this should be a reasonable tradeoff
602
+ // to capture the majority of `Text` uses but also not make this check too expensive.
603
+ if (Array.isArray(children) && children.length <= 3) {
604
+ let hasNonTextChild = false;
605
+ for (let child of children) {
606
+ if (child != null && typeof child === 'object') {
607
+ hasNonTextChild = true;
608
+ break;
609
+ }
610
+ }
611
+ if (!hasNonTextChild) {
612
+ return nativeText;
613
+ }
614
+ } else if (typeof children !== 'object') {
319
615
  return nativeText;
320
616
  }
321
- } else if (typeof children !== 'object') {
322
- return nativeText;
323
- }
324
617
 
325
- return <TextAncestorContext value={true}>{nativeText}</TextAncestorContext>;
326
- };
618
+ return <TextAncestorContext value={true}>{nativeText}</TextAncestorContext>;
619
+ };
620
+ _TextImpl = TextImplLegacy;
621
+ }
622
+
623
+ const TextImpl: component(
624
+ ref?: React.RefSetter<TextForwardRef>,
625
+ ...props: TextProps
626
+ ) = _TextImpl;
327
627
 
328
628
  TextImpl.displayName = 'Text';
329
629