@office-iss/react-native-win32 0.0.0-canary.257 → 0.0.0-canary.259
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.
- package/.flowconfig +3 -3
- package/CHANGELOG.json +55 -1
- package/CHANGELOG.md +28 -8
- package/Libraries/Alert/Alert.js +3 -0
- package/Libraries/Animated/nodes/AnimatedValue.js +1 -0
- package/Libraries/Animated/useAnimatedProps.js +68 -3
- package/Libraries/BatchedBridge/NativeModules.js +2 -0
- package/Libraries/Components/ScrollView/ScrollView.js +124 -165
- package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +3 -0
- package/Libraries/Components/TextInput/TextInput.js +204 -73
- package/Libraries/Components/TextInput/TextInput.win32.js +204 -79
- package/Libraries/Components/View/ReactNativeStyleAttributes.js +11 -0
- package/Libraries/Core/ErrorHandlers.js +9 -0
- package/Libraries/Core/ExceptionsManager.js +2 -0
- package/Libraries/Core/InitializeCore.js +2 -0
- package/Libraries/Core/ReactFiberErrorDialog.js +3 -0
- package/Libraries/Core/ReactNativeVersion.js +3 -3
- package/Libraries/Core/ReactNativeVersionCheck.win32.js +1 -1
- package/Libraries/Core/setUpGlobals.js +1 -0
- package/Libraries/Core/setUpReactRefresh.js +0 -4
- package/Libraries/Image/ImageViewNativeComponent.js +1 -0
- package/Libraries/Interaction/TaskQueue.js +1 -0
- package/Libraries/Lists/SectionList.js +1 -1
- package/Libraries/LogBox/Data/LogBoxData.js +1 -0
- package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +20 -8
- package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +20 -8
- package/Libraries/NativeComponent/BaseViewConfig.android.js +1 -0
- package/Libraries/NativeComponent/BaseViewConfig.ios.js +3 -0
- package/Libraries/NativeComponent/BaseViewConfig.win32.js +3 -0
- package/Libraries/NativeComponent/NativeComponentRegistry.js +9 -2
- package/Libraries/ReactNative/AppContainer-dev.js +1 -5
- package/Libraries/ReactNative/AppContainer-prod.js +1 -5
- package/Libraries/ReactNative/AppContainer.js +0 -1
- package/Libraries/ReactNative/AppRegistry.js +0 -6
- package/Libraries/ReactNative/BridgelessUIManager.js +1 -0
- package/Libraries/ReactNative/renderApplication.js +0 -2
- package/Libraries/Renderer/shims/ReactNativeTypes.js +3 -1
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +46 -0
- package/Libraries/StyleSheet/StyleSheetTypes.js +48 -5
- package/Libraries/StyleSheet/processBoxShadow.js +211 -0
- package/Libraries/StyleSheet/processFilter.js +226 -41
- package/Libraries/Text/Text.js +393 -196
- package/Libraries/Text/Text.win32.js +440 -228
- package/Libraries/TurboModule/TurboModuleRegistry.js +13 -50
- package/Libraries/Types/CodegenTypes.js +3 -1
- package/Libraries/Utilities/HMRClient.js +1 -0
- package/Libraries/Utilities/Platform.android.js +1 -1
- package/Libraries/Utilities/Platform.d.ts +1 -1
- package/Libraries/Utilities/Platform.flow.js +2 -2
- package/Libraries/Utilities/Platform.flow.win32.js +3 -3
- package/Libraries/Utilities/Platform.ios.js +1 -1
- package/Libraries/Utilities/Platform.win32.js +1 -1
- package/Libraries/vendor/emitter/EventEmitter.js +1 -0
- package/index.js +1 -0
- package/index.win32.js +1 -0
- package/jest/mockComponent.js +4 -1
- package/jest/setup.js +8 -1
- package/overrides.json +11 -11
- package/package.json +23 -23
- package/src/private/core/components/HScrollViewNativeComponents.js +55 -0
- package/src/private/core/components/VScrollViewNativeComponents.js +47 -0
- package/src/private/core/components/useSyncOnScroll.js +48 -0
- package/src/private/featureflags/ReactNativeFeatureFlags.js +70 -12
- package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +12 -4
- package/src/private/specs/modules/NativeLinkingManager.js +1 -1
- package/src/private/specs/modules/NativePlatformConstantsAndroid.js +1 -1
- package/src/private/specs/modules/NativePlatformConstantsIOS.js +1 -1
- package/src/private/specs/modules/NativePlatformConstantsWin.js +8 -1
- package/src/private/specs/modules/NativeSampleTurboModule.js +14 -1
- package/src/private/webapis/performance/PerformanceEntry.js +1 -1
- package/src/private/webapis/performance/RawPerformanceEntry.js +5 -0
- package/types/experimental.d.ts +12 -1
- package/Libraries/Text/TextOptimized.js +0 -538
package/Libraries/Text/Text.js
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import type {____TextStyle_Internal as TextStyleInternal} from '../StyleSheet/StyleSheetTypes';
|
|
11
12
|
import type {PressEvent} from '../Types/CoreEventTypes';
|
|
12
|
-
import type {
|
|
13
|
+
import type {NativeTextProps} from './TextNativeComponent';
|
|
14
|
+
import type {PressRetentionOffset, TextProps} from './TextProps';
|
|
13
15
|
|
|
14
16
|
import * as PressabilityDebug from '../Pressability/PressabilityDebug';
|
|
15
17
|
import usePressability from '../Pressability/usePressability';
|
|
@@ -21,96 +23,351 @@ import {NativeText, NativeVirtualText} from './TextNativeComponent';
|
|
|
21
23
|
import * as React from 'react';
|
|
22
24
|
import {useContext, useMemo, useState} from 'react';
|
|
23
25
|
|
|
26
|
+
type TextForwardRef = React.ElementRef<
|
|
27
|
+
typeof NativeText | typeof NativeVirtualText,
|
|
28
|
+
>;
|
|
29
|
+
|
|
24
30
|
/**
|
|
25
31
|
* Text is the fundamental component for displaying text.
|
|
26
32
|
*
|
|
27
33
|
* @see https://reactnative.dev/docs/text
|
|
28
34
|
*/
|
|
29
|
-
const Text: React.AbstractComponent<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
35
|
+
const Text: React.AbstractComponent<TextProps, TextForwardRef> =
|
|
36
|
+
React.forwardRef(
|
|
37
|
+
(
|
|
38
|
+
{
|
|
39
|
+
accessible,
|
|
40
|
+
accessibilityLabel,
|
|
41
|
+
accessibilityState,
|
|
42
|
+
allowFontScaling,
|
|
43
|
+
'aria-busy': ariaBusy,
|
|
44
|
+
'aria-checked': ariaChecked,
|
|
45
|
+
'aria-disabled': ariaDisabled,
|
|
46
|
+
'aria-expanded': ariaExpanded,
|
|
47
|
+
'aria-label': ariaLabel,
|
|
48
|
+
'aria-selected': ariaSelected,
|
|
49
|
+
children,
|
|
50
|
+
ellipsizeMode,
|
|
51
|
+
disabled,
|
|
52
|
+
id,
|
|
53
|
+
nativeID,
|
|
54
|
+
numberOfLines,
|
|
55
|
+
onLongPress,
|
|
56
|
+
onPress,
|
|
57
|
+
onPressIn,
|
|
58
|
+
onPressOut,
|
|
59
|
+
onResponderGrant,
|
|
60
|
+
onResponderMove,
|
|
61
|
+
onResponderRelease,
|
|
62
|
+
onResponderTerminate,
|
|
63
|
+
onResponderTerminationRequest,
|
|
64
|
+
onStartShouldSetResponder,
|
|
65
|
+
pressRetentionOffset,
|
|
66
|
+
selectable,
|
|
67
|
+
selectionColor,
|
|
68
|
+
suppressHighlighting,
|
|
69
|
+
style,
|
|
70
|
+
...restProps
|
|
71
|
+
}: TextProps,
|
|
72
|
+
forwardedRef,
|
|
73
|
+
) => {
|
|
74
|
+
const _accessibilityLabel = ariaLabel ?? accessibilityLabel;
|
|
66
75
|
|
|
67
|
-
|
|
76
|
+
let _accessibilityState: ?TextProps['accessibilityState'] =
|
|
77
|
+
accessibilityState;
|
|
78
|
+
if (
|
|
79
|
+
ariaBusy != null ||
|
|
80
|
+
ariaChecked != null ||
|
|
81
|
+
ariaDisabled != null ||
|
|
82
|
+
ariaExpanded != null ||
|
|
83
|
+
ariaSelected != null
|
|
84
|
+
) {
|
|
85
|
+
if (_accessibilityState != null) {
|
|
86
|
+
_accessibilityState = {
|
|
87
|
+
busy: ariaBusy ?? _accessibilityState.busy,
|
|
88
|
+
checked: ariaChecked ?? _accessibilityState.checked,
|
|
89
|
+
disabled: ariaDisabled ?? _accessibilityState.disabled,
|
|
90
|
+
expanded: ariaExpanded ?? _accessibilityState.expanded,
|
|
91
|
+
selected: ariaSelected ?? _accessibilityState.selected,
|
|
92
|
+
};
|
|
93
|
+
} else {
|
|
94
|
+
_accessibilityState = {
|
|
95
|
+
busy: ariaBusy,
|
|
96
|
+
checked: ariaChecked,
|
|
97
|
+
disabled: ariaDisabled,
|
|
98
|
+
expanded: ariaExpanded,
|
|
99
|
+
selected: ariaSelected,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
68
103
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
let _accessibilityState: ?TextProps['accessibilityState'] =
|
|
72
|
-
accessibilityState;
|
|
73
|
-
if (
|
|
74
|
-
ariaBusy != null ||
|
|
75
|
-
ariaChecked != null ||
|
|
76
|
-
ariaDisabled != null ||
|
|
77
|
-
ariaExpanded != null ||
|
|
78
|
-
ariaSelected != null
|
|
79
|
-
) {
|
|
80
|
-
if (_accessibilityState != null) {
|
|
81
|
-
_accessibilityState = {
|
|
82
|
-
busy: ariaBusy ?? _accessibilityState.busy,
|
|
83
|
-
checked: ariaChecked ?? _accessibilityState.checked,
|
|
84
|
-
disabled: ariaDisabled ?? _accessibilityState.disabled,
|
|
85
|
-
expanded: ariaExpanded ?? _accessibilityState.expanded,
|
|
86
|
-
selected: ariaSelected ?? _accessibilityState.selected,
|
|
87
|
-
};
|
|
88
|
-
} else {
|
|
89
|
-
_accessibilityState = {
|
|
90
|
-
busy: ariaBusy,
|
|
91
|
-
checked: ariaChecked,
|
|
92
|
-
disabled: ariaDisabled,
|
|
93
|
-
expanded: ariaExpanded,
|
|
94
|
-
selected: ariaSelected,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
104
|
+
const _accessibilityStateDisabled = _accessibilityState?.disabled;
|
|
105
|
+
const _disabled = disabled ?? _accessibilityStateDisabled;
|
|
98
106
|
|
|
99
|
-
|
|
100
|
-
|
|
107
|
+
const isPressable =
|
|
108
|
+
(onPress != null ||
|
|
109
|
+
onLongPress != null ||
|
|
110
|
+
onStartShouldSetResponder != null) &&
|
|
111
|
+
_disabled !== true;
|
|
101
112
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
onStartShouldSetResponder != null) &&
|
|
106
|
-
_disabled !== true;
|
|
113
|
+
// TODO: Move this processing to the view configuration.
|
|
114
|
+
const _selectionColor =
|
|
115
|
+
selectionColor == null ? null : processColor(selectionColor);
|
|
107
116
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
let _style = style;
|
|
118
|
+
if (__DEV__) {
|
|
119
|
+
if (PressabilityDebug.isEnabled() && onPress != null) {
|
|
120
|
+
_style = [style, {color: 'magenta'}];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let _numberOfLines = numberOfLines;
|
|
125
|
+
if (_numberOfLines != null && !(_numberOfLines >= 0)) {
|
|
126
|
+
if (__DEV__) {
|
|
127
|
+
console.error(
|
|
128
|
+
`'numberOfLines' in <Text> must be a non-negative number, received: ${_numberOfLines}. The value will be set to 0.`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
_numberOfLines = 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let _selectable = selectable;
|
|
135
|
+
|
|
136
|
+
let processedStyle: ?TextStyleInternal = flattenStyle(_style);
|
|
137
|
+
if (processedStyle != null) {
|
|
138
|
+
let overrides: ?{...TextStyleInternal} = null;
|
|
139
|
+
if (typeof processedStyle.fontWeight === 'number') {
|
|
140
|
+
overrides = overrides || ({}: {...TextStyleInternal});
|
|
141
|
+
overrides.fontWeight =
|
|
142
|
+
// $FlowFixMe[incompatible-cast]
|
|
143
|
+
(processedStyle.fontWeight.toString(): TextStyleInternal['fontWeight']);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (processedStyle.userSelect != null) {
|
|
147
|
+
_selectable = userSelectToSelectableMap[processedStyle.userSelect];
|
|
148
|
+
overrides = overrides || ({}: {...TextStyleInternal});
|
|
149
|
+
overrides.userSelect = undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (processedStyle.verticalAlign != null) {
|
|
153
|
+
overrides = overrides || ({}: {...TextStyleInternal});
|
|
154
|
+
overrides.textAlignVertical =
|
|
155
|
+
verticalAlignToTextAlignVerticalMap[processedStyle.verticalAlign];
|
|
156
|
+
overrides.verticalAlign = undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (overrides != null) {
|
|
160
|
+
// $FlowFixMe[incompatible-type]
|
|
161
|
+
processedStyle = [processedStyle, overrides];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const _nativeID = id ?? nativeID;
|
|
166
|
+
|
|
167
|
+
const hasTextAncestor = useContext(TextAncestor);
|
|
168
|
+
if (hasTextAncestor) {
|
|
169
|
+
if (isPressable) {
|
|
170
|
+
return (
|
|
171
|
+
<NativePressableVirtualText
|
|
172
|
+
ref={forwardedRef}
|
|
173
|
+
textProps={{
|
|
174
|
+
...restProps,
|
|
175
|
+
accessibilityLabel: _accessibilityLabel,
|
|
176
|
+
accessibilityState: _accessibilityState,
|
|
177
|
+
nativeID: _nativeID,
|
|
178
|
+
numberOfLines: _numberOfLines,
|
|
179
|
+
selectable: _selectable,
|
|
180
|
+
selectionColor: _selectionColor,
|
|
181
|
+
style: processedStyle,
|
|
182
|
+
disabled: disabled,
|
|
183
|
+
children,
|
|
184
|
+
}}
|
|
185
|
+
textPressabilityProps={{
|
|
186
|
+
onLongPress,
|
|
187
|
+
onPress,
|
|
188
|
+
onPressIn,
|
|
189
|
+
onPressOut,
|
|
190
|
+
onResponderGrant,
|
|
191
|
+
onResponderMove,
|
|
192
|
+
onResponderRelease,
|
|
193
|
+
onResponderTerminate,
|
|
194
|
+
onResponderTerminationRequest,
|
|
195
|
+
onStartShouldSetResponder,
|
|
196
|
+
pressRetentionOffset,
|
|
197
|
+
suppressHighlighting,
|
|
198
|
+
}}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<NativeVirtualText
|
|
205
|
+
{...restProps}
|
|
206
|
+
accessibilityLabel={_accessibilityLabel}
|
|
207
|
+
accessibilityState={_accessibilityState}
|
|
208
|
+
isHighlighted={false}
|
|
209
|
+
isPressable={false}
|
|
210
|
+
nativeID={_nativeID}
|
|
211
|
+
numberOfLines={_numberOfLines}
|
|
212
|
+
ref={forwardedRef}
|
|
213
|
+
selectable={_selectable}
|
|
214
|
+
selectionColor={_selectionColor}
|
|
215
|
+
style={processedStyle}
|
|
216
|
+
disabled={disabled}>
|
|
217
|
+
{children}
|
|
218
|
+
</NativeVirtualText>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// If the disabled prop and accessibilityState.disabled are out of sync but not both in
|
|
223
|
+
// falsy states we need to update the accessibilityState object to use the disabled prop.
|
|
224
|
+
if (
|
|
225
|
+
_disabled !== _accessibilityStateDisabled &&
|
|
226
|
+
((_disabled != null && _disabled !== false) ||
|
|
227
|
+
(_accessibilityStateDisabled != null &&
|
|
228
|
+
_accessibilityStateDisabled !== false))
|
|
229
|
+
) {
|
|
230
|
+
_accessibilityState = {..._accessibilityState, disabled: _disabled};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const _accessible = Platform.select({
|
|
234
|
+
ios: accessible !== false,
|
|
235
|
+
android:
|
|
236
|
+
accessible == null
|
|
237
|
+
? onPress != null || onLongPress != null
|
|
238
|
+
: accessible,
|
|
239
|
+
default: accessible,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
let nativeText = null;
|
|
243
|
+
if (isPressable) {
|
|
244
|
+
nativeText = (
|
|
245
|
+
<NativePressableText
|
|
246
|
+
ref={forwardedRef}
|
|
247
|
+
textProps={{
|
|
248
|
+
...restProps,
|
|
249
|
+
accessibilityLabel: _accessibilityLabel,
|
|
250
|
+
accessibilityState: _accessibilityState,
|
|
251
|
+
accessible: _accessible,
|
|
252
|
+
allowFontScaling: allowFontScaling !== false,
|
|
253
|
+
disabled: _disabled,
|
|
254
|
+
ellipsizeMode: ellipsizeMode ?? 'tail',
|
|
255
|
+
nativeID: _nativeID,
|
|
256
|
+
numberOfLines: _numberOfLines,
|
|
257
|
+
selectable: _selectable,
|
|
258
|
+
selectionColor: _selectionColor,
|
|
259
|
+
style: processedStyle,
|
|
260
|
+
children,
|
|
261
|
+
}}
|
|
262
|
+
textPressabilityProps={{
|
|
263
|
+
onLongPress,
|
|
264
|
+
onPress,
|
|
265
|
+
onPressIn,
|
|
266
|
+
onPressOut,
|
|
267
|
+
onResponderGrant,
|
|
268
|
+
onResponderMove,
|
|
269
|
+
onResponderRelease,
|
|
270
|
+
onResponderTerminate,
|
|
271
|
+
onResponderTerminationRequest,
|
|
272
|
+
onStartShouldSetResponder,
|
|
273
|
+
pressRetentionOffset,
|
|
274
|
+
suppressHighlighting,
|
|
275
|
+
}}
|
|
276
|
+
/>
|
|
277
|
+
);
|
|
278
|
+
} else {
|
|
279
|
+
nativeText = (
|
|
280
|
+
<NativeText
|
|
281
|
+
{...restProps}
|
|
282
|
+
accessibilityLabel={_accessibilityLabel}
|
|
283
|
+
accessibilityState={_accessibilityState}
|
|
284
|
+
accessible={_accessible}
|
|
285
|
+
allowFontScaling={allowFontScaling !== false}
|
|
286
|
+
disabled={_disabled}
|
|
287
|
+
ellipsizeMode={ellipsizeMode ?? 'tail'}
|
|
288
|
+
isHighlighted={false}
|
|
289
|
+
nativeID={_nativeID}
|
|
290
|
+
numberOfLines={_numberOfLines}
|
|
291
|
+
ref={forwardedRef}
|
|
292
|
+
selectable={_selectable}
|
|
293
|
+
selectionColor={_selectionColor}
|
|
294
|
+
style={processedStyle}>
|
|
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 `TextAncestor` 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
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (!hasNonTextChild) {
|
|
319
|
+
return nativeText;
|
|
320
|
+
}
|
|
321
|
+
} else if (typeof children !== 'object') {
|
|
322
|
+
return nativeText;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<TextAncestor.Provider value={true}>{nativeText}</TextAncestor.Provider>
|
|
327
|
+
);
|
|
328
|
+
},
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
Text.displayName = 'Text';
|
|
113
332
|
|
|
333
|
+
type TextPressabilityProps = $ReadOnly<{
|
|
334
|
+
onLongPress?: ?(event: PressEvent) => mixed,
|
|
335
|
+
onPress?: ?(event: PressEvent) => mixed,
|
|
336
|
+
onPressIn?: ?(event: PressEvent) => mixed,
|
|
337
|
+
onPressOut?: ?(event: PressEvent) => mixed,
|
|
338
|
+
onResponderGrant?: ?(event: PressEvent) => void,
|
|
339
|
+
onResponderMove?: ?(event: PressEvent) => void,
|
|
340
|
+
onResponderRelease?: ?(event: PressEvent) => void,
|
|
341
|
+
onResponderTerminate?: ?(event: PressEvent) => void,
|
|
342
|
+
onResponderTerminationRequest?: ?() => boolean,
|
|
343
|
+
onStartShouldSetResponder?: ?() => boolean,
|
|
344
|
+
pressRetentionOffset?: ?PressRetentionOffset,
|
|
345
|
+
suppressHighlighting?: ?boolean,
|
|
346
|
+
}>;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Hook that handles setting up Pressability of Text components.
|
|
350
|
+
*
|
|
351
|
+
* NOTE: This hook is relatively expensive so it should only be used absolutely necessary.
|
|
352
|
+
*/
|
|
353
|
+
function useTextPressability({
|
|
354
|
+
onLongPress,
|
|
355
|
+
onPress,
|
|
356
|
+
onPressIn,
|
|
357
|
+
onPressOut,
|
|
358
|
+
onResponderGrant,
|
|
359
|
+
onResponderMove,
|
|
360
|
+
onResponderRelease,
|
|
361
|
+
onResponderTerminate,
|
|
362
|
+
onResponderTerminationRequest,
|
|
363
|
+
onStartShouldSetResponder,
|
|
364
|
+
pressRetentionOffset,
|
|
365
|
+
suppressHighlighting,
|
|
366
|
+
}: TextPressabilityProps) {
|
|
367
|
+
const [isHighlighted, setHighlighted] = useState(false);
|
|
368
|
+
|
|
369
|
+
// Setup pressability config and wrap callbacks needs to track the highlight state.
|
|
370
|
+
const config = useMemo(() => {
|
|
114
371
|
let _onPressIn = onPressIn;
|
|
115
372
|
let _onPressOut = onPressOut;
|
|
116
373
|
|
|
@@ -130,7 +387,7 @@ const Text: React.AbstractComponent<
|
|
|
130
387
|
}
|
|
131
388
|
|
|
132
389
|
return {
|
|
133
|
-
disabled:
|
|
390
|
+
disabled: false,
|
|
134
391
|
pressRectOffset: pressRetentionOffset,
|
|
135
392
|
onLongPress,
|
|
136
393
|
onPress,
|
|
@@ -138,8 +395,6 @@ const Text: React.AbstractComponent<
|
|
|
138
395
|
onPressOut: _onPressOut,
|
|
139
396
|
};
|
|
140
397
|
}, [
|
|
141
|
-
initialized,
|
|
142
|
-
isPressable,
|
|
143
398
|
pressRetentionOffset,
|
|
144
399
|
onLongPress,
|
|
145
400
|
onPress,
|
|
@@ -148,7 +403,10 @@ const Text: React.AbstractComponent<
|
|
|
148
403
|
suppressHighlighting,
|
|
149
404
|
]);
|
|
150
405
|
|
|
406
|
+
// Init the pressability class
|
|
151
407
|
const eventHandlers = usePressability(config);
|
|
408
|
+
|
|
409
|
+
// Create NativeText event handlers which proxy events to pressability
|
|
152
410
|
const eventHandlersForText = useMemo(
|
|
153
411
|
() =>
|
|
154
412
|
eventHandlers == null
|
|
@@ -199,128 +457,67 @@ const Text: React.AbstractComponent<
|
|
|
199
457
|
],
|
|
200
458
|
);
|
|
201
459
|
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (PressabilityDebug.isEnabled() && onPress != null) {
|
|
209
|
-
_style = [style, {color: 'magenta'}];
|
|
210
|
-
}
|
|
211
|
-
}
|
|
460
|
+
// Return the highlight state and NativeText event handlers
|
|
461
|
+
return useMemo(
|
|
462
|
+
() => [isHighlighted, eventHandlersForText],
|
|
463
|
+
[isHighlighted, eventHandlersForText],
|
|
464
|
+
);
|
|
465
|
+
}
|
|
212
466
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
`'numberOfLines' in <Text> must be a non-negative number, received: ${_numberOfLines}. The value will be set to 0.`,
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
_numberOfLines = 0;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
let _selectable = selectable;
|
|
224
|
-
const processedStyle = flattenStyle(_style);
|
|
225
|
-
if (processedStyle != null) {
|
|
226
|
-
if (typeof processedStyle.fontWeight === 'number') {
|
|
227
|
-
// $FlowFixMe[cannot-write]
|
|
228
|
-
processedStyle.fontWeight = processedStyle.fontWeight.toString();
|
|
229
|
-
}
|
|
467
|
+
type NativePressableTextProps = $ReadOnly<{
|
|
468
|
+
textProps: NativeTextProps,
|
|
469
|
+
textPressabilityProps: TextPressabilityProps,
|
|
470
|
+
}>;
|
|
230
471
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const _nativeID = id ?? nativeID;
|
|
247
|
-
|
|
248
|
-
const hasTextAncestor = useContext(TextAncestor);
|
|
249
|
-
if (hasTextAncestor) {
|
|
250
|
-
return (
|
|
251
|
-
<NativeVirtualText
|
|
252
|
-
{...restProps}
|
|
253
|
-
{...eventHandlersForText}
|
|
254
|
-
accessibilityLabel={_accessibilityLabel}
|
|
255
|
-
accessibilityState={_accessibilityState}
|
|
256
|
-
isHighlighted={isHighlighted}
|
|
257
|
-
isPressable={isPressable}
|
|
258
|
-
nativeID={_nativeID}
|
|
259
|
-
numberOfLines={_numberOfLines}
|
|
260
|
-
ref={forwardedRef}
|
|
261
|
-
selectable={_selectable}
|
|
262
|
-
selectionColor={_selectionColor}
|
|
263
|
-
style={processedStyle}
|
|
264
|
-
disabled={disabled}
|
|
265
|
-
/>
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// If the disabled prop and accessibilityState.disabled are out of sync but not both in
|
|
270
|
-
// falsy states we need to update the accessibilityState object to use the disabled prop.
|
|
271
|
-
if (
|
|
272
|
-
_disabled !== _accessibilityStateDisabled &&
|
|
273
|
-
((_disabled != null && _disabled !== false) ||
|
|
274
|
-
(_accessibilityStateDisabled != null &&
|
|
275
|
-
_accessibilityStateDisabled !== false))
|
|
276
|
-
) {
|
|
277
|
-
_accessibilityState = {..._accessibilityState, disabled: _disabled};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const _accessible = Platform.select({
|
|
281
|
-
ios: accessible !== false,
|
|
282
|
-
android:
|
|
283
|
-
accessible == null ? onPress != null || onLongPress != null : accessible,
|
|
284
|
-
default: accessible,
|
|
285
|
-
});
|
|
472
|
+
/**
|
|
473
|
+
* Wrap the NativeVirtualText component and initialize pressability.
|
|
474
|
+
*
|
|
475
|
+
* This logic is split out from the main Text component to enable the more
|
|
476
|
+
* expensive pressability logic to be only initialized when needed.
|
|
477
|
+
*/
|
|
478
|
+
const NativePressableVirtualText: React.AbstractComponent<
|
|
479
|
+
NativePressableTextProps,
|
|
480
|
+
TextForwardRef,
|
|
481
|
+
> = React.forwardRef(({textProps, textPressabilityProps}, forwardedRef) => {
|
|
482
|
+
const [isHighlighted, eventHandlersForText] = useTextPressability(
|
|
483
|
+
textPressabilityProps,
|
|
484
|
+
);
|
|
286
485
|
|
|
287
486
|
return (
|
|
288
|
-
<
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
allowFontScaling={allowFontScaling !== false}
|
|
296
|
-
disabled={_disabled}
|
|
297
|
-
ellipsizeMode={ellipsizeMode ?? 'tail'}
|
|
298
|
-
isHighlighted={isHighlighted}
|
|
299
|
-
nativeID={_nativeID}
|
|
300
|
-
numberOfLines={_numberOfLines}
|
|
301
|
-
ref={forwardedRef}
|
|
302
|
-
selectable={_selectable}
|
|
303
|
-
selectionColor={_selectionColor}
|
|
304
|
-
style={processedStyle}
|
|
305
|
-
/>
|
|
306
|
-
</TextAncestor.Provider>
|
|
487
|
+
<NativeVirtualText
|
|
488
|
+
{...textProps}
|
|
489
|
+
{...eventHandlersForText}
|
|
490
|
+
isHighlighted={isHighlighted}
|
|
491
|
+
isPressable={true}
|
|
492
|
+
ref={forwardedRef}
|
|
493
|
+
/>
|
|
307
494
|
);
|
|
308
495
|
});
|
|
309
496
|
|
|
310
|
-
Text.displayName = 'Text';
|
|
311
|
-
|
|
312
497
|
/**
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
498
|
+
* Wrap the NativeText component and initialize pressability.
|
|
499
|
+
*
|
|
500
|
+
* This logic is split out from the main Text component to enable the more
|
|
501
|
+
* expensive pressability logic to be only initialized when needed.
|
|
316
502
|
*/
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
503
|
+
const NativePressableText: React.AbstractComponent<
|
|
504
|
+
NativePressableTextProps,
|
|
505
|
+
TextForwardRef,
|
|
506
|
+
> = React.forwardRef(({textProps, textPressabilityProps}, forwardedRef) => {
|
|
507
|
+
const [isHighlighted, eventHandlersForText] = useTextPressability(
|
|
508
|
+
textPressabilityProps,
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
return (
|
|
512
|
+
<NativeText
|
|
513
|
+
{...textProps}
|
|
514
|
+
{...eventHandlersForText}
|
|
515
|
+
isHighlighted={isHighlighted}
|
|
516
|
+
isPressable={true}
|
|
517
|
+
ref={forwardedRef}
|
|
518
|
+
/>
|
|
519
|
+
);
|
|
520
|
+
});
|
|
324
521
|
|
|
325
522
|
const userSelectToSelectableMap = {
|
|
326
523
|
auto: true,
|