@office-iss/react-native-win32 0.75.2 → 0.76.0-preview.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/.eslintrc.js +11 -0
  2. package/.flowconfig +5 -4
  3. package/CHANGELOG.json +191 -47
  4. package/CHANGELOG.md +63 -28
  5. package/Libraries/Alert/Alert.js +3 -0
  6. package/Libraries/Animated/AnimatedEvent.js +1 -1
  7. package/Libraries/Animated/AnimatedImplementation.js +7 -7
  8. package/Libraries/Animated/NativeAnimatedAllowlist.js +111 -0
  9. package/Libraries/Animated/animations/Animation.js +11 -1
  10. package/Libraries/Animated/animations/DecayAnimation.js +1 -1
  11. package/Libraries/Animated/animations/SpringAnimation.js +1 -1
  12. package/Libraries/Animated/animations/TimingAnimation.js +2 -1
  13. package/Libraries/Animated/components/AnimatedScrollView.js +3 -2
  14. package/Libraries/Animated/createAnimatedComponent.js +10 -9
  15. package/Libraries/Animated/nodes/AnimatedColor.js +1 -1
  16. package/Libraries/Animated/nodes/AnimatedInterpolation.js +3 -2
  17. package/Libraries/Animated/nodes/AnimatedNode.js +42 -33
  18. package/Libraries/Animated/nodes/AnimatedObject.js +56 -50
  19. package/Libraries/Animated/nodes/AnimatedProps.js +77 -40
  20. package/Libraries/Animated/nodes/AnimatedStyle.js +103 -59
  21. package/Libraries/Animated/nodes/AnimatedTracking.js +1 -1
  22. package/Libraries/Animated/nodes/AnimatedTransform.js +102 -67
  23. package/Libraries/Animated/nodes/AnimatedValue.js +2 -1
  24. package/Libraries/Animated/nodes/AnimatedWithChildren.js +21 -22
  25. package/Libraries/Animated/useAnimatedProps.js +142 -7
  26. package/Libraries/BatchedBridge/NativeModules.js +2 -0
  27. package/Libraries/Blob/FileReader.js +1 -1
  28. package/Libraries/Blob/URL.js +2 -62
  29. package/Libraries/Blob/URLSearchParams.js +71 -0
  30. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +1 -1
  31. package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +17 -0
  32. package/Libraries/Components/RefreshControl/__mocks__/RefreshControlMock.js +1 -1
  33. package/Libraries/Components/ScrollView/ScrollView.js +131 -169
  34. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +3 -0
  35. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +1 -1
  36. package/Libraries/Components/StatusBar/StatusBar.js +3 -1
  37. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +10 -0
  38. package/Libraries/Components/TextInput/TextInput.d.ts +32 -2
  39. package/Libraries/Components/TextInput/TextInput.js +230 -94
  40. package/Libraries/Components/TextInput/TextInput.win32.js +230 -100
  41. package/Libraries/Components/View/ReactNativeStyleAttributes.js +23 -1
  42. package/Libraries/Components/View/ReactNativeViewAttributes.js +2 -0
  43. package/Libraries/Components/View/ReactNativeViewAttributes.win32.js +2 -0
  44. package/Libraries/Components/View/ViewAccessibility.d.ts +15 -0
  45. package/Libraries/Components/View/ViewNativeComponent.js +0 -1
  46. package/Libraries/Components/View/ViewPropTypes.js +14 -0
  47. package/Libraries/Components/View/ViewPropTypes.win32.js +14 -0
  48. package/Libraries/Core/ExceptionsManager.js +2 -0
  49. package/Libraries/Core/InitializeCore.js +3 -1
  50. package/Libraries/Core/ReactFiberErrorDialog.js +3 -0
  51. package/Libraries/Core/ReactNativeVersion.js +4 -4
  52. package/Libraries/Core/ReactNativeVersionCheck.win32.js +1 -1
  53. package/Libraries/Core/setUpDeveloperTools.js +5 -1
  54. package/Libraries/Core/setUpErrorHandling.js +7 -1
  55. package/Libraries/Core/setUpGlobals.js +1 -0
  56. package/Libraries/Core/setUpReactRefresh.js +0 -4
  57. package/Libraries/Image/AssetSourceResolver.js +28 -1
  58. package/Libraries/Image/Image.android.js +9 -14
  59. package/Libraries/Image/Image.ios.js +11 -22
  60. package/Libraries/Image/Image.win32.js +11 -24
  61. package/Libraries/Image/ImageBackground.js +1 -8
  62. package/Libraries/Image/ImageUtils.js +9 -9
  63. package/Libraries/Image/ImageViewNativeComponent.js +1 -0
  64. package/Libraries/Inspector/Inspector.js +3 -2
  65. package/Libraries/Inspector/Inspector.win32.js +3 -2
  66. package/Libraries/Inspector/InspectorPanel.js +16 -10
  67. package/Libraries/Inspector/NetworkOverlay.js +1 -1
  68. package/Libraries/Interaction/TaskQueue.js +1 -0
  69. package/Libraries/Lists/FlatList.js +1 -1
  70. package/Libraries/Lists/SectionList.js +2 -2
  71. package/Libraries/Lists/SectionListModern.js +3 -3
  72. package/Libraries/LogBox/Data/LogBoxData.js +24 -3
  73. package/Libraries/LogBox/LogBoxNotificationContainer.js +3 -2
  74. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +9 -8
  75. package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +9 -29
  76. package/Libraries/Modal/Modal.js +0 -1
  77. package/Libraries/NativeComponent/BaseViewConfig.android.js +9 -1
  78. package/Libraries/NativeComponent/BaseViewConfig.ios.js +17 -1
  79. package/Libraries/NativeComponent/BaseViewConfig.win32.js +17 -1
  80. package/Libraries/NativeComponent/NativeComponentRegistry.js +22 -22
  81. package/Libraries/NativeComponent/StaticViewConfigValidator.js +0 -21
  82. package/Libraries/Network/XMLHttpRequest.js +4 -2
  83. package/Libraries/ReactNative/AppContainer-dev.js +1 -5
  84. package/Libraries/ReactNative/AppContainer-prod.js +1 -5
  85. package/Libraries/ReactNative/AppContainer.js +0 -1
  86. package/Libraries/ReactNative/AppRegistry.js +0 -6
  87. package/Libraries/ReactNative/BridgelessUIManager.js +1 -0
  88. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +1 -1
  89. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +5 -5
  90. package/Libraries/ReactNative/RendererImplementation.js +26 -4
  91. package/Libraries/ReactNative/getNativeComponentAttributes.js +12 -0
  92. package/Libraries/ReactNative/renderApplication.js +0 -2
  93. package/Libraries/Renderer/shims/ReactNativeTypes.js +11 -4
  94. package/Libraries/StyleSheet/StyleSheet.js +1 -1
  95. package/Libraries/StyleSheet/StyleSheet.win32.js +1 -1
  96. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +152 -2
  97. package/Libraries/StyleSheet/StyleSheetTypes.js +60 -5
  98. package/Libraries/StyleSheet/processBackgroundImage.js +384 -0
  99. package/Libraries/StyleSheet/processBoxShadow.js +209 -0
  100. package/Libraries/StyleSheet/processFilter.js +231 -42
  101. package/Libraries/Text/Text.js +394 -196
  102. package/Libraries/Text/Text.win32.js +442 -229
  103. package/Libraries/Text/TextNativeComponent.js +2 -1
  104. package/Libraries/Text/TextNativeComponent.win32.js +1 -1
  105. package/Libraries/TurboModule/TurboModuleRegistry.js +13 -50
  106. package/Libraries/Types/CodegenTypes.js +3 -1
  107. package/Libraries/Utilities/Appearance.js +108 -84
  108. package/Libraries/Utilities/DevLoadingView.js +2 -4
  109. package/Libraries/Utilities/HMRClient.js +8 -6
  110. package/Libraries/Utilities/ReactNativeTestTools.js +1 -1
  111. package/Libraries/Utilities/createPerformanceLogger.js +0 -9
  112. package/Libraries/Utilities/stringifyViewConfig.js +22 -0
  113. package/Libraries/Utilities/useColorScheme.js +3 -3
  114. package/Libraries/WebSocket/WebSocket.js +1 -1
  115. package/Libraries/promiseRejectionTrackingOptions.js +1 -1
  116. package/Libraries/vendor/emitter/EventEmitter.js +6 -5
  117. package/flow/jest.js +2 -2
  118. package/index.js +3 -1
  119. package/index.win32.js +3 -1
  120. package/jest/mockComponent.js +4 -1
  121. package/jest/mockModal.js +1 -3
  122. package/jest/mockScrollView.js +1 -1
  123. package/jest/renderer.js +2 -2
  124. package/jest/setup.js +16 -13
  125. package/jest.config.js +1 -2
  126. package/overrides.json +22 -22
  127. package/package.json +32 -30
  128. package/src/private/animated/NativeAnimatedHelper.js +438 -0
  129. package/src/private/animated/NativeAnimatedHelper.win32.js +440 -0
  130. package/src/private/animated/NativeAnimatedValidation.js +64 -0
  131. package/src/private/components/HScrollViewNativeComponents.js +56 -0
  132. package/src/private/components/SafeAreaView_INTERNAL_DO_NOT_USE.js +29 -0
  133. package/src/private/components/VScrollViewNativeComponents.js +48 -0
  134. package/src/private/components/useSyncOnScroll.js +48 -0
  135. package/src/private/featureflags/ReactNativeFeatureFlags.js +166 -16
  136. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +29 -5
  137. package/src/private/fusebox/FuseboxSessionObserver.js +42 -0
  138. package/{Libraries/Core → src/private/renderer/errorhandling}/ErrorHandlers.js +14 -4
  139. package/src/private/setup/setUpDOM.js +28 -0
  140. package/src/private/setup/setUpIntersectionObserver.js +27 -0
  141. package/src/private/setup/setUpMutationObserver.js +26 -0
  142. package/src/private/setup/setUpPerformanceObserver.js +64 -0
  143. package/src/private/specs/modules/NativeAppearance.js +3 -3
  144. package/src/private/specs/modules/NativeLinkingManager.js +1 -1
  145. package/src/private/specs/modules/NativePlatformConstantsWin.js +7 -0
  146. package/src/private/specs/modules/NativeSampleTurboModule.js +14 -1
  147. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +6 -4
  148. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserver.js +5 -3
  149. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserverEntry.js +3 -3
  150. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserverManager.js +14 -17
  151. package/src/private/{specs/modules → webapis/intersectionobserver/specs}/NativeIntersectionObserver.js +2 -2
  152. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver/specs}/__mocks__/NativeIntersectionObserver.js +4 -4
  153. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationObserver.js +5 -3
  154. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationObserverManager.js +24 -15
  155. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationRecord.js +4 -6
  156. package/src/private/{specs/modules → webapis/mutationobserver/specs}/NativeMutationObserver.js +2 -2
  157. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver/specs}/__mocks__/NativeMutationObserver.js +5 -5
  158. package/src/private/webapis/performance/{EventCounts.js → EventTiming.js} +65 -3
  159. package/src/private/webapis/performance/LongTasks.js +39 -0
  160. package/src/private/webapis/performance/Performance.js +22 -9
  161. package/src/private/webapis/performance/PerformanceEntry.js +36 -18
  162. package/src/private/webapis/performance/PerformanceObserver.js +29 -43
  163. package/src/private/webapis/performance/RawPerformanceEntry.js +24 -1
  164. package/src/private/webapis/performance/UserTiming.js +17 -12
  165. package/src/private/webapis/performance/specs/NativePerformanceObserver.js +1 -1
  166. package/src-win/Libraries/Components/View/ViewAccessibility.d.ts +15 -0
  167. package/types/experimental.d.ts +12 -98
  168. package/Libraries/Animated/NativeAnimatedHelper.js +0 -615
  169. package/Libraries/Animated/NativeAnimatedHelper.win32.js +0 -617
  170. package/Libraries/Core/setUpIntersectionObserver.js +0 -16
  171. package/Libraries/Core/setUpMutationObserver.js +0 -16
  172. package/Libraries/Core/setUpPerformanceObserver.js +0 -18
  173. package/Libraries/IntersectionObserver/NativeIntersectionObserver.js +0 -13
  174. package/Libraries/MutationObserver/NativeMutationObserver.js +0 -13
  175. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +0 -135
  176. package/src/private/core/setUpDOM.js +0 -18
  177. package/src/private/webapis/performance/PerformanceEventTiming.js +0 -55
  178. /package/src/private/{core → styles}/composeStyles.js +0 -0
@@ -0,0 +1,438 @@
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 '../../../Libraries/vendor/emitter/EventEmitter';
12
+ import type {EventConfig} from '../../../Libraries/Animated/AnimatedEvent';
13
+ import type {
14
+ AnimationConfig,
15
+ EndCallback,
16
+ } from '../../../Libraries/Animated/animations/Animation';
17
+ import type {
18
+ AnimatedNodeConfig,
19
+ EventMapping,
20
+ } from '../../../Libraries/Animated/NativeAnimatedModule';
21
+
22
+ import * as ReactNativeFeatureFlags from '../featureflags/ReactNativeFeatureFlags';
23
+ import NativeEventEmitter from '../../../Libraries/EventEmitter/NativeEventEmitter';
24
+ import RCTDeviceEventEmitter from '../../../Libraries/EventEmitter/RCTDeviceEventEmitter';
25
+ import Platform from '../../../Libraries/Utilities/Platform';
26
+ import NativeAnimatedNonTurboModule from '../../../Libraries/Animated/NativeAnimatedModule';
27
+ import NativeAnimatedTurboModule from '../../../Libraries/Animated/NativeAnimatedTurboModule';
28
+ import invariant from 'invariant';
29
+ import nullthrows from 'nullthrows';
30
+
31
+ // TODO T69437152 @petetheheat - Delete this fork when Fabric ships to 100%.
32
+ const NativeAnimatedModule: typeof NativeAnimatedTurboModule =
33
+ NativeAnimatedNonTurboModule ?? NativeAnimatedTurboModule;
34
+
35
+ let __nativeAnimatedNodeTagCount = 1; /* used for animated nodes */
36
+ let __nativeAnimationIdCount = 1; /* used for started animations */
37
+
38
+ let nativeEventEmitter;
39
+
40
+ let waitingForQueuedOperations = new Set<string>();
41
+ let queueOperations = false;
42
+ let queue: Array<() => void> = [];
43
+ let singleOpQueue: Array<mixed> = [];
44
+
45
+ const isSingleOpBatching =
46
+ Platform.OS === 'android' &&
47
+ NativeAnimatedModule?.queueAndExecuteBatchedOperations != null &&
48
+ ReactNativeFeatureFlags.animatedShouldUseSingleOp();
49
+ let flushQueueTimeout = null;
50
+
51
+ const eventListenerGetValueCallbacks: {
52
+ [number]: (value: number) => void,
53
+ } = {};
54
+ const eventListenerAnimationFinishedCallbacks: {
55
+ [number]: EndCallback,
56
+ } = {};
57
+ let globalEventEmitterGetValueListener: ?EventSubscription = null;
58
+ let globalEventEmitterAnimationFinishedListener: ?EventSubscription = null;
59
+
60
+ function createNativeOperations(): $NonMaybeType<typeof NativeAnimatedModule> {
61
+ const methodNames = [
62
+ 'createAnimatedNode', // 1
63
+ 'updateAnimatedNodeConfig', // 2
64
+ 'getValue', // 3
65
+ 'startListeningToAnimatedNodeValue', // 4
66
+ 'stopListeningToAnimatedNodeValue', // 5
67
+ 'connectAnimatedNodes', // 6
68
+ 'disconnectAnimatedNodes', // 7
69
+ 'startAnimatingNode', // 8
70
+ 'stopAnimation', // 9
71
+ 'setAnimatedNodeValue', // 10
72
+ 'setAnimatedNodeOffset', // 11
73
+ 'flattenAnimatedNodeOffset', // 12
74
+ 'extractAnimatedNodeOffset', // 13
75
+ 'connectAnimatedNodeToView', // 14
76
+ 'disconnectAnimatedNodeFromView', // 15
77
+ 'restoreDefaultValues', // 16
78
+ 'dropAnimatedNode', // 17
79
+ 'addAnimatedEventToView', // 18
80
+ 'removeAnimatedEventFromView', // 19
81
+ 'addListener', // 20
82
+ 'removeListener', // 21
83
+ ];
84
+ const nativeOperations: {
85
+ [$Values<typeof methodNames>]: (...$ReadOnlyArray<mixed>) => void,
86
+ } = {};
87
+ if (isSingleOpBatching) {
88
+ for (let ii = 0, length = methodNames.length; ii < length; ii++) {
89
+ const methodName = methodNames[ii];
90
+ const operationID = ii + 1;
91
+ nativeOperations[methodName] = (...args) => {
92
+ // `singleOpQueue` is a flat array of operation IDs and arguments, which
93
+ // is possible because # arguments is fixed for each operation. For more
94
+ // details, see `NativeAnimatedModule.queueAndExecuteBatchedOperations`.
95
+ singleOpQueue.push(operationID, ...args);
96
+ };
97
+ }
98
+ } else {
99
+ for (let ii = 0, length = methodNames.length; ii < length; ii++) {
100
+ const methodName = methodNames[ii];
101
+ nativeOperations[methodName] = (...args) => {
102
+ const method = nullthrows(NativeAnimatedModule)[methodName];
103
+ // If queueing is explicitly on, *or* the queue has not yet
104
+ // been flushed, use the queue. This is to prevent operations
105
+ // from being executed out of order.
106
+ if (queueOperations || queue.length !== 0) {
107
+ // $FlowExpectedError[incompatible-call] - Dynamism.
108
+ queue.push(() => method(...args));
109
+ } else {
110
+ // $FlowExpectedError[incompatible-call] - Dynamism.
111
+ method(...args);
112
+ }
113
+ };
114
+ }
115
+ }
116
+ // $FlowExpectedError[incompatible-return] - Dynamism.
117
+ return nativeOperations;
118
+ }
119
+
120
+ const NativeOperations = createNativeOperations();
121
+
122
+ /**
123
+ * Wrappers around NativeAnimatedModule to provide flow and autocomplete support for
124
+ * the native module methods, and automatic queue management on Android
125
+ */
126
+ const API = {
127
+ getValue: (isSingleOpBatching
128
+ ? (tag, saveValueCallback) => {
129
+ if (saveValueCallback) {
130
+ eventListenerGetValueCallbacks[tag] = saveValueCallback;
131
+ }
132
+ /* $FlowExpectedError[incompatible-call] - `saveValueCallback` is handled
133
+ differently when `isSingleOpBatching` is enabled. */
134
+ NativeOperations.getValue(tag);
135
+ }
136
+ : (tag, saveValueCallback) => {
137
+ NativeOperations.getValue(tag, saveValueCallback);
138
+ }) as $NonMaybeType<typeof NativeAnimatedModule>['getValue'],
139
+
140
+ setWaitingForIdentifier(id: string): void {
141
+ waitingForQueuedOperations.add(id);
142
+ queueOperations = true;
143
+ if (
144
+ ReactNativeFeatureFlags.animatedShouldDebounceQueueFlush() &&
145
+ flushQueueTimeout
146
+ ) {
147
+ clearTimeout(flushQueueTimeout);
148
+ }
149
+ },
150
+
151
+ unsetWaitingForIdentifier(id: string): void {
152
+ waitingForQueuedOperations.delete(id);
153
+
154
+ if (waitingForQueuedOperations.size === 0) {
155
+ queueOperations = false;
156
+ API.disableQueue();
157
+ }
158
+ },
159
+
160
+ disableQueue(): void {
161
+ invariant(NativeAnimatedModule, 'Native animated module is not available');
162
+
163
+ if (ReactNativeFeatureFlags.animatedShouldDebounceQueueFlush()) {
164
+ const prevTimeout = flushQueueTimeout;
165
+ clearImmediate(prevTimeout);
166
+ flushQueueTimeout = setImmediate(API.flushQueue);
167
+ } else {
168
+ API.flushQueue();
169
+ }
170
+ },
171
+
172
+ flushQueue: (isSingleOpBatching
173
+ ? (): void => {
174
+ // TODO: (T136971132)
175
+ invariant(
176
+ NativeAnimatedModule || process.env.NODE_ENV === 'test',
177
+ 'Native animated module is not available',
178
+ );
179
+ flushQueueTimeout = null;
180
+
181
+ if (singleOpQueue.length === 0) {
182
+ return;
183
+ }
184
+
185
+ // Set up event listener for callbacks if it's not set up
186
+ ensureGlobalEventEmitterListeners();
187
+
188
+ // Single op batching doesn't use callback functions, instead we
189
+ // use RCTDeviceEventEmitter. This reduces overhead of sending lots of
190
+ // JSI functions across to native code; but also, TM infrastructure currently
191
+ // does not support packing a function into native arrays.
192
+ NativeAnimatedModule?.queueAndExecuteBatchedOperations?.(singleOpQueue);
193
+ singleOpQueue.length = 0;
194
+ }
195
+ : (): void => {
196
+ // TODO: (T136971132)
197
+ invariant(
198
+ NativeAnimatedModule || process.env.NODE_ENV === 'test',
199
+ 'Native animated module is not available',
200
+ );
201
+ flushQueueTimeout = null;
202
+
203
+ if (queue.length === 0) {
204
+ return;
205
+ }
206
+
207
+ if (Platform.OS === 'android') {
208
+ NativeAnimatedModule?.startOperationBatch?.();
209
+ }
210
+
211
+ for (let q = 0, l = queue.length; q < l; q++) {
212
+ queue[q]();
213
+ }
214
+ queue.length = 0;
215
+
216
+ if (Platform.OS === 'android') {
217
+ NativeAnimatedModule?.finishOperationBatch?.();
218
+ }
219
+ }) as () => void,
220
+
221
+ createAnimatedNode(tag: number, config: AnimatedNodeConfig): void {
222
+ NativeOperations.createAnimatedNode(tag, config);
223
+ },
224
+
225
+ updateAnimatedNodeConfig(tag: number, config: AnimatedNodeConfig): void {
226
+ NativeOperations.updateAnimatedNodeConfig?.(tag, config);
227
+ },
228
+
229
+ startListeningToAnimatedNodeValue(tag: number): void {
230
+ NativeOperations.startListeningToAnimatedNodeValue(tag);
231
+ },
232
+
233
+ stopListeningToAnimatedNodeValue(tag: number): void {
234
+ NativeOperations.stopListeningToAnimatedNodeValue(tag);
235
+ },
236
+
237
+ connectAnimatedNodes(parentTag: number, childTag: number): void {
238
+ NativeOperations.connectAnimatedNodes(parentTag, childTag);
239
+ },
240
+
241
+ disconnectAnimatedNodes(parentTag: number, childTag: number): void {
242
+ NativeOperations.disconnectAnimatedNodes(parentTag, childTag);
243
+ },
244
+
245
+ startAnimatingNode: (isSingleOpBatching
246
+ ? (animationId, nodeTag, config, endCallback) => {
247
+ if (endCallback) {
248
+ eventListenerAnimationFinishedCallbacks[animationId] = endCallback;
249
+ }
250
+ /* $FlowExpectedError[incompatible-call] - `endCallback` is handled
251
+ differently when `isSingleOpBatching` is enabled. */
252
+ NativeOperations.startAnimatingNode(animationId, nodeTag, config);
253
+ }
254
+ : (animationId, nodeTag, config, endCallback) => {
255
+ NativeOperations.startAnimatingNode(
256
+ animationId,
257
+ nodeTag,
258
+ config,
259
+ endCallback,
260
+ );
261
+ }) as $NonMaybeType<typeof NativeAnimatedModule>['startAnimatingNode'],
262
+
263
+ stopAnimation(animationId: number) {
264
+ NativeOperations.stopAnimation(animationId);
265
+ },
266
+
267
+ setAnimatedNodeValue(nodeTag: number, value: number): void {
268
+ NativeOperations.setAnimatedNodeValue(nodeTag, value);
269
+ },
270
+
271
+ setAnimatedNodeOffset(nodeTag: number, offset: number): void {
272
+ NativeOperations.setAnimatedNodeOffset(nodeTag, offset);
273
+ },
274
+
275
+ flattenAnimatedNodeOffset(nodeTag: number): void {
276
+ NativeOperations.flattenAnimatedNodeOffset(nodeTag);
277
+ },
278
+
279
+ extractAnimatedNodeOffset(nodeTag: number): void {
280
+ NativeOperations.extractAnimatedNodeOffset(nodeTag);
281
+ },
282
+
283
+ connectAnimatedNodeToView(nodeTag: number, viewTag: number): void {
284
+ NativeOperations.connectAnimatedNodeToView(nodeTag, viewTag);
285
+ },
286
+
287
+ disconnectAnimatedNodeFromView(nodeTag: number, viewTag: number): void {
288
+ NativeOperations.disconnectAnimatedNodeFromView(nodeTag, viewTag);
289
+ },
290
+
291
+ restoreDefaultValues(nodeTag: number): void {
292
+ NativeOperations.restoreDefaultValues?.(nodeTag);
293
+ },
294
+
295
+ dropAnimatedNode(tag: number): void {
296
+ NativeOperations.dropAnimatedNode(tag);
297
+ },
298
+
299
+ addAnimatedEventToView(
300
+ viewTag: number,
301
+ eventName: string,
302
+ eventMapping: EventMapping,
303
+ ) {
304
+ NativeOperations.addAnimatedEventToView(viewTag, eventName, eventMapping);
305
+ },
306
+
307
+ removeAnimatedEventFromView(
308
+ viewTag: number,
309
+ eventName: string,
310
+ animatedNodeTag: number,
311
+ ) {
312
+ NativeOperations.removeAnimatedEventFromView(
313
+ viewTag,
314
+ eventName,
315
+ animatedNodeTag,
316
+ );
317
+ },
318
+ };
319
+
320
+ function ensureGlobalEventEmitterListeners() {
321
+ if (
322
+ globalEventEmitterGetValueListener &&
323
+ globalEventEmitterAnimationFinishedListener
324
+ ) {
325
+ return;
326
+ }
327
+ globalEventEmitterGetValueListener = RCTDeviceEventEmitter.addListener(
328
+ 'onNativeAnimatedModuleGetValue',
329
+ params => {
330
+ const {tag} = params;
331
+ const callback = eventListenerGetValueCallbacks[tag];
332
+ if (!callback) {
333
+ return;
334
+ }
335
+ callback(params.value);
336
+ delete eventListenerGetValueCallbacks[tag];
337
+ },
338
+ );
339
+ globalEventEmitterAnimationFinishedListener =
340
+ RCTDeviceEventEmitter.addListener(
341
+ 'onNativeAnimatedModuleAnimationFinished',
342
+ params => {
343
+ // TODO: remove Array.isArray once native changes have propagated
344
+ const animations = Array.isArray(params) ? params : [params];
345
+ for (const animation of animations) {
346
+ const {animationId} = animation;
347
+ const callback = eventListenerAnimationFinishedCallbacks[animationId];
348
+ if (callback) {
349
+ callback(animation);
350
+ delete eventListenerAnimationFinishedCallbacks[animationId];
351
+ }
352
+ }
353
+ },
354
+ );
355
+ }
356
+
357
+ function generateNewNodeTag(): number {
358
+ return __nativeAnimatedNodeTagCount++;
359
+ }
360
+
361
+ function generateNewAnimationId(): number {
362
+ return __nativeAnimationIdCount++;
363
+ }
364
+
365
+ function assertNativeAnimatedModule(): void {
366
+ invariant(NativeAnimatedModule, 'Native animated module is not available');
367
+ }
368
+
369
+ let _warnedMissingNativeAnimated = false;
370
+
371
+ function shouldUseNativeDriver(
372
+ config: $ReadOnly<{...AnimationConfig, ...}> | EventConfig,
373
+ ): boolean {
374
+ if (config.useNativeDriver == null) {
375
+ console.warn(
376
+ 'Animated: `useNativeDriver` was not specified. This is a required ' +
377
+ 'option and must be explicitly set to `true` or `false`',
378
+ );
379
+ }
380
+
381
+ if (config.useNativeDriver === true && !NativeAnimatedModule) {
382
+ if (process.env.NODE_ENV !== 'test') {
383
+ if (!_warnedMissingNativeAnimated) {
384
+ console.warn(
385
+ 'Animated: `useNativeDriver` is not supported because the native ' +
386
+ 'animated module is missing. Falling back to JS-based animation. To ' +
387
+ 'resolve this, add `RCTAnimation` module to this app, or remove ' +
388
+ '`useNativeDriver`. ' +
389
+ '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',
390
+ );
391
+ _warnedMissingNativeAnimated = true;
392
+ }
393
+ }
394
+ return false;
395
+ }
396
+
397
+ return config.useNativeDriver || false;
398
+ }
399
+
400
+ function transformDataType(value: number | string): number | string {
401
+ // Change the string type to number type so we can reuse the same logic in
402
+ // iOS and Android platform
403
+ if (typeof value !== 'string') {
404
+ return value;
405
+ }
406
+
407
+ // Normalize degrees and radians to a number expressed in radians
408
+ if (value.endsWith('deg')) {
409
+ const degrees = parseFloat(value) || 0;
410
+ return (degrees * Math.PI) / 180.0;
411
+ } else if (value.endsWith('rad')) {
412
+ return parseFloat(value) || 0;
413
+ } else {
414
+ return value;
415
+ }
416
+ }
417
+
418
+ export default {
419
+ API,
420
+ generateNewNodeTag,
421
+ generateNewAnimationId,
422
+ assertNativeAnimatedModule,
423
+ shouldUseNativeDriver,
424
+ transformDataType,
425
+ // $FlowExpectedError[unsafe-getters-setters] - unsafe getter lint suppression
426
+ // $FlowExpectedError[missing-type-arg] - unsafe getter lint suppression
427
+ get nativeEventEmitter(): NativeEventEmitter {
428
+ if (!nativeEventEmitter) {
429
+ // $FlowFixMe[underconstrained-implicit-instantiation]
430
+ nativeEventEmitter = new NativeEventEmitter(
431
+ // 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
432
+ // If you want to use the native module on other platforms, please remove this condition and test its behavior
433
+ Platform.OS !== 'ios' ? null : NativeAnimatedModule,
434
+ );
435
+ }
436
+ return nativeEventEmitter;
437
+ },
438
+ };