@office-iss/react-native-win32 0.0.0-canary.258 → 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 +2 -4
- package/CHANGELOG.json +16 -1
- package/CHANGELOG.md +16 -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/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/ReactFiberErrorDialog.js +3 -0
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- 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/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/BridgelessUIManager.js +1 -0
- package/Libraries/Renderer/shims/ReactNativeTypes.js +3 -1
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +46 -19
- package/Libraries/StyleSheet/StyleSheetTypes.js +48 -23
- package/Libraries/StyleSheet/processBoxShadow.js +211 -0
- package/Libraries/StyleSheet/processFilter.js +24 -14
- package/Libraries/Text/Text.js +394 -212
- package/Libraries/Text/Text.win32.js +442 -245
- 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/jest/setup.js +8 -1
- package/overrides.json +9 -9
- package/package.json +12 -12
- package/src/private/featureflags/ReactNativeFeatureFlags.js +65 -18
- package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +11 -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/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,10 +8,11 @@
|
|
|
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
|
-
import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';
|
|
15
16
|
import * as PressabilityDebug from '../Pressability/PressabilityDebug';
|
|
16
17
|
import usePressability from '../Pressability/usePressability';
|
|
17
18
|
import flattenStyle from '../StyleSheet/flattenStyle';
|
|
@@ -19,100 +20,354 @@ import processColor from '../StyleSheet/processColor';
|
|
|
19
20
|
import Platform from '../Utilities/Platform';
|
|
20
21
|
import TextAncestor from './TextAncestor';
|
|
21
22
|
import {NativeText, NativeVirtualText} from './TextNativeComponent';
|
|
22
|
-
import TextOptimized from './TextOptimized';
|
|
23
23
|
import * as React from 'react';
|
|
24
24
|
import {useContext, useMemo, useState} from 'react';
|
|
25
25
|
|
|
26
|
+
type TextForwardRef = React.ElementRef<
|
|
27
|
+
typeof NativeText | typeof NativeVirtualText,
|
|
28
|
+
>;
|
|
29
|
+
|
|
26
30
|
/**
|
|
27
31
|
* Text is the fundamental component for displaying text.
|
|
28
32
|
*
|
|
29
33
|
* @see https://reactnative.dev/docs/text
|
|
30
34
|
*/
|
|
31
|
-
const
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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;
|
|
75
|
+
|
|
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
|
+
}
|
|
103
|
+
|
|
104
|
+
const _accessibilityStateDisabled = _accessibilityState?.disabled;
|
|
105
|
+
const _disabled = disabled ?? _accessibilityStateDisabled;
|
|
106
|
+
|
|
107
|
+
const isPressable =
|
|
108
|
+
(onPress != null ||
|
|
109
|
+
onLongPress != null ||
|
|
110
|
+
onStartShouldSetResponder != null) &&
|
|
111
|
+
_disabled !== true;
|
|
112
|
+
|
|
113
|
+
// TODO: Move this processing to the view configuration.
|
|
114
|
+
const _selectionColor =
|
|
115
|
+
selectionColor == null ? null : processColor(selectionColor);
|
|
116
|
+
|
|
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
|
+
);
|
|
70
330
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let _accessibilityState: ?TextProps['accessibilityState'] =
|
|
74
|
-
accessibilityState;
|
|
75
|
-
if (
|
|
76
|
-
ariaBusy != null ||
|
|
77
|
-
ariaChecked != null ||
|
|
78
|
-
ariaDisabled != null ||
|
|
79
|
-
ariaExpanded != null ||
|
|
80
|
-
ariaSelected != null
|
|
81
|
-
) {
|
|
82
|
-
if (_accessibilityState != null) {
|
|
83
|
-
_accessibilityState = {
|
|
84
|
-
busy: ariaBusy ?? _accessibilityState.busy,
|
|
85
|
-
checked: ariaChecked ?? _accessibilityState.checked,
|
|
86
|
-
disabled: ariaDisabled ?? _accessibilityState.disabled,
|
|
87
|
-
expanded: ariaExpanded ?? _accessibilityState.expanded,
|
|
88
|
-
selected: ariaSelected ?? _accessibilityState.selected,
|
|
89
|
-
};
|
|
90
|
-
} else {
|
|
91
|
-
_accessibilityState = {
|
|
92
|
-
busy: ariaBusy,
|
|
93
|
-
checked: ariaChecked,
|
|
94
|
-
disabled: ariaDisabled,
|
|
95
|
-
expanded: ariaExpanded,
|
|
96
|
-
selected: ariaSelected,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
331
|
+
Text.displayName = 'Text';
|
|
100
332
|
|
|
101
|
-
|
|
102
|
-
|
|
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
|
+
}>;
|
|
103
347
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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);
|
|
109
368
|
|
|
110
|
-
|
|
369
|
+
// Setup pressability config and wrap callbacks needs to track the highlight state.
|
|
111
370
|
const config = useMemo(() => {
|
|
112
|
-
if (!initialized) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
371
|
let _onPressIn = onPressIn;
|
|
117
372
|
let _onPressOut = onPressOut;
|
|
118
373
|
|
|
@@ -132,7 +387,7 @@ const TextLegacy: React.AbstractComponent<
|
|
|
132
387
|
}
|
|
133
388
|
|
|
134
389
|
return {
|
|
135
|
-
disabled:
|
|
390
|
+
disabled: false,
|
|
136
391
|
pressRectOffset: pressRetentionOffset,
|
|
137
392
|
onLongPress,
|
|
138
393
|
onPress,
|
|
@@ -140,8 +395,6 @@ const TextLegacy: React.AbstractComponent<
|
|
|
140
395
|
onPressOut: _onPressOut,
|
|
141
396
|
};
|
|
142
397
|
}, [
|
|
143
|
-
initialized,
|
|
144
|
-
isPressable,
|
|
145
398
|
pressRetentionOffset,
|
|
146
399
|
onLongPress,
|
|
147
400
|
onPress,
|
|
@@ -150,7 +403,10 @@ const TextLegacy: React.AbstractComponent<
|
|
|
150
403
|
suppressHighlighting,
|
|
151
404
|
]);
|
|
152
405
|
|
|
406
|
+
// Init the pressability class
|
|
153
407
|
const eventHandlers = usePressability(config);
|
|
408
|
+
|
|
409
|
+
// Create NativeText event handlers which proxy events to pressability
|
|
154
410
|
const eventHandlersForText = useMemo(
|
|
155
411
|
() =>
|
|
156
412
|
eventHandlers == null
|
|
@@ -201,128 +457,67 @@ const TextLegacy: React.AbstractComponent<
|
|
|
201
457
|
],
|
|
202
458
|
);
|
|
203
459
|
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (PressabilityDebug.isEnabled() && onPress != null) {
|
|
211
|
-
_style = [style, {color: 'magenta'}];
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
let _numberOfLines = numberOfLines;
|
|
216
|
-
if (_numberOfLines != null && !(_numberOfLines >= 0)) {
|
|
217
|
-
if (__DEV__) {
|
|
218
|
-
console.error(
|
|
219
|
-
`'numberOfLines' in <Text> must be a non-negative number, received: ${_numberOfLines}. The value will be set to 0.`,
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
_numberOfLines = 0;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
let _selectable = selectable;
|
|
226
|
-
const processedStyle = flattenStyle(_style);
|
|
227
|
-
if (processedStyle != null) {
|
|
228
|
-
if (typeof processedStyle.fontWeight === 'number') {
|
|
229
|
-
// $FlowFixMe[cannot-write]
|
|
230
|
-
processedStyle.fontWeight = processedStyle.fontWeight.toString();
|
|
231
|
-
}
|
|
460
|
+
// Return the highlight state and NativeText event handlers
|
|
461
|
+
return useMemo(
|
|
462
|
+
() => [isHighlighted, eventHandlersForText],
|
|
463
|
+
[isHighlighted, eventHandlersForText],
|
|
464
|
+
);
|
|
465
|
+
}
|
|
232
466
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
467
|
+
type NativePressableTextProps = $ReadOnly<{
|
|
468
|
+
textProps: NativeTextProps,
|
|
469
|
+
textPressabilityProps: TextPressabilityProps,
|
|
470
|
+
}>;
|
|
238
471
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
return (
|
|
253
|
-
<NativeVirtualText
|
|
254
|
-
{...restProps}
|
|
255
|
-
{...eventHandlersForText}
|
|
256
|
-
accessibilityLabel={_accessibilityLabel}
|
|
257
|
-
accessibilityState={_accessibilityState}
|
|
258
|
-
isHighlighted={isHighlighted}
|
|
259
|
-
isPressable={isPressable}
|
|
260
|
-
nativeID={_nativeID}
|
|
261
|
-
numberOfLines={_numberOfLines}
|
|
262
|
-
ref={forwardedRef}
|
|
263
|
-
selectable={_selectable}
|
|
264
|
-
selectionColor={_selectionColor}
|
|
265
|
-
style={processedStyle}
|
|
266
|
-
disabled={disabled}
|
|
267
|
-
/>
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// If the disabled prop and accessibilityState.disabled are out of sync but not both in
|
|
272
|
-
// falsy states we need to update the accessibilityState object to use the disabled prop.
|
|
273
|
-
if (
|
|
274
|
-
_disabled !== _accessibilityStateDisabled &&
|
|
275
|
-
((_disabled != null && _disabled !== false) ||
|
|
276
|
-
(_accessibilityStateDisabled != null &&
|
|
277
|
-
_accessibilityStateDisabled !== false))
|
|
278
|
-
) {
|
|
279
|
-
_accessibilityState = {..._accessibilityState, disabled: _disabled};
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const _accessible = Platform.select({
|
|
283
|
-
ios: accessible !== false,
|
|
284
|
-
android:
|
|
285
|
-
accessible == null ? onPress != null || onLongPress != null : accessible,
|
|
286
|
-
default: accessible,
|
|
287
|
-
});
|
|
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
|
+
);
|
|
288
485
|
|
|
289
486
|
return (
|
|
290
|
-
<
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
allowFontScaling={allowFontScaling !== false}
|
|
298
|
-
disabled={_disabled}
|
|
299
|
-
ellipsizeMode={ellipsizeMode ?? 'tail'}
|
|
300
|
-
isHighlighted={isHighlighted}
|
|
301
|
-
nativeID={_nativeID}
|
|
302
|
-
numberOfLines={_numberOfLines}
|
|
303
|
-
ref={forwardedRef}
|
|
304
|
-
selectable={_selectable}
|
|
305
|
-
selectionColor={_selectionColor}
|
|
306
|
-
style={processedStyle}
|
|
307
|
-
/>
|
|
308
|
-
</TextAncestor.Provider>
|
|
487
|
+
<NativeVirtualText
|
|
488
|
+
{...textProps}
|
|
489
|
+
{...eventHandlersForText}
|
|
490
|
+
isHighlighted={isHighlighted}
|
|
491
|
+
isPressable={true}
|
|
492
|
+
ref={forwardedRef}
|
|
493
|
+
/>
|
|
309
494
|
);
|
|
310
495
|
});
|
|
311
496
|
|
|
312
|
-
TextLegacy.displayName = 'TextLegacy';
|
|
313
|
-
|
|
314
497
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
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.
|
|
318
502
|
*/
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
+
});
|
|
326
521
|
|
|
327
522
|
const userSelectToSelectableMap = {
|
|
328
523
|
auto: true,
|
|
@@ -339,17 +534,4 @@ const verticalAlignToTextAlignVerticalMap = {
|
|
|
339
534
|
middle: 'center',
|
|
340
535
|
};
|
|
341
536
|
|
|
342
|
-
const Text: React.AbstractComponent<
|
|
343
|
-
TextProps,
|
|
344
|
-
React.ElementRef<typeof NativeText | typeof NativeVirtualText>,
|
|
345
|
-
> = React.forwardRef((props: TextProps, forwardedRef) => {
|
|
346
|
-
if (ReactNativeFeatureFlags.shouldUseOptimizedText()) {
|
|
347
|
-
return <TextOptimized {...props} ref={forwardedRef} />;
|
|
348
|
-
} else {
|
|
349
|
-
return <TextLegacy {...props} ref={forwardedRef} />;
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
Text.displayName = 'Text';
|
|
354
|
-
|
|
355
537
|
module.exports = Text;
|