@react-native-oh/react-native-harmony 0.72.86 → 0.77.18

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 (81) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-Meta +21 -0
  3. package/Libraries/Alert/delegates/AlertDelegate.harmony.ts +84 -0
  4. package/Libraries/Alert/{AlertManager.ts → delegates/AlertManager.harmony.ts} +10 -4
  5. package/Libraries/Animated/shouldUseTurboAnimatedModule.harmony.ts +10 -0
  6. package/Libraries/Components/AccessibilityInfo/delegates/AccessibilityInfoDelegate.harmony.ts +44 -0
  7. package/Libraries/Components/AccessibilityInfo/{NativeAccessibilityInfoHarmony.ts → delegates/NativeAccessibilityInfoHarmony.harmony.ts} +9 -2
  8. package/Libraries/Components/Keyboard/delegates/KeyboardAvoidingViewDelegate.harmony.ts +42 -0
  9. package/Libraries/Components/RefreshControl/delegates/RefreshControlDelegate.harmony.tsx +29 -0
  10. package/Libraries/Components/SafeAreaView/SafeAreaView.harmony.tsx +93 -31
  11. package/Libraries/Components/ScrollView/delegates/ScrollViewDelegate.harmony.tsx +41 -0
  12. package/Libraries/Components/ScrollView/delegates/ScrollViewNativeComponentDelegate.harmony.ts +89 -0
  13. package/Libraries/Components/ScrollView/processDecelerationRate.harmony.ts +19 -0
  14. package/Libraries/Components/StatusBar/delegates/NativeStatusBarManagerHarmony.harmony.ts +53 -0
  15. package/Libraries/Components/StatusBar/delegates/StatusBarDelegate.harmony.ts +83 -0
  16. package/Libraries/Components/TextInput/delegates/TextInputDelegate.harmony.tsx +98 -0
  17. package/Libraries/Components/TextInput/delegates/TextInputStateDelegate.harmony.tsx +20 -0
  18. package/Libraries/Components/Touchable/delegates/TouchableHighlightDelegate.harmony.ts +14 -0
  19. package/Libraries/Components/Touchable/delegates/TouchableNativeFeedbackDelegate.harmony.ts +14 -0
  20. package/Libraries/Components/Touchable/delegates/TouchableWithoutFeedbackDelegate.harmony.ts +14 -0
  21. package/Libraries/Components/delegates/ButtonDelegate.harmony.ts +41 -0
  22. package/Libraries/Core/setUpPlatform.harmony.js +30 -0
  23. package/Libraries/Image/AssetSourceResolver.harmony.ts +1 -5
  24. package/Libraries/Image/Image.harmony.ts +17 -0
  25. package/Libraries/NativeComponent/BaseViewConfig.harmony.js +12 -326
  26. package/Libraries/NativeComponent/delegates/ViewConfigIgnoreDelegate.harmony.ts +13 -0
  27. package/Libraries/ReactNative/delegates/BridgelessUIManagerDelegate.harmony.ts +14 -0
  28. package/Libraries/ReactNative/delegates/I18nManagerDelegate.harmony.ts +22 -0
  29. package/Libraries/Settings/Settings.harmony.ts +20 -0
  30. package/Libraries/Share/delegates/ShareDelegate.harmony.ts +42 -0
  31. package/Libraries/StyleSheet/NativePlatformColor.harmony.ts +15 -0
  32. package/Libraries/StyleSheet/PlatformColorValueTypes.harmony.ts +8 -1
  33. package/Libraries/Utilities/BackHandler.harmony.ts +10 -0
  34. package/Libraries/Utilities/NativePlatformConstantsHarmony.harmony.ts +17 -0
  35. package/Libraries/Utilities/Platform.harmony.ts +38 -13
  36. package/Libraries/Vibration/delegates/VibrationDelegate.harmony.ts +14 -0
  37. package/NOTICE.md +846 -0
  38. package/README.md +2 -2
  39. package/index.js +53 -63
  40. package/jest.config.js +0 -7
  41. package/metro.config.d.ts +17 -0
  42. package/metro.config.js +398 -115
  43. package/package.json +58 -37
  44. package/react-native.config.js +57 -9
  45. package/react_native_openharmony.har +0 -0
  46. package/tsconfig.json +10 -4
  47. package/types/index.harmony.d.ts +99 -0
  48. package/Libraries/Alert/Alert.harmony.js +0 -77
  49. package/Libraries/Animated/NativeAnimatedHelper.harmony.js +0 -601
  50. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.harmony.js +0 -441
  51. package/Libraries/Components/Button/Button.harmony.js +0 -451
  52. package/Libraries/Components/Image/Image.flow.harmony.js +0 -53
  53. package/Libraries/Components/Image/Image.harmony.js +0 -317
  54. package/Libraries/Components/Image/NativeImageLoaderHarmony.js +0 -38
  55. package/Libraries/Components/Keyboard/KeyboardAvoidingView.harmony.js +0 -256
  56. package/Libraries/Components/RefreshControl/RefreshControl.harmony.js +0 -210
  57. package/Libraries/Components/ScrollView/ScrollView.harmony.js +0 -1951
  58. package/Libraries/Components/ScrollView/processDecelerationRate.harmony.js +0 -24
  59. package/Libraries/Components/StatusBar/NativeStatusBarManagerHarmony.js +0 -71
  60. package/Libraries/Components/StatusBar/StatusBar.harmony.js +0 -447
  61. package/Libraries/Components/TextInput/TextInput.harmony.js +0 -1716
  62. package/Libraries/Components/TextInput/TextInputState.harmony.js +0 -220
  63. package/Libraries/Components/Touchable/TouchableHighlight.harmony.js +0 -396
  64. package/Libraries/Components/Touchable/TouchableNativeFeedback.harmony.js +0 -364
  65. package/Libraries/Components/Touchable/TouchableWithoutFeedback.harmony.js +0 -227
  66. package/Libraries/Components/View/View.harmony.js +0 -149
  67. package/Libraries/Core/setUpReactDevTools.harmony.js +0 -93
  68. package/Libraries/ReactNative/I18nManager.harmony.js +0 -78
  69. package/Libraries/ReactNative/UIManager.harmony.js +0 -210
  70. package/Libraries/Settings/Settings.harmony.js +0 -15
  71. package/Libraries/Share/Share.harmony.js +0 -174
  72. package/Libraries/StyleSheet/NativePlatformColor.ts +0 -8
  73. package/Libraries/Utilities/BackHandler.harmony.js +0 -109
  74. package/Libraries/Utilities/NativePlatformConstants.harmony.ts +0 -8
  75. package/Libraries/Utilities/Platform.d.ts +0 -117
  76. package/Libraries/Utilities/createPerformanceLogger.harmony.js +0 -328
  77. package/Libraries/Vibration/Vibration.harmony.js +0 -88
  78. package/harmony/.keep +0 -0
  79. package/harmony/rnoh-hvigor-plugin-0.2.0.tgz +0 -0
  80. package/react_native_openharmony_release.har +0 -0
  81. package/types/index.d.ts +0 -108
@@ -1,601 +0,0 @@
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
- import type {EventSubscription} from 'react-native/Libraries/vendor/emitter/EventEmitter';
12
- import type {EventConfig} from 'react-native/Libraries/Animated/AnimatedEvent';
13
- import type {AnimationConfig, EndCallback} from 'react-native/Libraries/Animated/animations/Animation';
14
- import type {
15
- AnimatedNodeConfig,
16
- AnimatingNodeConfig,
17
- EventMapping,
18
- } from 'react-native/Libraries/Animated/NativeAnimatedModule';
19
- import type {InterpolationConfigType} from 'react-native/Libraries/Animated/nodes/AnimatedInterpolation';
20
-
21
- import NativeEventEmitter from 'react-native/Libraries/EventEmitter/NativeEventEmitter';
22
- import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter';
23
- import ReactNativeFeatureFlags from 'react-native/Libraries/ReactNative/ReactNativeFeatureFlags';
24
- import Platform from '../Utilities/Platform';
25
- import NativeAnimatedNonTurboModule from 'react-native/Libraries/Animated/NativeAnimatedModule';
26
- import NativeAnimatedTurboModule from 'react-native/Libraries/Animated/NativeAnimatedTurboModule';
27
- import invariant from 'invariant';
28
-
29
- // RNOH Patch: always use TurboModule version of NativeAnimatedModule
30
- const NativeAnimatedModule = NativeAnimatedTurboModule;
31
-
32
- let __nativeAnimatedNodeTagCount = 1; /* used for animated nodes */
33
- let __nativeAnimationIdCount = 1; /* used for started animations */
34
-
35
- let nativeEventEmitter;
36
-
37
- let waitingForQueuedOperations = new Set<string>();
38
- let queueOperations = false;
39
- let queue: Array<() => void> = [];
40
- // $FlowFixMe
41
- let singleOpQueue: Array<any> = [];
42
-
43
- const useSingleOpBatching =
44
- Platform.OS === 'android' &&
45
- !!NativeAnimatedModule?.queueAndExecuteBatchedOperations &&
46
- ReactNativeFeatureFlags.animatedShouldUseSingleOp();
47
- let flushQueueTimeout = null;
48
-
49
- const eventListenerGetValueCallbacks: {
50
- [$FlowFixMe | number]: ((value: number) => void) | void,
51
- } = {};
52
- const eventListenerAnimationFinishedCallbacks: {
53
- [$FlowFixMe | number]: EndCallback | void,
54
- } = {};
55
- let globalEventEmitterGetValueListener: ?EventSubscription = null;
56
- let globalEventEmitterAnimationFinishedListener: ?EventSubscription = null;
57
-
58
- const nativeOps: ?typeof NativeAnimatedModule = useSingleOpBatching
59
- ? ((function () {
60
- const apis = [
61
- 'createAnimatedNode', // 1
62
- 'updateAnimatedNodeConfig', // 2
63
- 'getValue', // 3
64
- 'startListeningToAnimatedNodeValue', // 4
65
- 'stopListeningToAnimatedNodeValue', // 5
66
- 'connectAnimatedNodes', // 6
67
- 'disconnectAnimatedNodes', // 7
68
- 'startAnimatingNode', // 8
69
- 'stopAnimation', // 9
70
- 'setAnimatedNodeValue', // 10
71
- 'setAnimatedNodeOffset', // 11
72
- 'flattenAnimatedNodeOffset', // 12
73
- 'extractAnimatedNodeOffset', // 13
74
- 'connectAnimatedNodeToView', // 14
75
- 'disconnectAnimatedNodeFromView', // 15
76
- 'restoreDefaultValues', // 16
77
- 'dropAnimatedNode', // 17
78
- 'addAnimatedEventToView', // 18
79
- 'removeAnimatedEventFromView', // 19
80
- 'addListener', // 20
81
- 'removeListener', // 21
82
- ];
83
- return apis.reduce<{[string]: number}>((acc, functionName, i) => {
84
- // These indices need to be kept in sync with the indices in native (see NativeAnimatedModule in Java, or the equivalent for any other native platform).
85
- // $FlowFixMe[prop-missing]
86
- acc[functionName] = i + 1;
87
- return acc;
88
- }, {});
89
- })(): $FlowFixMe)
90
- : NativeAnimatedModule;
91
-
92
- /**
93
- * Wrappers around NativeAnimatedModule to provide flow and autocomplete support for
94
- * the native module methods, and automatic queue management on Android
95
- */
96
- const API = {
97
- getValue: function (
98
- tag: number,
99
- saveValueCallback: (value: number) => void,
100
- ): void {
101
- invariant(nativeOps, 'Native animated module is not available');
102
- if (useSingleOpBatching) {
103
- if (saveValueCallback) {
104
- eventListenerGetValueCallbacks[tag] = saveValueCallback;
105
- }
106
- // $FlowFixMe
107
- API.queueOperation(nativeOps.getValue, tag);
108
- } else {
109
- API.queueOperation(nativeOps.getValue, tag, saveValueCallback);
110
- }
111
- },
112
- setWaitingForIdentifier: function (id: string): void {
113
- waitingForQueuedOperations.add(id);
114
- queueOperations = true;
115
- if (
116
- ReactNativeFeatureFlags.animatedShouldDebounceQueueFlush() &&
117
- flushQueueTimeout
118
- ) {
119
- clearTimeout(flushQueueTimeout);
120
- }
121
- },
122
- unsetWaitingForIdentifier: function (id: string): void {
123
- waitingForQueuedOperations.delete(id);
124
-
125
- if (waitingForQueuedOperations.size === 0) {
126
- queueOperations = false;
127
- API.disableQueue();
128
- }
129
- },
130
- disableQueue: function (): void {
131
- invariant(nativeOps, 'Native animated module is not available');
132
-
133
- if (ReactNativeFeatureFlags.animatedShouldDebounceQueueFlush()) {
134
- const prevTimeout = flushQueueTimeout;
135
- clearImmediate(prevTimeout);
136
- flushQueueTimeout = setImmediate(API.flushQueue);
137
- } else {
138
- API.flushQueue();
139
- }
140
- },
141
- flushQueue: function (): void {
142
- // TODO: (T136971132)
143
- invariant(
144
- NativeAnimatedModule || process.env.NODE_ENV === 'test',
145
- 'Native animated module is not available',
146
- );
147
- flushQueueTimeout = null;
148
-
149
- // Early returns before calling any APIs
150
- if (useSingleOpBatching && singleOpQueue.length === 0) {
151
- return;
152
- }
153
- if (!useSingleOpBatching && queue.length === 0) {
154
- return;
155
- }
156
-
157
- if (useSingleOpBatching) {
158
- // Set up event listener for callbacks if it's not set up
159
- if (
160
- !globalEventEmitterGetValueListener ||
161
- !globalEventEmitterAnimationFinishedListener
162
- ) {
163
- setupGlobalEventEmitterListeners();
164
- }
165
- // Single op batching doesn't use callback functions, instead we
166
- // use RCTDeviceEventEmitter. This reduces overhead of sending lots of
167
- // JSI functions across to native code; but also, TM infrastructure currently
168
- // does not support packing a function into native arrays.
169
- NativeAnimatedModule?.queueAndExecuteBatchedOperations?.(singleOpQueue);
170
- singleOpQueue.length = 0;
171
- } else {
172
- Platform.OS === 'android' &&
173
- NativeAnimatedModule?.startOperationBatch?.();
174
-
175
- for (let q = 0, l = queue.length; q < l; q++) {
176
- queue[q]();
177
- }
178
- queue.length = 0;
179
- Platform.OS === 'android' &&
180
- NativeAnimatedModule?.finishOperationBatch?.();
181
- }
182
- },
183
- queueOperation: <Args: $ReadOnlyArray<mixed>, Fn: (...Args) => void>(
184
- fn: Fn,
185
- ...args: Args
186
- ): void => {
187
- if (useSingleOpBatching) {
188
- // Get the command ID from the queued function, and push that ID and any arguments needed to execute the operation
189
- // $FlowFixMe: surprise, fn is actually a number
190
- singleOpQueue.push(fn, ...args);
191
- return;
192
- }
193
-
194
- // If queueing is explicitly on, *or* the queue has not yet
195
- // been flushed, use the queue. This is to prevent operations
196
- // from being executed out of order.
197
- if (queueOperations || queue.length !== 0) {
198
- queue.push(() => fn(...args));
199
- } else {
200
- fn(...args);
201
- }
202
- },
203
- createAnimatedNode: function (tag: number, config: AnimatedNodeConfig): void {
204
- invariant(nativeOps, 'Native animated module is not available');
205
- API.queueOperation(nativeOps.createAnimatedNode, tag, config);
206
- },
207
- updateAnimatedNodeConfig: function (
208
- tag: number,
209
- config: AnimatedNodeConfig,
210
- ): void {
211
- invariant(nativeOps, 'Native animated module is not available');
212
- if (nativeOps.updateAnimatedNodeConfig) {
213
- API.queueOperation(nativeOps.updateAnimatedNodeConfig, tag, config);
214
- }
215
- },
216
- startListeningToAnimatedNodeValue: function (tag: number) {
217
- invariant(nativeOps, 'Native animated module is not available');
218
- API.queueOperation(nativeOps.startListeningToAnimatedNodeValue, tag);
219
- },
220
- stopListeningToAnimatedNodeValue: function (tag: number) {
221
- invariant(nativeOps, 'Native animated module is not available');
222
- API.queueOperation(nativeOps.stopListeningToAnimatedNodeValue, tag);
223
- },
224
- connectAnimatedNodes: function (parentTag: number, childTag: number): void {
225
- invariant(nativeOps, 'Native animated module is not available');
226
- API.queueOperation(nativeOps.connectAnimatedNodes, parentTag, childTag);
227
- },
228
- disconnectAnimatedNodes: function (
229
- parentTag: number,
230
- childTag: number,
231
- ): void {
232
- invariant(nativeOps, 'Native animated module is not available');
233
- API.queueOperation(nativeOps.disconnectAnimatedNodes, parentTag, childTag);
234
- },
235
- startAnimatingNode: function (
236
- animationId: number,
237
- nodeTag: number,
238
- config: AnimatingNodeConfig,
239
- endCallback: EndCallback,
240
- ): void {
241
- invariant(nativeOps, 'Native animated module is not available');
242
- if (useSingleOpBatching) {
243
- if (endCallback) {
244
- eventListenerAnimationFinishedCallbacks[animationId] = endCallback;
245
- }
246
- // $FlowFixMe
247
- API.queueOperation(
248
- // $FlowFixMe[incompatible-call]
249
- nativeOps.startAnimatingNode,
250
- animationId,
251
- nodeTag,
252
- config,
253
- );
254
- } else {
255
- API.queueOperation(
256
- nativeOps.startAnimatingNode,
257
- animationId,
258
- nodeTag,
259
- config,
260
- endCallback,
261
- );
262
- }
263
- },
264
- stopAnimation: function (animationId: number) {
265
- invariant(nativeOps, 'Native animated module is not available');
266
- API.queueOperation(nativeOps.stopAnimation, animationId);
267
- },
268
- setAnimatedNodeValue: function (nodeTag: number, value: number): void {
269
- invariant(nativeOps, 'Native animated module is not available');
270
- API.queueOperation(nativeOps.setAnimatedNodeValue, nodeTag, value);
271
- },
272
- setAnimatedNodeOffset: function (nodeTag: number, offset: number): void {
273
- invariant(nativeOps, 'Native animated module is not available');
274
- API.queueOperation(nativeOps.setAnimatedNodeOffset, nodeTag, offset);
275
- },
276
- flattenAnimatedNodeOffset: function (nodeTag: number): void {
277
- invariant(nativeOps, 'Native animated module is not available');
278
- API.queueOperation(nativeOps.flattenAnimatedNodeOffset, nodeTag);
279
- },
280
- extractAnimatedNodeOffset: function (nodeTag: number): void {
281
- invariant(nativeOps, 'Native animated module is not available');
282
- API.queueOperation(nativeOps.extractAnimatedNodeOffset, nodeTag);
283
- },
284
- connectAnimatedNodeToView: function (nodeTag: number, viewTag: number): void {
285
- invariant(nativeOps, 'Native animated module is not available');
286
- API.queueOperation(nativeOps.connectAnimatedNodeToView, nodeTag, viewTag);
287
- },
288
- disconnectAnimatedNodeFromView: function (
289
- nodeTag: number,
290
- viewTag: number,
291
- ): void {
292
- invariant(nativeOps, 'Native animated module is not available');
293
- API.queueOperation(
294
- nativeOps.disconnectAnimatedNodeFromView,
295
- nodeTag,
296
- viewTag,
297
- );
298
- },
299
- restoreDefaultValues: function (nodeTag: number): void {
300
- invariant(nativeOps, 'Native animated module is not available');
301
- // Backwards compat with older native runtimes, can be removed later.
302
- if (nativeOps.restoreDefaultValues != null) {
303
- API.queueOperation(nativeOps.restoreDefaultValues, nodeTag);
304
- }
305
- },
306
- dropAnimatedNode: function (tag: number): void {
307
- invariant(nativeOps, 'Native animated module is not available');
308
- API.queueOperation(nativeOps.dropAnimatedNode, tag);
309
- },
310
- addAnimatedEventToView: function (
311
- viewTag: number,
312
- eventName: string,
313
- eventMapping: EventMapping,
314
- ) {
315
- invariant(nativeOps, 'Native animated module is not available');
316
- API.queueOperation(
317
- nativeOps.addAnimatedEventToView,
318
- viewTag,
319
- eventName,
320
- eventMapping,
321
- );
322
- },
323
- removeAnimatedEventFromView(
324
- viewTag: number,
325
- eventName: string,
326
- animatedNodeTag: number,
327
- ) {
328
- invariant(nativeOps, 'Native animated module is not available');
329
- API.queueOperation(
330
- nativeOps.removeAnimatedEventFromView,
331
- viewTag,
332
- eventName,
333
- animatedNodeTag,
334
- );
335
- },
336
- };
337
-
338
- function setupGlobalEventEmitterListeners() {
339
- globalEventEmitterGetValueListener = RCTDeviceEventEmitter.addListener(
340
- 'onNativeAnimatedModuleGetValue',
341
- function (params) {
342
- const {tag} = params;
343
- const callback = eventListenerGetValueCallbacks[tag];
344
- if (!callback) {
345
- return;
346
- }
347
- callback(params.value);
348
- delete eventListenerGetValueCallbacks[tag];
349
- },
350
- );
351
- globalEventEmitterAnimationFinishedListener =
352
- RCTDeviceEventEmitter.addListener(
353
- 'onNativeAnimatedModuleAnimationFinished',
354
- function (params) {
355
- const {animationId} = params;
356
- const callback = eventListenerAnimationFinishedCallbacks[animationId];
357
- if (!callback) {
358
- return;
359
- }
360
- callback(params);
361
- delete eventListenerAnimationFinishedCallbacks[animationId];
362
- },
363
- );
364
- }
365
-
366
- /**
367
- * Styles allowed by the native animated implementation.
368
- *
369
- * In general native animated implementation should support any numeric or color property that
370
- * doesn't need to be updated through the shadow view hierarchy (all non-layout properties).
371
- */
372
- const SUPPORTED_COLOR_STYLES = {
373
- backgroundColor: true,
374
- borderBottomColor: true,
375
- borderColor: true,
376
- borderEndColor: true,
377
- borderLeftColor: true,
378
- borderRightColor: true,
379
- borderStartColor: true,
380
- borderTopColor: true,
381
- color: true,
382
- tintColor: true,
383
- };
384
-
385
- const SUPPORTED_STYLES = {
386
- ...SUPPORTED_COLOR_STYLES,
387
- borderBottomEndRadius: true,
388
- borderBottomLeftRadius: true,
389
- borderBottomRightRadius: true,
390
- borderBottomStartRadius: true,
391
- borderEndEndRadius: true,
392
- borderEndStartRadius: true,
393
- borderRadius: true,
394
- borderTopEndRadius: true,
395
- borderTopLeftRadius: true,
396
- borderTopRightRadius: true,
397
- borderTopStartRadius: true,
398
- borderStartEndRadius: true,
399
- borderStartStartRadius: true,
400
- elevation: true,
401
- opacity: true,
402
- transform: true,
403
- zIndex: true,
404
- /* ios styles */
405
- shadowOpacity: true,
406
- shadowRadius: true,
407
- /* legacy android transform properties */
408
- scaleX: true,
409
- scaleY: true,
410
- translateX: true,
411
- translateY: true,
412
- };
413
-
414
- const SUPPORTED_TRANSFORMS = {
415
- translateX: true,
416
- translateY: true,
417
- scale: true,
418
- scaleX: true,
419
- scaleY: true,
420
- rotate: true,
421
- rotateX: true,
422
- rotateY: true,
423
- rotateZ: true,
424
- perspective: true,
425
- };
426
-
427
- const SUPPORTED_INTERPOLATION_PARAMS = {
428
- inputRange: true,
429
- outputRange: true,
430
- extrapolate: true,
431
- extrapolateRight: true,
432
- extrapolateLeft: true,
433
- };
434
-
435
- function addWhitelistedStyleProp(prop: string): void {
436
- // $FlowFixMe[prop-missing]
437
- SUPPORTED_STYLES[prop] = true;
438
- }
439
-
440
- function addWhitelistedTransformProp(prop: string): void {
441
- // $FlowFixMe[prop-missing]
442
- SUPPORTED_TRANSFORMS[prop] = true;
443
- }
444
-
445
- function addWhitelistedInterpolationParam(param: string): void {
446
- // $FlowFixMe[prop-missing]
447
- SUPPORTED_INTERPOLATION_PARAMS[param] = true;
448
- }
449
-
450
- function isSupportedColorStyleProp(prop: string): boolean {
451
- return SUPPORTED_COLOR_STYLES.hasOwnProperty(prop);
452
- }
453
-
454
- function isSupportedStyleProp(prop: string): boolean {
455
- return SUPPORTED_STYLES.hasOwnProperty(prop);
456
- }
457
-
458
- function isSupportedTransformProp(prop: string): boolean {
459
- return SUPPORTED_TRANSFORMS.hasOwnProperty(prop);
460
- }
461
-
462
- function isSupportedInterpolationParam(param: string): boolean {
463
- return SUPPORTED_INTERPOLATION_PARAMS.hasOwnProperty(param);
464
- }
465
-
466
- function validateTransform(
467
- configs: Array<
468
- | {
469
- type: 'animated',
470
- property: string,
471
- nodeTag: ?number,
472
- ...
473
- }
474
- | {
475
- type: 'static',
476
- property: string,
477
- value: number | string,
478
- ...
479
- },
480
- >,
481
- ): void {
482
- configs.forEach(config => {
483
- if (!isSupportedTransformProp(config.property)) {
484
- throw new Error(
485
- `Property '${config.property}' is not supported by native animated module`,
486
- );
487
- }
488
- });
489
- }
490
-
491
- function validateStyles(styles: {[key: string]: ?number, ...}): void {
492
- for (const key in styles) {
493
- if (!isSupportedStyleProp(key)) {
494
- throw new Error(
495
- `Style property '${key}' is not supported by native animated module`,
496
- );
497
- }
498
- }
499
- }
500
-
501
- function validateInterpolation<OutputT: number | string>(
502
- config: InterpolationConfigType<OutputT>,
503
- ): void {
504
- for (const key in config) {
505
- if (!isSupportedInterpolationParam(key)) {
506
- throw new Error(
507
- `Interpolation property '${key}' is not supported by native animated module`,
508
- );
509
- }
510
- }
511
- }
512
-
513
- function generateNewNodeTag(): number {
514
- return __nativeAnimatedNodeTagCount++;
515
- }
516
-
517
- function generateNewAnimationId(): number {
518
- return __nativeAnimationIdCount++;
519
- }
520
-
521
- function assertNativeAnimatedModule(): void {
522
- invariant(NativeAnimatedModule, 'Native animated module is not available');
523
- }
524
-
525
- let _warnedMissingNativeAnimated = false;
526
-
527
- function shouldUseNativeDriver(
528
- config: $ReadOnly<{...AnimationConfig, ...}> | EventConfig,
529
- ): boolean {
530
- if (config.useNativeDriver == null) {
531
- console.warn(
532
- 'Animated: `useNativeDriver` was not specified. This is a required ' +
533
- 'option and must be explicitly set to `true` or `false`',
534
- );
535
- }
536
-
537
- if (config.useNativeDriver === true && !NativeAnimatedModule) {
538
- if (process.env.NODE_ENV !== 'test') {
539
- if (!_warnedMissingNativeAnimated) {
540
- console.warn(
541
- 'Animated: `useNativeDriver` is not supported because the native ' +
542
- 'animated module is missing. Falling back to JS-based animation. To ' +
543
- 'resolve this, add `RCTAnimation` module to this app, or remove ' +
544
- '`useNativeDriver`. ' +
545
- 'Make sure to run `bundle exec pod install` first. Read more about autolinking: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md',
546
- );
547
- _warnedMissingNativeAnimated = true;
548
- }
549
- }
550
- return false;
551
- }
552
-
553
- return config.useNativeDriver || false;
554
- }
555
-
556
- function transformDataType(value: number | string): number | string {
557
- // Change the string type to number type so we can reuse the same logic in
558
- // iOS and Android platform
559
- if (typeof value !== 'string') {
560
- return value;
561
- }
562
- if (/deg$/.test(value)) {
563
- const degrees = parseFloat(value) || 0;
564
- const radians = (degrees * Math.PI) / 180.0;
565
- return radians;
566
- } else {
567
- return value;
568
- }
569
- }
570
-
571
- export default {
572
- API,
573
- isSupportedColorStyleProp,
574
- isSupportedStyleProp,
575
- isSupportedTransformProp,
576
- isSupportedInterpolationParam,
577
- addWhitelistedStyleProp,
578
- addWhitelistedTransformProp,
579
- addWhitelistedInterpolationParam,
580
- validateStyles,
581
- validateTransform,
582
- validateInterpolation,
583
- generateNewNodeTag,
584
- generateNewAnimationId,
585
- assertNativeAnimatedModule,
586
- shouldUseNativeDriver,
587
- transformDataType,
588
- // $FlowExpectedError[unsafe-getters-setters] - unsafe getter lint suppression
589
- // $FlowExpectedError[missing-type-arg] - unsafe getter lint suppression
590
- get nativeEventEmitter(): NativeEventEmitter {
591
- if (!nativeEventEmitter) {
592
- // $FlowFixMe[underconstrained-implicit-instantiation]
593
- nativeEventEmitter = new NativeEventEmitter(
594
- // T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
595
- // If you want to use the native module on other platforms, please remove this condition and test its behavior
596
- Platform.OS !== 'ios' ? null : NativeAnimatedModule,
597
- );
598
- }
599
- return nativeEventEmitter;
600
- },
601
- };