@office-iss/react-native-win32 0.75.1 → 0.76.0-preview.1

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 (174) hide show
  1. package/.eslintrc.js +11 -0
  2. package/.flowconfig +5 -4
  3. package/CHANGELOG.json +172 -40
  4. package/CHANGELOG.md +57 -24
  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/RefreshControl/__mocks__/RefreshControlMock.js +1 -1
  32. package/Libraries/Components/ScrollView/ScrollView.js +131 -169
  33. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +1 -1
  34. package/Libraries/Components/StatusBar/StatusBar.js +3 -1
  35. package/Libraries/Components/TextInput/TextInput.d.ts +32 -2
  36. package/Libraries/Components/TextInput/TextInput.js +230 -94
  37. package/Libraries/Components/TextInput/TextInput.win32.js +230 -100
  38. package/Libraries/Components/View/ReactNativeStyleAttributes.js +22 -0
  39. package/Libraries/Components/View/ReactNativeViewAttributes.js +2 -0
  40. package/Libraries/Components/View/ReactNativeViewAttributes.win32.js +2 -0
  41. package/Libraries/Components/View/ViewAccessibility.d.ts +15 -0
  42. package/Libraries/Components/View/ViewNativeComponent.js +0 -1
  43. package/Libraries/Components/View/ViewPropTypes.js +14 -0
  44. package/Libraries/Components/View/ViewPropTypes.win32.js +14 -0
  45. package/Libraries/Core/ExceptionsManager.js +2 -0
  46. package/Libraries/Core/InitializeCore.js +3 -1
  47. package/Libraries/Core/ReactFiberErrorDialog.js +3 -0
  48. package/Libraries/Core/ReactNativeVersion.js +4 -4
  49. package/Libraries/Core/ReactNativeVersionCheck.win32.js +1 -1
  50. package/Libraries/Core/setUpErrorHandling.js +7 -1
  51. package/Libraries/Core/setUpGlobals.js +1 -0
  52. package/Libraries/Core/setUpReactRefresh.js +0 -4
  53. package/Libraries/Image/AssetSourceResolver.js +28 -1
  54. package/Libraries/Image/Image.android.js +9 -14
  55. package/Libraries/Image/Image.ios.js +11 -22
  56. package/Libraries/Image/Image.win32.js +11 -24
  57. package/Libraries/Image/ImageBackground.js +1 -8
  58. package/Libraries/Image/ImageUtils.js +9 -9
  59. package/Libraries/Image/ImageViewNativeComponent.js +1 -0
  60. package/Libraries/Inspector/Inspector.js +3 -2
  61. package/Libraries/Inspector/Inspector.win32.js +3 -2
  62. package/Libraries/Inspector/InspectorPanel.js +16 -10
  63. package/Libraries/Inspector/NetworkOverlay.js +1 -1
  64. package/Libraries/Interaction/TaskQueue.js +1 -0
  65. package/Libraries/Lists/FlatList.js +1 -1
  66. package/Libraries/Lists/SectionList.js +2 -2
  67. package/Libraries/Lists/SectionListModern.js +3 -3
  68. package/Libraries/LogBox/Data/LogBoxData.js +24 -3
  69. package/Libraries/LogBox/LogBoxNotificationContainer.js +3 -2
  70. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +9 -8
  71. package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +9 -29
  72. package/Libraries/Modal/Modal.js +0 -1
  73. package/Libraries/NativeComponent/BaseViewConfig.android.js +8 -0
  74. package/Libraries/NativeComponent/BaseViewConfig.ios.js +7 -0
  75. package/Libraries/NativeComponent/BaseViewConfig.win32.js +7 -0
  76. package/Libraries/NativeComponent/NativeComponentRegistry.js +22 -22
  77. package/Libraries/NativeComponent/StaticViewConfigValidator.js +0 -21
  78. package/Libraries/Network/XMLHttpRequest.js +4 -2
  79. package/Libraries/ReactNative/AppContainer-dev.js +1 -5
  80. package/Libraries/ReactNative/AppContainer-prod.js +1 -5
  81. package/Libraries/ReactNative/AppContainer.js +0 -1
  82. package/Libraries/ReactNative/AppRegistry.js +0 -6
  83. package/Libraries/ReactNative/BridgelessUIManager.js +1 -0
  84. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +1 -1
  85. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +5 -5
  86. package/Libraries/ReactNative/RendererImplementation.js +26 -4
  87. package/Libraries/ReactNative/getNativeComponentAttributes.js +8 -0
  88. package/Libraries/ReactNative/renderApplication.js +0 -2
  89. package/Libraries/Renderer/shims/ReactNativeTypes.js +11 -4
  90. package/Libraries/StyleSheet/StyleSheet.js +1 -1
  91. package/Libraries/StyleSheet/StyleSheet.win32.js +1 -1
  92. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +74 -15
  93. package/Libraries/StyleSheet/StyleSheetTypes.js +60 -5
  94. package/Libraries/StyleSheet/processBackgroundImage.js +384 -0
  95. package/Libraries/StyleSheet/processBoxShadow.js +211 -0
  96. package/Libraries/StyleSheet/processFilter.js +231 -42
  97. package/Libraries/Text/Text.js +394 -196
  98. package/Libraries/Text/Text.win32.js +442 -229
  99. package/Libraries/Text/TextNativeComponent.js +2 -1
  100. package/Libraries/Text/TextNativeComponent.win32.js +1 -1
  101. package/Libraries/TurboModule/TurboModuleRegistry.js +13 -50
  102. package/Libraries/Types/CodegenTypes.js +3 -1
  103. package/Libraries/Utilities/Appearance.js +108 -84
  104. package/Libraries/Utilities/DevLoadingView.js +2 -4
  105. package/Libraries/Utilities/HMRClient.js +2 -1
  106. package/Libraries/Utilities/ReactNativeTestTools.js +1 -1
  107. package/Libraries/Utilities/createPerformanceLogger.js +0 -9
  108. package/Libraries/Utilities/stringifyViewConfig.js +22 -0
  109. package/Libraries/Utilities/useColorScheme.js +3 -3
  110. package/Libraries/WebSocket/WebSocket.js +1 -1
  111. package/Libraries/promiseRejectionTrackingOptions.js +1 -1
  112. package/Libraries/vendor/emitter/EventEmitter.js +6 -5
  113. package/flow/jest.js +2 -2
  114. package/index.js +3 -1
  115. package/index.win32.js +3 -1
  116. package/jest/mockComponent.js +4 -1
  117. package/jest/mockModal.js +1 -3
  118. package/jest/mockScrollView.js +1 -1
  119. package/jest/renderer.js +2 -2
  120. package/jest/setup.js +16 -13
  121. package/jest.config.js +1 -2
  122. package/overrides.json +22 -22
  123. package/package.json +27 -26
  124. package/src/private/animated/NativeAnimatedHelper.js +438 -0
  125. package/src/private/animated/NativeAnimatedHelper.win32.js +440 -0
  126. package/src/private/animated/NativeAnimatedValidation.js +64 -0
  127. package/src/private/components/HScrollViewNativeComponents.js +56 -0
  128. package/src/private/components/SafeAreaView_INTERNAL_DO_NOT_USE.js +27 -0
  129. package/src/private/components/VScrollViewNativeComponents.js +48 -0
  130. package/src/private/components/useSyncOnScroll.js +48 -0
  131. package/src/private/featureflags/ReactNativeFeatureFlags.js +166 -16
  132. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +29 -5
  133. package/src/private/fusebox/FuseboxSessionObserver.js +42 -0
  134. package/{Libraries/Core → src/private/renderer/errorhandling}/ErrorHandlers.js +14 -4
  135. package/src/private/setup/setUpDOM.js +28 -0
  136. package/src/private/setup/setUpIntersectionObserver.js +27 -0
  137. package/src/private/setup/setUpMutationObserver.js +26 -0
  138. package/src/private/setup/setUpPerformanceObserver.js +64 -0
  139. package/src/private/specs/modules/NativeAppearance.js +3 -3
  140. package/src/private/specs/modules/NativeLinkingManager.js +1 -1
  141. package/src/private/specs/modules/NativePlatformConstantsWin.js +7 -0
  142. package/src/private/specs/modules/NativeSampleTurboModule.js +14 -1
  143. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +6 -4
  144. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserver.js +5 -3
  145. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserverEntry.js +3 -3
  146. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserverManager.js +14 -17
  147. package/src/private/{specs/modules → webapis/intersectionobserver/specs}/NativeIntersectionObserver.js +2 -2
  148. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver/specs}/__mocks__/NativeIntersectionObserver.js +4 -4
  149. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationObserver.js +5 -3
  150. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationObserverManager.js +24 -15
  151. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationRecord.js +4 -6
  152. package/src/private/{specs/modules → webapis/mutationobserver/specs}/NativeMutationObserver.js +2 -2
  153. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver/specs}/__mocks__/NativeMutationObserver.js +5 -5
  154. package/src/private/webapis/performance/{EventCounts.js → EventTiming.js} +65 -3
  155. package/src/private/webapis/performance/LongTasks.js +39 -0
  156. package/src/private/webapis/performance/Performance.js +22 -9
  157. package/src/private/webapis/performance/PerformanceEntry.js +36 -18
  158. package/src/private/webapis/performance/PerformanceObserver.js +29 -43
  159. package/src/private/webapis/performance/RawPerformanceEntry.js +24 -1
  160. package/src/private/webapis/performance/UserTiming.js +17 -12
  161. package/src/private/webapis/performance/specs/NativePerformanceObserver.js +1 -1
  162. package/src-win/Libraries/Components/View/ViewAccessibility.d.ts +15 -0
  163. package/types/experimental.d.ts +20 -1
  164. package/Libraries/Animated/NativeAnimatedHelper.js +0 -615
  165. package/Libraries/Animated/NativeAnimatedHelper.win32.js +0 -617
  166. package/Libraries/Core/setUpIntersectionObserver.js +0 -16
  167. package/Libraries/Core/setUpMutationObserver.js +0 -16
  168. package/Libraries/Core/setUpPerformanceObserver.js +0 -18
  169. package/Libraries/IntersectionObserver/NativeIntersectionObserver.js +0 -13
  170. package/Libraries/MutationObserver/NativeMutationObserver.js +0 -13
  171. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +0 -135
  172. package/src/private/core/setUpDOM.js +0 -18
  173. package/src/private/webapis/performance/PerformanceEventTiming.js +0 -55
  174. /package/src/private/{core → styles}/composeStyles.js +0 -0
@@ -1,615 +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 '../vendor/emitter/EventEmitter';
12
- import type {EventConfig} from './AnimatedEvent';
13
- import type {AnimationConfig, EndCallback} from './animations/Animation';
14
- import type {
15
- AnimatedNodeConfig,
16
- AnimatingNodeConfig,
17
- EventMapping,
18
- } from './NativeAnimatedModule';
19
- import type {InterpolationConfigType} from './nodes/AnimatedInterpolation';
20
-
21
- import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';
22
- import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
23
- import RCTDeviceEventEmitter from '../EventEmitter/RCTDeviceEventEmitter';
24
- import Platform from '../Utilities/Platform';
25
- import NativeAnimatedNonTurboModule from './NativeAnimatedModule';
26
- import NativeAnimatedTurboModule from './NativeAnimatedTurboModule';
27
- import invariant from 'invariant';
28
-
29
- // TODO T69437152 @petetheheat - Delete this fork when Fabric ships to 100%.
30
- const NativeAnimatedModule =
31
- NativeAnimatedNonTurboModule ?? NativeAnimatedTurboModule;
32
-
33
- let __nativeAnimatedNodeTagCount = 1; /* used for animated nodes */
34
- let __nativeAnimationIdCount = 1; /* used for started animations */
35
-
36
- let nativeEventEmitter;
37
-
38
- let waitingForQueuedOperations = new Set<string>();
39
- let queueOperations = false;
40
- let queue: Array<() => void> = [];
41
- // $FlowFixMe
42
- let singleOpQueue: Array<any> = [];
43
-
44
- const useSingleOpBatching =
45
- Platform.OS === 'android' &&
46
- !!NativeAnimatedModule?.queueAndExecuteBatchedOperations &&
47
- ReactNativeFeatureFlags.animatedShouldUseSingleOp();
48
- let flushQueueTimeout = null;
49
-
50
- const eventListenerGetValueCallbacks: {
51
- [number]: (value: number) => void,
52
- } = {};
53
- const eventListenerAnimationFinishedCallbacks: {
54
- [number]: EndCallback,
55
- } = {};
56
- let globalEventEmitterGetValueListener: ?EventSubscription = null;
57
- let globalEventEmitterAnimationFinishedListener: ?EventSubscription = null;
58
-
59
- const nativeOps: ?typeof NativeAnimatedModule = useSingleOpBatching
60
- ? ((function () {
61
- const apis = [
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
- return apis.reduce<{[string]: number}>((acc, functionName, i) => {
85
- // 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).
86
- // $FlowFixMe[prop-missing]
87
- acc[functionName] = i + 1;
88
- return acc;
89
- }, {});
90
- })(): $FlowFixMe)
91
- : NativeAnimatedModule;
92
-
93
- /**
94
- * Wrappers around NativeAnimatedModule to provide flow and autocomplete support for
95
- * the native module methods, and automatic queue management on Android
96
- */
97
- const API = {
98
- getValue: function (
99
- tag: number,
100
- saveValueCallback: (value: number) => void,
101
- ): void {
102
- invariant(nativeOps, 'Native animated module is not available');
103
- if (useSingleOpBatching) {
104
- if (saveValueCallback) {
105
- eventListenerGetValueCallbacks[tag] = saveValueCallback;
106
- }
107
- // $FlowFixMe
108
- API.queueOperation(nativeOps.getValue, tag);
109
- } else {
110
- API.queueOperation(nativeOps.getValue, tag, saveValueCallback);
111
- }
112
- },
113
- setWaitingForIdentifier: function (id: string): void {
114
- waitingForQueuedOperations.add(id);
115
- queueOperations = true;
116
- if (
117
- ReactNativeFeatureFlags.animatedShouldDebounceQueueFlush() &&
118
- flushQueueTimeout
119
- ) {
120
- clearTimeout(flushQueueTimeout);
121
- }
122
- },
123
- unsetWaitingForIdentifier: function (id: string): void {
124
- waitingForQueuedOperations.delete(id);
125
-
126
- if (waitingForQueuedOperations.size === 0) {
127
- queueOperations = false;
128
- API.disableQueue();
129
- }
130
- },
131
- disableQueue: function (): void {
132
- invariant(nativeOps, 'Native animated module is not available');
133
-
134
- if (ReactNativeFeatureFlags.animatedShouldDebounceQueueFlush()) {
135
- const prevTimeout = flushQueueTimeout;
136
- clearImmediate(prevTimeout);
137
- flushQueueTimeout = setImmediate(API.flushQueue);
138
- } else {
139
- API.flushQueue();
140
- }
141
- },
142
- flushQueue: function (): void {
143
- // TODO: (T136971132)
144
- invariant(
145
- NativeAnimatedModule || process.env.NODE_ENV === 'test',
146
- 'Native animated module is not available',
147
- );
148
- flushQueueTimeout = null;
149
-
150
- // Early returns before calling any APIs
151
- if (useSingleOpBatching && singleOpQueue.length === 0) {
152
- return;
153
- }
154
- if (!useSingleOpBatching && queue.length === 0) {
155
- return;
156
- }
157
-
158
- if (useSingleOpBatching) {
159
- // Set up event listener for callbacks if it's not set up
160
- if (
161
- !globalEventEmitterGetValueListener ||
162
- !globalEventEmitterAnimationFinishedListener
163
- ) {
164
- setupGlobalEventEmitterListeners();
165
- }
166
- // Single op batching doesn't use callback functions, instead we
167
- // use RCTDeviceEventEmitter. This reduces overhead of sending lots of
168
- // JSI functions across to native code; but also, TM infrastructure currently
169
- // does not support packing a function into native arrays.
170
- NativeAnimatedModule?.queueAndExecuteBatchedOperations?.(singleOpQueue);
171
- singleOpQueue.length = 0;
172
- } else {
173
- Platform.OS === 'android' &&
174
- NativeAnimatedModule?.startOperationBatch?.();
175
-
176
- for (let q = 0, l = queue.length; q < l; q++) {
177
- queue[q]();
178
- }
179
- queue.length = 0;
180
- Platform.OS === 'android' &&
181
- NativeAnimatedModule?.finishOperationBatch?.();
182
- }
183
- },
184
- queueOperation: <Args: $ReadOnlyArray<mixed>, Fn: (...Args) => void>(
185
- fn: Fn,
186
- ...args: Args
187
- ): void => {
188
- if (useSingleOpBatching) {
189
- // Get the command ID from the queued function, and push that ID and any arguments needed to execute the operation
190
- // $FlowFixMe: surprise, fn is actually a number
191
- singleOpQueue.push(fn, ...args);
192
- return;
193
- }
194
-
195
- // If queueing is explicitly on, *or* the queue has not yet
196
- // been flushed, use the queue. This is to prevent operations
197
- // from being executed out of order.
198
- if (queueOperations || queue.length !== 0) {
199
- queue.push(() => fn(...args));
200
- } else {
201
- fn(...args);
202
- }
203
- },
204
- createAnimatedNode: function (tag: number, config: AnimatedNodeConfig): void {
205
- invariant(nativeOps, 'Native animated module is not available');
206
- API.queueOperation(nativeOps.createAnimatedNode, tag, config);
207
- },
208
- updateAnimatedNodeConfig: function (
209
- tag: number,
210
- config: AnimatedNodeConfig,
211
- ): void {
212
- invariant(nativeOps, 'Native animated module is not available');
213
- if (nativeOps.updateAnimatedNodeConfig) {
214
- API.queueOperation(nativeOps.updateAnimatedNodeConfig, tag, config);
215
- }
216
- },
217
- startListeningToAnimatedNodeValue: function (tag: number) {
218
- invariant(nativeOps, 'Native animated module is not available');
219
- API.queueOperation(nativeOps.startListeningToAnimatedNodeValue, tag);
220
- },
221
- stopListeningToAnimatedNodeValue: function (tag: number) {
222
- invariant(nativeOps, 'Native animated module is not available');
223
- API.queueOperation(nativeOps.stopListeningToAnimatedNodeValue, tag);
224
- },
225
- connectAnimatedNodes: function (parentTag: number, childTag: number): void {
226
- invariant(nativeOps, 'Native animated module is not available');
227
- API.queueOperation(nativeOps.connectAnimatedNodes, parentTag, childTag);
228
- },
229
- disconnectAnimatedNodes: function (
230
- parentTag: number,
231
- childTag: number,
232
- ): void {
233
- invariant(nativeOps, 'Native animated module is not available');
234
- API.queueOperation(nativeOps.disconnectAnimatedNodes, parentTag, childTag);
235
- },
236
- startAnimatingNode: function (
237
- animationId: number,
238
- nodeTag: number,
239
- config: AnimatingNodeConfig,
240
- endCallback: EndCallback,
241
- ): void {
242
- invariant(nativeOps, 'Native animated module is not available');
243
- if (useSingleOpBatching) {
244
- if (endCallback) {
245
- eventListenerAnimationFinishedCallbacks[animationId] = endCallback;
246
- }
247
- // $FlowFixMe
248
- API.queueOperation(
249
- // $FlowFixMe[incompatible-call]
250
- nativeOps.startAnimatingNode,
251
- animationId,
252
- nodeTag,
253
- config,
254
- );
255
- } else {
256
- API.queueOperation(
257
- nativeOps.startAnimatingNode,
258
- animationId,
259
- nodeTag,
260
- config,
261
- endCallback,
262
- );
263
- }
264
- },
265
- stopAnimation: function (animationId: number) {
266
- invariant(nativeOps, 'Native animated module is not available');
267
- API.queueOperation(nativeOps.stopAnimation, animationId);
268
- },
269
- setAnimatedNodeValue: function (nodeTag: number, value: number): void {
270
- invariant(nativeOps, 'Native animated module is not available');
271
- API.queueOperation(nativeOps.setAnimatedNodeValue, nodeTag, value);
272
- },
273
- setAnimatedNodeOffset: function (nodeTag: number, offset: number): void {
274
- invariant(nativeOps, 'Native animated module is not available');
275
- API.queueOperation(nativeOps.setAnimatedNodeOffset, nodeTag, offset);
276
- },
277
- flattenAnimatedNodeOffset: function (nodeTag: number): void {
278
- invariant(nativeOps, 'Native animated module is not available');
279
- API.queueOperation(nativeOps.flattenAnimatedNodeOffset, nodeTag);
280
- },
281
- extractAnimatedNodeOffset: function (nodeTag: number): void {
282
- invariant(nativeOps, 'Native animated module is not available');
283
- API.queueOperation(nativeOps.extractAnimatedNodeOffset, nodeTag);
284
- },
285
- connectAnimatedNodeToView: function (nodeTag: number, viewTag: number): void {
286
- invariant(nativeOps, 'Native animated module is not available');
287
- API.queueOperation(nativeOps.connectAnimatedNodeToView, nodeTag, viewTag);
288
- },
289
- disconnectAnimatedNodeFromView: function (
290
- nodeTag: number,
291
- viewTag: number,
292
- ): void {
293
- invariant(nativeOps, 'Native animated module is not available');
294
- API.queueOperation(
295
- nativeOps.disconnectAnimatedNodeFromView,
296
- nodeTag,
297
- viewTag,
298
- );
299
- },
300
- restoreDefaultValues: function (nodeTag: number): void {
301
- invariant(nativeOps, 'Native animated module is not available');
302
- // Backwards compat with older native runtimes, can be removed later.
303
- if (nativeOps.restoreDefaultValues != null) {
304
- API.queueOperation(nativeOps.restoreDefaultValues, nodeTag);
305
- }
306
- },
307
- dropAnimatedNode: function (tag: number): void {
308
- invariant(nativeOps, 'Native animated module is not available');
309
- API.queueOperation(nativeOps.dropAnimatedNode, tag);
310
- },
311
- addAnimatedEventToView: function (
312
- viewTag: number,
313
- eventName: string,
314
- eventMapping: EventMapping,
315
- ) {
316
- invariant(nativeOps, 'Native animated module is not available');
317
- API.queueOperation(
318
- nativeOps.addAnimatedEventToView,
319
- viewTag,
320
- eventName,
321
- eventMapping,
322
- );
323
- },
324
- removeAnimatedEventFromView(
325
- viewTag: number,
326
- eventName: string,
327
- animatedNodeTag: number,
328
- ) {
329
- invariant(nativeOps, 'Native animated module is not available');
330
- API.queueOperation(
331
- nativeOps.removeAnimatedEventFromView,
332
- viewTag,
333
- eventName,
334
- animatedNodeTag,
335
- );
336
- },
337
- };
338
-
339
- function setupGlobalEventEmitterListeners() {
340
- globalEventEmitterGetValueListener = RCTDeviceEventEmitter.addListener(
341
- 'onNativeAnimatedModuleGetValue',
342
- params => {
343
- const {tag} = params;
344
- const callback = eventListenerGetValueCallbacks[tag];
345
- if (!callback) {
346
- return;
347
- }
348
- callback(params.value);
349
- delete eventListenerGetValueCallbacks[tag];
350
- },
351
- );
352
- globalEventEmitterAnimationFinishedListener =
353
- RCTDeviceEventEmitter.addListener(
354
- 'onNativeAnimatedModuleAnimationFinished',
355
- params => {
356
- // TODO: remove Array.isArray once native changes have propagated
357
- const animations = Array.isArray(params) ? params : [params];
358
- for (const animation of animations) {
359
- const {animationId} = animation;
360
- const callback = eventListenerAnimationFinishedCallbacks[animationId];
361
- if (callback) {
362
- callback(animation);
363
- delete eventListenerAnimationFinishedCallbacks[animationId];
364
- }
365
- }
366
- },
367
- );
368
- }
369
-
370
- /**
371
- * Styles allowed by the native animated implementation.
372
- *
373
- * In general native animated implementation should support any numeric or color property that
374
- * doesn't need to be updated through the shadow view hierarchy (all non-layout properties).
375
- */
376
- const SUPPORTED_COLOR_STYLES = {
377
- backgroundColor: true,
378
- borderBottomColor: true,
379
- borderColor: true,
380
- borderEndColor: true,
381
- borderLeftColor: true,
382
- borderRightColor: true,
383
- borderStartColor: true,
384
- borderTopColor: true,
385
- color: true,
386
- tintColor: true,
387
- };
388
-
389
- const SUPPORTED_STYLES = {
390
- ...SUPPORTED_COLOR_STYLES,
391
- borderBottomEndRadius: true,
392
- borderBottomLeftRadius: true,
393
- borderBottomRightRadius: true,
394
- borderBottomStartRadius: true,
395
- borderEndEndRadius: true,
396
- borderEndStartRadius: true,
397
- borderRadius: true,
398
- borderTopEndRadius: true,
399
- borderTopLeftRadius: true,
400
- borderTopRightRadius: true,
401
- borderTopStartRadius: true,
402
- borderStartEndRadius: true,
403
- borderStartStartRadius: true,
404
- elevation: true,
405
- opacity: true,
406
- transform: true,
407
- zIndex: true,
408
- /* ios styles */
409
- shadowOpacity: true,
410
- shadowRadius: true,
411
- /* legacy android transform properties */
412
- scaleX: true,
413
- scaleY: true,
414
- translateX: true,
415
- translateY: true,
416
- };
417
-
418
- const SUPPORTED_TRANSFORMS = {
419
- translateX: true,
420
- translateY: true,
421
- scale: true,
422
- scaleX: true,
423
- scaleY: true,
424
- rotate: true,
425
- rotateX: true,
426
- rotateY: true,
427
- rotateZ: true,
428
- perspective: true,
429
- skewX: true,
430
- skewY: true,
431
- matrix: ReactNativeFeatureFlags.shouldUseAnimatedObjectForTransform(),
432
- };
433
-
434
- const SUPPORTED_INTERPOLATION_PARAMS = {
435
- inputRange: true,
436
- outputRange: true,
437
- extrapolate: true,
438
- extrapolateRight: true,
439
- extrapolateLeft: true,
440
- };
441
-
442
- function addWhitelistedStyleProp(prop: string): void {
443
- // $FlowFixMe[prop-missing]
444
- SUPPORTED_STYLES[prop] = true;
445
- }
446
-
447
- function addWhitelistedTransformProp(prop: string): void {
448
- // $FlowFixMe[prop-missing]
449
- SUPPORTED_TRANSFORMS[prop] = true;
450
- }
451
-
452
- function addWhitelistedInterpolationParam(param: string): void {
453
- // $FlowFixMe[prop-missing]
454
- SUPPORTED_INTERPOLATION_PARAMS[param] = true;
455
- }
456
-
457
- function isSupportedColorStyleProp(prop: string): boolean {
458
- // $FlowFixMe[invalid-computed-prop]
459
- return SUPPORTED_COLOR_STYLES[prop] === true;
460
- }
461
-
462
- function isSupportedStyleProp(prop: string): boolean {
463
- // $FlowFixMe[invalid-computed-prop]
464
- return SUPPORTED_STYLES[prop] === true;
465
- }
466
-
467
- function isSupportedTransformProp(prop: string): boolean {
468
- // $FlowFixMe[invalid-computed-prop]
469
- return SUPPORTED_TRANSFORMS[prop] === true;
470
- }
471
-
472
- function isSupportedInterpolationParam(param: string): boolean {
473
- // $FlowFixMe[invalid-computed-prop]
474
- return SUPPORTED_INTERPOLATION_PARAMS[param] === true;
475
- }
476
-
477
- function validateTransform(
478
- configs: Array<
479
- | {
480
- type: 'animated',
481
- property: string,
482
- nodeTag: ?number,
483
- ...
484
- }
485
- | {
486
- type: 'static',
487
- property: string,
488
- value: number | string,
489
- ...
490
- },
491
- >,
492
- ): void {
493
- configs.forEach(config => {
494
- if (!isSupportedTransformProp(config.property)) {
495
- throw new Error(
496
- `Property '${config.property}' is not supported by native animated module`,
497
- );
498
- }
499
- });
500
- }
501
-
502
- function validateStyles(styles: {[key: string]: ?number, ...}): void {
503
- for (const key in styles) {
504
- if (!isSupportedStyleProp(key)) {
505
- throw new Error(
506
- `Style property '${key}' is not supported by native animated module`,
507
- );
508
- }
509
- }
510
- }
511
-
512
- function validateInterpolation<OutputT: number | string>(
513
- config: InterpolationConfigType<OutputT>,
514
- ): void {
515
- for (const key in config) {
516
- if (!isSupportedInterpolationParam(key)) {
517
- throw new Error(
518
- `Interpolation property '${key}' is not supported by native animated module`,
519
- );
520
- }
521
- }
522
- }
523
-
524
- function generateNewNodeTag(): number {
525
- return __nativeAnimatedNodeTagCount++;
526
- }
527
-
528
- function generateNewAnimationId(): number {
529
- return __nativeAnimationIdCount++;
530
- }
531
-
532
- function assertNativeAnimatedModule(): void {
533
- invariant(NativeAnimatedModule, 'Native animated module is not available');
534
- }
535
-
536
- let _warnedMissingNativeAnimated = false;
537
-
538
- function shouldUseNativeDriver(
539
- config: $ReadOnly<{...AnimationConfig, ...}> | EventConfig,
540
- ): boolean {
541
- if (config.useNativeDriver == null) {
542
- console.warn(
543
- 'Animated: `useNativeDriver` was not specified. This is a required ' +
544
- 'option and must be explicitly set to `true` or `false`',
545
- );
546
- }
547
-
548
- if (config.useNativeDriver === true && !NativeAnimatedModule) {
549
- if (process.env.NODE_ENV !== 'test') {
550
- if (!_warnedMissingNativeAnimated) {
551
- console.warn(
552
- 'Animated: `useNativeDriver` is not supported because the native ' +
553
- 'animated module is missing. Falling back to JS-based animation. To ' +
554
- 'resolve this, add `RCTAnimation` module to this app, or remove ' +
555
- '`useNativeDriver`. ' +
556
- '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',
557
- );
558
- _warnedMissingNativeAnimated = true;
559
- }
560
- }
561
- return false;
562
- }
563
-
564
- return config.useNativeDriver || false;
565
- }
566
-
567
- function transformDataType(value: number | string): number | string {
568
- // Change the string type to number type so we can reuse the same logic in
569
- // iOS and Android platform
570
- if (typeof value !== 'string') {
571
- return value;
572
- }
573
-
574
- // Normalize degrees and radians to a number expressed in radians
575
- if (value.endsWith('deg')) {
576
- const degrees = parseFloat(value) || 0;
577
- return (degrees * Math.PI) / 180.0;
578
- } else if (value.endsWith('rad')) {
579
- return parseFloat(value) || 0;
580
- } else {
581
- return value;
582
- }
583
- }
584
-
585
- export default {
586
- API,
587
- isSupportedColorStyleProp,
588
- isSupportedStyleProp,
589
- isSupportedTransformProp,
590
- isSupportedInterpolationParam,
591
- addWhitelistedStyleProp,
592
- addWhitelistedTransformProp,
593
- addWhitelistedInterpolationParam,
594
- validateStyles,
595
- validateTransform,
596
- validateInterpolation,
597
- generateNewNodeTag,
598
- generateNewAnimationId,
599
- assertNativeAnimatedModule,
600
- shouldUseNativeDriver,
601
- transformDataType,
602
- // $FlowExpectedError[unsafe-getters-setters] - unsafe getter lint suppression
603
- // $FlowExpectedError[missing-type-arg] - unsafe getter lint suppression
604
- get nativeEventEmitter(): NativeEventEmitter {
605
- if (!nativeEventEmitter) {
606
- // $FlowFixMe[underconstrained-implicit-instantiation]
607
- nativeEventEmitter = new NativeEventEmitter(
608
- // 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
609
- // If you want to use the native module on other platforms, please remove this condition and test its behavior
610
- Platform.OS !== 'ios' ? null : NativeAnimatedModule,
611
- );
612
- }
613
- return nativeEventEmitter;
614
- },
615
- };