@react-native-oh/react-native-harmony 0.72.23 → 0.72.27

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 (44) hide show
  1. package/Libraries/Alert/Alert.harmony.js +71 -71
  2. package/Libraries/Alert/AlertManager.ts +35 -35
  3. package/Libraries/Animated/NativeAnimatedHelper.harmony.js +601 -601
  4. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.harmony.js +445 -426
  5. package/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.harmony.js +30 -0
  6. package/Libraries/Components/AccessibilityInfo/legacySendAccessibilityEvent.harmony.js +26 -0
  7. package/Libraries/Components/Button/Button.harmony.js +450 -450
  8. package/Libraries/Components/Image/Image.flow.harmony.js +53 -0
  9. package/Libraries/Components/Image/Image.harmony.js +299 -0
  10. package/Libraries/Components/Image/NativeImageLoaderHarmony.js +38 -0
  11. package/Libraries/Components/RefreshControl/RefreshControl.harmony.js +210 -208
  12. package/Libraries/Components/SafeAreaView/SafeAreaView.harmony.tsx +76 -75
  13. package/Libraries/Components/ScrollView/ScrollView.harmony.js +1951 -1930
  14. package/Libraries/Components/ScrollView/processDecelerationRate.harmony.js +24 -24
  15. package/Libraries/Components/StatusBar/NativeStatusBarManagerHarmony.js +71 -68
  16. package/Libraries/Components/StatusBar/StatusBar.harmony.js +447 -447
  17. package/Libraries/Components/TextInput/TextInput.harmony.js +1707 -1697
  18. package/Libraries/Components/TextInput/TextInputState.harmony.js +220 -220
  19. package/Libraries/Components/Touchable/TouchableHighlight.harmony.js +396 -396
  20. package/Libraries/Components/Touchable/TouchableNativeFeedback.harmony.js +364 -364
  21. package/Libraries/Components/Touchable/TouchableWithoutFeedback.harmony.js +227 -227
  22. package/Libraries/Components/View/View.harmony.js +149 -149
  23. package/Libraries/Core/setUpReactDevTools.harmony.js +93 -93
  24. package/Libraries/Image/AssetSourceResolver.harmony.ts +78 -78
  25. package/Libraries/NativeComponent/BaseViewConfig.harmony.js +337 -337
  26. package/Libraries/ReactNative/UIManager.harmony.js +210 -210
  27. package/Libraries/Settings/Settings.harmony.js +15 -15
  28. package/Libraries/Share/Share.harmony.js +174 -0
  29. package/Libraries/StyleSheet/NativePlatformColor.ts +8 -8
  30. package/Libraries/StyleSheet/PlatformColorValueTypes.harmony.ts +14 -14
  31. package/Libraries/Utilities/BackHandler.harmony.js +109 -109
  32. package/Libraries/Utilities/{NativePlatformConstantsHarmony.ts → NativePlatformConstants.harmony.ts} +8 -8
  33. package/Libraries/Utilities/Platform.d.ts +117 -117
  34. package/Libraries/Utilities/Platform.harmony.ts +33 -33
  35. package/Libraries/Utilities/createPerformanceLogger.harmony.js +328 -328
  36. package/Libraries/Vibration/Vibration.harmony.js +88 -88
  37. package/index.js +212 -202
  38. package/jest.config.js +5 -5
  39. package/metro.config.js +348 -349
  40. package/package.json +58 -55
  41. package/react-native.config.js +10 -10
  42. package/{rnoh-4.1.0.404-vmall.har → react_native_openharmony.har} +0 -0
  43. package/tsconfig.json +13 -13
  44. package/types/index.d.ts +101 -101
@@ -1,364 +1,364 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict-local
8
- * @format
9
- */
10
-
11
- // RNOH patch: disable view flattening
12
-
13
- import type { PressEvent } from "react-native/Libraries/Types/CoreEventTypes";
14
- import typeof TouchableWithoutFeedback from "./TouchableWithoutFeedback";
15
-
16
- import View from "react-native/Libraries/Components/View/View";
17
- import Pressability, {
18
- type PressabilityConfig,
19
- } from "react-native/Libraries/Pressability/Pressability";
20
- import { PressabilityDebugView } from "react-native/Libraries/Pressability/PressabilityDebug";
21
- import { findHostInstance_DEPRECATED } from "react-native/Libraries/ReactNative/RendererProxy";
22
- import processColor from "react-native/Libraries/StyleSheet/processColor";
23
- import Platform from "react-native/Libraries/Utilities/Platform";
24
- import { Commands } from "react-native/Libraries/Components/View/ViewNativeComponent";
25
- import invariant from "invariant";
26
- import * as React from "react";
27
-
28
- type Props = $ReadOnly<{|
29
- ...React.ElementConfig<TouchableWithoutFeedback>,
30
-
31
- /**
32
- * Determines the type of background drawable that's going to be used to
33
- * display feedback. It takes an object with `type` property and extra data
34
- * depending on the `type`. It's recommended to use one of the static
35
- * methods to generate that dictionary.
36
- */
37
- background?: ?(
38
- | $ReadOnly<{|
39
- type: "ThemeAttrAndroid",
40
- attribute:
41
- | "selectableItemBackground"
42
- | "selectableItemBackgroundBorderless",
43
- rippleRadius: ?number,
44
- |}>
45
- | $ReadOnly<{|
46
- type: "RippleAndroid",
47
- color: ?number,
48
- borderless: boolean,
49
- rippleRadius: ?number,
50
- |}>
51
- ),
52
-
53
- /**
54
- * TV preferred focus (see documentation for the View component).
55
- */
56
- hasTVPreferredFocus?: ?boolean,
57
-
58
- /**
59
- * TV next focus down (see documentation for the View component).
60
- */
61
- nextFocusDown?: ?number,
62
-
63
- /**
64
- * TV next focus forward (see documentation for the View component).
65
- */
66
- nextFocusForward?: ?number,
67
-
68
- /**
69
- * TV next focus left (see documentation for the View component).
70
- */
71
- nextFocusLeft?: ?number,
72
-
73
- /**
74
- * TV next focus right (see documentation for the View component).
75
- */
76
- nextFocusRight?: ?number,
77
-
78
- /**
79
- * TV next focus up (see documentation for the View component).
80
- */
81
- nextFocusUp?: ?number,
82
-
83
- /**
84
- * Set to true to add the ripple effect to the foreground of the view, instead
85
- * of the background. This is useful if one of your child views has a
86
- * background of its own, or you're e.g. displaying images, and you don't want
87
- * the ripple to be covered by them.
88
- *
89
- * Check TouchableNativeFeedback.canUseNativeForeground() first, as this is
90
- * only available on Android 6.0 and above. If you try to use this on older
91
- * versions, this will fallback to background.
92
- */
93
- useForeground?: ?boolean,
94
- |}>;
95
-
96
- type State = $ReadOnly<{|
97
- pressability: Pressability,
98
- |}>;
99
-
100
- class TouchableNativeFeedback extends React.Component<Props, State> {
101
- /**
102
- * Creates a value for the `background` prop that uses the Android theme's
103
- * default background for selectable elements.
104
- */
105
- static SelectableBackground: (rippleRadius: ?number) => $ReadOnly<{|
106
- attribute: "selectableItemBackground",
107
- type: "ThemeAttrAndroid",
108
- rippleRadius: ?number,
109
- |}> = (rippleRadius: ?number) => ({
110
- type: "ThemeAttrAndroid",
111
- attribute: "selectableItemBackground",
112
- rippleRadius,
113
- });
114
-
115
- /**
116
- * Creates a value for the `background` prop that uses the Android theme's
117
- * default background for borderless selectable elements. Requires API 21+.
118
- */
119
- static SelectableBackgroundBorderless: (rippleRadius: ?number) => $ReadOnly<{|
120
- attribute: "selectableItemBackgroundBorderless",
121
- type: "ThemeAttrAndroid",
122
- rippleRadius: ?number,
123
- |}> = (rippleRadius: ?number) => ({
124
- type: "ThemeAttrAndroid",
125
- attribute: "selectableItemBackgroundBorderless",
126
- rippleRadius,
127
- });
128
-
129
- /**
130
- * Creates a value for the `background` prop that uses the Android ripple with
131
- * the supplied color. If `borderless` is true, the ripple will render outside
132
- * of the view bounds. Requires API 21+.
133
- */
134
- static Ripple: (
135
- color: string,
136
- borderless: boolean,
137
- rippleRadius: ?number
138
- ) => $ReadOnly<{|
139
- borderless: boolean,
140
- color: ?number,
141
- rippleRadius: ?number,
142
- type: "RippleAndroid",
143
- |}> = (color: string, borderless: boolean, rippleRadius: ?number) => {
144
- const processedColor = processColor(color);
145
- invariant(
146
- processedColor == null || typeof processedColor === "number",
147
- "Unexpected color given for Ripple color"
148
- );
149
- return {
150
- type: "RippleAndroid",
151
- color: processedColor,
152
- borderless,
153
- rippleRadius,
154
- };
155
- };
156
-
157
- /**
158
- * Whether `useForeground` is supported.
159
- */
160
- static canUseNativeForeground: () => boolean = () =>
161
- Platform.OS === "android" && Platform.Version >= 23;
162
-
163
- state: State = {
164
- pressability: new Pressability(this._createPressabilityConfig()),
165
- };
166
-
167
- _createPressabilityConfig(): PressabilityConfig {
168
- const accessibilityStateDisabled =
169
- this.props["aria-disabled"] ?? this.props.accessibilityState?.disabled;
170
- return {
171
- cancelable: !this.props.rejectResponderTermination,
172
- disabled:
173
- this.props.disabled != null
174
- ? this.props.disabled
175
- : accessibilityStateDisabled,
176
- hitSlop: this.props.hitSlop,
177
- delayLongPress: this.props.delayLongPress,
178
- delayPressIn: this.props.delayPressIn,
179
- delayPressOut: this.props.delayPressOut,
180
- minPressDuration: 0,
181
- pressRectOffset: this.props.pressRetentionOffset,
182
- android_disableSound: this.props.touchSoundDisabled,
183
- onLongPress: this.props.onLongPress,
184
- onPress: this.props.onPress,
185
- onPressIn: (event) => {
186
- if (Platform.OS === "android") {
187
- this._dispatchHotspotUpdate(event);
188
- this._dispatchPressedStateChange(true);
189
- }
190
- if (this.props.onPressIn != null) {
191
- this.props.onPressIn(event);
192
- }
193
- },
194
- onPressMove: (event) => {
195
- if (Platform.OS === "android") {
196
- this._dispatchHotspotUpdate(event);
197
- }
198
- },
199
- onPressOut: (event) => {
200
- if (Platform.OS === "android") {
201
- this._dispatchPressedStateChange(false);
202
- }
203
- if (this.props.onPressOut != null) {
204
- this.props.onPressOut(event);
205
- }
206
- },
207
- };
208
- }
209
-
210
- _dispatchPressedStateChange(pressed: boolean): void {
211
- if (Platform.OS === "android") {
212
- const hostComponentRef = findHostInstance_DEPRECATED(this);
213
- if (hostComponentRef == null) {
214
- console.warn(
215
- "Touchable: Unable to find HostComponent instance. " +
216
- "Has your Touchable component been unmounted?"
217
- );
218
- } else {
219
- Commands.setPressed(hostComponentRef, pressed);
220
- }
221
- }
222
- }
223
-
224
- _dispatchHotspotUpdate(event: PressEvent): void {
225
- if (Platform.OS === "android") {
226
- const { locationX, locationY } = event.nativeEvent;
227
- const hostComponentRef = findHostInstance_DEPRECATED(this);
228
- if (hostComponentRef == null) {
229
- console.warn(
230
- "Touchable: Unable to find HostComponent instance. " +
231
- "Has your Touchable component been unmounted?"
232
- );
233
- } else {
234
- Commands.hotspotUpdate(
235
- hostComponentRef,
236
- locationX ?? 0,
237
- locationY ?? 0
238
- );
239
- }
240
- }
241
- }
242
-
243
- render(): React.Node {
244
- const element = React.Children.only<$FlowFixMe>(this.props.children);
245
- const children: Array<React.Node> = [element.props.children];
246
- if (__DEV__) {
247
- if (element.type === View) {
248
- children.push(
249
- <PressabilityDebugView color="brown" hitSlop={this.props.hitSlop} />
250
- );
251
- }
252
- }
253
-
254
- // BACKWARD-COMPATIBILITY: Focus and blur events were never supported before
255
- // adopting `Pressability`, so preserve that behavior.
256
- const { onBlur, onFocus, ...eventHandlersWithoutBlurAndFocus } =
257
- this.state.pressability.getEventHandlers();
258
-
259
- let _accessibilityState = {
260
- busy: this.props["aria-busy"] ?? this.props.accessibilityState?.busy,
261
- checked:
262
- this.props["aria-checked"] ?? this.props.accessibilityState?.checked,
263
- disabled:
264
- this.props["aria-disabled"] ?? this.props.accessibilityState?.disabled,
265
- expanded:
266
- this.props["aria-expanded"] ?? this.props.accessibilityState?.expanded,
267
- selected:
268
- this.props["aria-selected"] ?? this.props.accessibilityState?.selected,
269
- };
270
-
271
- _accessibilityState =
272
- this.props.disabled != null
273
- ? {
274
- ..._accessibilityState,
275
- disabled: this.props.disabled,
276
- }
277
- : _accessibilityState;
278
-
279
- const accessibilityValue = {
280
- max: this.props["aria-valuemax"] ?? this.props.accessibilityValue?.max,
281
- min: this.props["aria-valuemin"] ?? this.props.accessibilityValue?.min,
282
- now: this.props["aria-valuenow"] ?? this.props.accessibilityValue?.now,
283
- text: this.props["aria-valuetext"] ?? this.props.accessibilityValue?.text,
284
- };
285
-
286
- const accessibilityLiveRegion =
287
- this.props["aria-live"] === "off"
288
- ? "none"
289
- : this.props["aria-live"] ?? this.props.accessibilityLiveRegion;
290
-
291
- const accessibilityLabel =
292
- this.props["aria-label"] ?? this.props.accessibilityLabel;
293
- return React.cloneElement(
294
- element,
295
- {
296
- ...eventHandlersWithoutBlurAndFocus,
297
- ...getBackgroundProp(
298
- this.props.background === undefined
299
- ? TouchableNativeFeedback.SelectableBackground()
300
- : this.props.background,
301
- this.props.useForeground === true
302
- ),
303
- accessible: this.props.accessible !== false,
304
- accessibilityHint: this.props.accessibilityHint,
305
- accessibilityLanguage: this.props.accessibilityLanguage,
306
- accessibilityLabel: accessibilityLabel,
307
- accessibilityRole: this.props.accessibilityRole,
308
- accessibilityState: _accessibilityState,
309
- accessibilityActions: this.props.accessibilityActions,
310
- onAccessibilityAction: this.props.onAccessibilityAction,
311
- accessibilityValue: accessibilityValue,
312
- importantForAccessibility:
313
- this.props["aria-hidden"] === true
314
- ? "no-hide-descendants"
315
- : this.props.importantForAccessibility,
316
- accessibilityViewIsModal:
317
- this.props["aria-modal"] ?? this.props.accessibilityViewIsModal,
318
- accessibilityLiveRegion: accessibilityLiveRegion,
319
- accessibilityElementsHidden:
320
- this.props["aria-hidden"] ?? this.props.accessibilityElementsHidden,
321
- hasTVPreferredFocus: this.props.hasTVPreferredFocus,
322
- hitSlop: this.props.hitSlop,
323
- focusable:
324
- this.props.focusable !== false &&
325
- this.props.onPress !== undefined &&
326
- !this.props.disabled,
327
- nativeID: this.props.nativeID,
328
- nextFocusDown: this.props.nextFocusDown,
329
- nextFocusForward: this.props.nextFocusForward,
330
- nextFocusLeft: this.props.nextFocusLeft,
331
- nextFocusRight: this.props.nextFocusRight,
332
- nextFocusUp: this.props.nextFocusUp,
333
- onLayout: this.props.onLayout,
334
- testID: this.props.testID,
335
- collapsable: false, // RNOH: patch
336
- },
337
- ...children
338
- );
339
- }
340
-
341
- componentDidUpdate(prevProps: Props, prevState: State) {
342
- this.state.pressability.configure(this._createPressabilityConfig());
343
- }
344
-
345
- componentWillUnmount(): void {
346
- this.state.pressability.reset();
347
- }
348
- }
349
-
350
- const getBackgroundProp =
351
- Platform.OS === "android"
352
- ? /* $FlowFixMe[missing-local-annot] The type annotation(s) required by
353
- * Flow's LTI update could not be added via codemod */
354
- (background, useForeground: boolean) =>
355
- useForeground && TouchableNativeFeedback.canUseNativeForeground()
356
- ? { nativeForegroundAndroid: background }
357
- : { nativeBackgroundAndroid: background }
358
- : /* $FlowFixMe[missing-local-annot] The type annotation(s) required by
359
- * Flow's LTI update could not be added via codemod */
360
- (background, useForeground: boolean) => null;
361
-
362
- TouchableNativeFeedback.displayName = "TouchableNativeFeedback";
363
-
364
- module.exports = TouchableNativeFeedback;
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ // RNOH patch: disable view flattening
12
+
13
+ import type { PressEvent } from "react-native/Libraries/Types/CoreEventTypes";
14
+ import typeof TouchableWithoutFeedback from "./TouchableWithoutFeedback";
15
+
16
+ import View from "react-native/Libraries/Components/View/View";
17
+ import Pressability, {
18
+ type PressabilityConfig,
19
+ } from "react-native/Libraries/Pressability/Pressability";
20
+ import { PressabilityDebugView } from "react-native/Libraries/Pressability/PressabilityDebug";
21
+ import { findHostInstance_DEPRECATED } from "react-native/Libraries/ReactNative/RendererProxy";
22
+ import processColor from "react-native/Libraries/StyleSheet/processColor";
23
+ import Platform from "react-native/Libraries/Utilities/Platform";
24
+ import { Commands } from "react-native/Libraries/Components/View/ViewNativeComponent";
25
+ import invariant from "invariant";
26
+ import * as React from "react";
27
+
28
+ type Props = $ReadOnly<{|
29
+ ...React.ElementConfig<TouchableWithoutFeedback>,
30
+
31
+ /**
32
+ * Determines the type of background drawable that's going to be used to
33
+ * display feedback. It takes an object with `type` property and extra data
34
+ * depending on the `type`. It's recommended to use one of the static
35
+ * methods to generate that dictionary.
36
+ */
37
+ background?: ?(
38
+ | $ReadOnly<{|
39
+ type: "ThemeAttrAndroid",
40
+ attribute:
41
+ | "selectableItemBackground"
42
+ | "selectableItemBackgroundBorderless",
43
+ rippleRadius: ?number,
44
+ |}>
45
+ | $ReadOnly<{|
46
+ type: "RippleAndroid",
47
+ color: ?number,
48
+ borderless: boolean,
49
+ rippleRadius: ?number,
50
+ |}>
51
+ ),
52
+
53
+ /**
54
+ * TV preferred focus (see documentation for the View component).
55
+ */
56
+ hasTVPreferredFocus?: ?boolean,
57
+
58
+ /**
59
+ * TV next focus down (see documentation for the View component).
60
+ */
61
+ nextFocusDown?: ?number,
62
+
63
+ /**
64
+ * TV next focus forward (see documentation for the View component).
65
+ */
66
+ nextFocusForward?: ?number,
67
+
68
+ /**
69
+ * TV next focus left (see documentation for the View component).
70
+ */
71
+ nextFocusLeft?: ?number,
72
+
73
+ /**
74
+ * TV next focus right (see documentation for the View component).
75
+ */
76
+ nextFocusRight?: ?number,
77
+
78
+ /**
79
+ * TV next focus up (see documentation for the View component).
80
+ */
81
+ nextFocusUp?: ?number,
82
+
83
+ /**
84
+ * Set to true to add the ripple effect to the foreground of the view, instead
85
+ * of the background. This is useful if one of your child views has a
86
+ * background of its own, or you're e.g. displaying images, and you don't want
87
+ * the ripple to be covered by them.
88
+ *
89
+ * Check TouchableNativeFeedback.canUseNativeForeground() first, as this is
90
+ * only available on Android 6.0 and above. If you try to use this on older
91
+ * versions, this will fallback to background.
92
+ */
93
+ useForeground?: ?boolean,
94
+ |}>;
95
+
96
+ type State = $ReadOnly<{|
97
+ pressability: Pressability,
98
+ |}>;
99
+
100
+ class TouchableNativeFeedback extends React.Component<Props, State> {
101
+ /**
102
+ * Creates a value for the `background` prop that uses the Android theme's
103
+ * default background for selectable elements.
104
+ */
105
+ static SelectableBackground: (rippleRadius: ?number) => $ReadOnly<{|
106
+ attribute: "selectableItemBackground",
107
+ type: "ThemeAttrAndroid",
108
+ rippleRadius: ?number,
109
+ |}> = (rippleRadius: ?number) => ({
110
+ type: "ThemeAttrAndroid",
111
+ attribute: "selectableItemBackground",
112
+ rippleRadius,
113
+ });
114
+
115
+ /**
116
+ * Creates a value for the `background` prop that uses the Android theme's
117
+ * default background for borderless selectable elements. Requires API 21+.
118
+ */
119
+ static SelectableBackgroundBorderless: (rippleRadius: ?number) => $ReadOnly<{|
120
+ attribute: "selectableItemBackgroundBorderless",
121
+ type: "ThemeAttrAndroid",
122
+ rippleRadius: ?number,
123
+ |}> = (rippleRadius: ?number) => ({
124
+ type: "ThemeAttrAndroid",
125
+ attribute: "selectableItemBackgroundBorderless",
126
+ rippleRadius,
127
+ });
128
+
129
+ /**
130
+ * Creates a value for the `background` prop that uses the Android ripple with
131
+ * the supplied color. If `borderless` is true, the ripple will render outside
132
+ * of the view bounds. Requires API 21+.
133
+ */
134
+ static Ripple: (
135
+ color: string,
136
+ borderless: boolean,
137
+ rippleRadius: ?number
138
+ ) => $ReadOnly<{|
139
+ borderless: boolean,
140
+ color: ?number,
141
+ rippleRadius: ?number,
142
+ type: "RippleAndroid",
143
+ |}> = (color: string, borderless: boolean, rippleRadius: ?number) => {
144
+ const processedColor = processColor(color);
145
+ invariant(
146
+ processedColor == null || typeof processedColor === "number",
147
+ "Unexpected color given for Ripple color"
148
+ );
149
+ return {
150
+ type: "RippleAndroid",
151
+ color: processedColor,
152
+ borderless,
153
+ rippleRadius,
154
+ };
155
+ };
156
+
157
+ /**
158
+ * Whether `useForeground` is supported.
159
+ */
160
+ static canUseNativeForeground: () => boolean = () =>
161
+ Platform.OS === "android" && Platform.Version >= 23;
162
+
163
+ state: State = {
164
+ pressability: new Pressability(this._createPressabilityConfig()),
165
+ };
166
+
167
+ _createPressabilityConfig(): PressabilityConfig {
168
+ const accessibilityStateDisabled =
169
+ this.props["aria-disabled"] ?? this.props.accessibilityState?.disabled;
170
+ return {
171
+ cancelable: !this.props.rejectResponderTermination,
172
+ disabled:
173
+ this.props.disabled != null
174
+ ? this.props.disabled
175
+ : accessibilityStateDisabled,
176
+ hitSlop: this.props.hitSlop,
177
+ delayLongPress: this.props.delayLongPress,
178
+ delayPressIn: this.props.delayPressIn,
179
+ delayPressOut: this.props.delayPressOut,
180
+ minPressDuration: 0,
181
+ pressRectOffset: this.props.pressRetentionOffset,
182
+ android_disableSound: this.props.touchSoundDisabled,
183
+ onLongPress: this.props.onLongPress,
184
+ onPress: this.props.onPress,
185
+ onPressIn: (event) => {
186
+ if (Platform.OS === "android") {
187
+ this._dispatchHotspotUpdate(event);
188
+ this._dispatchPressedStateChange(true);
189
+ }
190
+ if (this.props.onPressIn != null) {
191
+ this.props.onPressIn(event);
192
+ }
193
+ },
194
+ onPressMove: (event) => {
195
+ if (Platform.OS === "android") {
196
+ this._dispatchHotspotUpdate(event);
197
+ }
198
+ },
199
+ onPressOut: (event) => {
200
+ if (Platform.OS === "android") {
201
+ this._dispatchPressedStateChange(false);
202
+ }
203
+ if (this.props.onPressOut != null) {
204
+ this.props.onPressOut(event);
205
+ }
206
+ },
207
+ };
208
+ }
209
+
210
+ _dispatchPressedStateChange(pressed: boolean): void {
211
+ if (Platform.OS === "android") {
212
+ const hostComponentRef = findHostInstance_DEPRECATED(this);
213
+ if (hostComponentRef == null) {
214
+ console.warn(
215
+ "Touchable: Unable to find HostComponent instance. " +
216
+ "Has your Touchable component been unmounted?"
217
+ );
218
+ } else {
219
+ Commands.setPressed(hostComponentRef, pressed);
220
+ }
221
+ }
222
+ }
223
+
224
+ _dispatchHotspotUpdate(event: PressEvent): void {
225
+ if (Platform.OS === "android") {
226
+ const { locationX, locationY } = event.nativeEvent;
227
+ const hostComponentRef = findHostInstance_DEPRECATED(this);
228
+ if (hostComponentRef == null) {
229
+ console.warn(
230
+ "Touchable: Unable to find HostComponent instance. " +
231
+ "Has your Touchable component been unmounted?"
232
+ );
233
+ } else {
234
+ Commands.hotspotUpdate(
235
+ hostComponentRef,
236
+ locationX ?? 0,
237
+ locationY ?? 0
238
+ );
239
+ }
240
+ }
241
+ }
242
+
243
+ render(): React.Node {
244
+ const element = React.Children.only<$FlowFixMe>(this.props.children);
245
+ const children: Array<React.Node> = [element.props.children];
246
+ if (__DEV__) {
247
+ if (element.type === View) {
248
+ children.push(
249
+ <PressabilityDebugView color="brown" hitSlop={this.props.hitSlop} />
250
+ );
251
+ }
252
+ }
253
+
254
+ // BACKWARD-COMPATIBILITY: Focus and blur events were never supported before
255
+ // adopting `Pressability`, so preserve that behavior.
256
+ const { onBlur, onFocus, ...eventHandlersWithoutBlurAndFocus } =
257
+ this.state.pressability.getEventHandlers();
258
+
259
+ let _accessibilityState = {
260
+ busy: this.props["aria-busy"] ?? this.props.accessibilityState?.busy,
261
+ checked:
262
+ this.props["aria-checked"] ?? this.props.accessibilityState?.checked,
263
+ disabled:
264
+ this.props["aria-disabled"] ?? this.props.accessibilityState?.disabled,
265
+ expanded:
266
+ this.props["aria-expanded"] ?? this.props.accessibilityState?.expanded,
267
+ selected:
268
+ this.props["aria-selected"] ?? this.props.accessibilityState?.selected,
269
+ };
270
+
271
+ _accessibilityState =
272
+ this.props.disabled != null
273
+ ? {
274
+ ..._accessibilityState,
275
+ disabled: this.props.disabled,
276
+ }
277
+ : _accessibilityState;
278
+
279
+ const accessibilityValue = {
280
+ max: this.props["aria-valuemax"] ?? this.props.accessibilityValue?.max,
281
+ min: this.props["aria-valuemin"] ?? this.props.accessibilityValue?.min,
282
+ now: this.props["aria-valuenow"] ?? this.props.accessibilityValue?.now,
283
+ text: this.props["aria-valuetext"] ?? this.props.accessibilityValue?.text,
284
+ };
285
+
286
+ const accessibilityLiveRegion =
287
+ this.props["aria-live"] === "off"
288
+ ? "none"
289
+ : this.props["aria-live"] ?? this.props.accessibilityLiveRegion;
290
+
291
+ const accessibilityLabel =
292
+ this.props["aria-label"] ?? this.props.accessibilityLabel;
293
+ return React.cloneElement(
294
+ element,
295
+ {
296
+ ...eventHandlersWithoutBlurAndFocus,
297
+ ...getBackgroundProp(
298
+ this.props.background === undefined
299
+ ? TouchableNativeFeedback.SelectableBackground()
300
+ : this.props.background,
301
+ this.props.useForeground === true
302
+ ),
303
+ accessible: this.props.accessible !== false,
304
+ accessibilityHint: this.props.accessibilityHint,
305
+ accessibilityLanguage: this.props.accessibilityLanguage,
306
+ accessibilityLabel: accessibilityLabel,
307
+ accessibilityRole: this.props.accessibilityRole,
308
+ accessibilityState: _accessibilityState,
309
+ accessibilityActions: this.props.accessibilityActions,
310
+ onAccessibilityAction: this.props.onAccessibilityAction,
311
+ accessibilityValue: accessibilityValue,
312
+ importantForAccessibility:
313
+ this.props["aria-hidden"] === true
314
+ ? "no-hide-descendants"
315
+ : this.props.importantForAccessibility,
316
+ accessibilityViewIsModal:
317
+ this.props["aria-modal"] ?? this.props.accessibilityViewIsModal,
318
+ accessibilityLiveRegion: accessibilityLiveRegion,
319
+ accessibilityElementsHidden:
320
+ this.props["aria-hidden"] ?? this.props.accessibilityElementsHidden,
321
+ hasTVPreferredFocus: this.props.hasTVPreferredFocus,
322
+ hitSlop: this.props.hitSlop,
323
+ focusable:
324
+ this.props.focusable !== false &&
325
+ this.props.onPress !== undefined &&
326
+ !this.props.disabled,
327
+ nativeID: this.props.nativeID,
328
+ nextFocusDown: this.props.nextFocusDown,
329
+ nextFocusForward: this.props.nextFocusForward,
330
+ nextFocusLeft: this.props.nextFocusLeft,
331
+ nextFocusRight: this.props.nextFocusRight,
332
+ nextFocusUp: this.props.nextFocusUp,
333
+ onLayout: this.props.onLayout,
334
+ testID: this.props.testID,
335
+ collapsable: false, // RNOH: patch
336
+ },
337
+ ...children
338
+ );
339
+ }
340
+
341
+ componentDidUpdate(prevProps: Props, prevState: State) {
342
+ this.state.pressability.configure(this._createPressabilityConfig());
343
+ }
344
+
345
+ componentWillUnmount(): void {
346
+ this.state.pressability.reset();
347
+ }
348
+ }
349
+
350
+ const getBackgroundProp =
351
+ Platform.OS === "android"
352
+ ? /* $FlowFixMe[missing-local-annot] The type annotation(s) required by
353
+ * Flow's LTI update could not be added via codemod */
354
+ (background, useForeground: boolean) =>
355
+ useForeground && TouchableNativeFeedback.canUseNativeForeground()
356
+ ? { nativeForegroundAndroid: background }
357
+ : { nativeBackgroundAndroid: background }
358
+ : /* $FlowFixMe[missing-local-annot] The type annotation(s) required by
359
+ * Flow's LTI update could not be added via codemod */
360
+ (background, useForeground: boolean) => null;
361
+
362
+ TouchableNativeFeedback.displayName = "TouchableNativeFeedback";
363
+
364
+ module.exports = TouchableNativeFeedback;