react-native-reanimated 2.3.0-alpha.3 → 2.3.0-beta.4

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 (264) hide show
  1. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +15 -8
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +176 -154
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +49 -33
  4. package/Common/cpp/Registries/EventHandlerRegistry.cpp +14 -7
  5. package/Common/cpp/Registries/MapperRegistry.cpp +24 -20
  6. package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
  7. package/Common/cpp/SharedItems/FrozenObject.cpp +17 -8
  8. package/Common/cpp/SharedItems/MutableValue.cpp +38 -25
  9. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +11 -7
  10. package/Common/cpp/SharedItems/RemoteObject.cpp +9 -5
  11. package/Common/cpp/SharedItems/ShareableValue.cpp +211 -160
  12. package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
  13. package/Common/cpp/Tools/JSIStoreValueUser.cpp +25 -6
  14. package/Common/cpp/Tools/Mapper.cpp +30 -30
  15. package/Common/cpp/Tools/RuntimeDecorator.cpp +124 -86
  16. package/Common/cpp/Tools/Scheduler.cpp +6 -5
  17. package/Common/cpp/Tools/WorkletEventHandler.cpp +4 -2
  18. package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
  19. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +50 -31
  20. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +34 -16
  21. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +15 -8
  22. package/Common/cpp/headers/Registries/MapperRegistry.h +5 -4
  23. package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
  24. package/Common/cpp/headers/SharedItems/FrozenObject.h +19 -11
  25. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +8 -4
  26. package/Common/cpp/headers/SharedItems/MutableValue.h +23 -12
  27. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +12 -7
  28. package/Common/cpp/headers/SharedItems/RemoteObject.h +19 -8
  29. package/Common/cpp/headers/SharedItems/RuntimeManager.h +26 -25
  30. package/Common/cpp/headers/SharedItems/ShareableValue.h +32 -27
  31. package/Common/cpp/headers/SharedItems/SharedParent.h +10 -7
  32. package/Common/cpp/headers/SharedItems/ValueWrapper.h +95 -72
  33. package/Common/cpp/headers/SpecTools/ErrorHandler.h +18 -19
  34. package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
  35. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +13 -16
  36. package/Common/cpp/headers/Tools/Mapper.h +19 -16
  37. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +17 -7
  38. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -11
  39. package/Common/cpp/headers/Tools/RuntimeDecorator.h +36 -27
  40. package/Common/cpp/headers/Tools/Scheduler.h +30 -35
  41. package/Common/cpp/headers/Tools/WorkletEventHandler.h +11 -8
  42. package/Common/cpp/hidden_headers/Logger.h +14 -14
  43. package/Common/cpp/hidden_headers/LoggerInterface.h +8 -9
  44. package/Common/cpp/hidden_headers/SpeedChecker.h +7 -8
  45. package/README.md +1 -1
  46. package/RNReanimated.podspec +24 -6
  47. package/android/build.gradle +38 -29
  48. package/android/react-native-reanimated-63-hermes.aar +0 -0
  49. package/android/react-native-reanimated-63-jsc.aar +0 -0
  50. package/android/react-native-reanimated-64-hermes.aar +0 -0
  51. package/android/react-native-reanimated-64-jsc.aar +0 -0
  52. package/android/react-native-reanimated-65-hermes.aar +0 -0
  53. package/android/react-native-reanimated-65-jsc.aar +0 -0
  54. package/android/react-native-reanimated-66-hermes.aar +0 -0
  55. package/android/react-native-reanimated-66-jsc.aar +0 -0
  56. package/android/react-native-reanimated-67-hermes.aar +0 -0
  57. package/android/react-native-reanimated-67-jsc.aar +0 -0
  58. package/ios/LayoutReanimation/REAAnimationsManager.h +10 -8
  59. package/ios/LayoutReanimation/REAAnimationsManager.m +91 -87
  60. package/ios/LayoutReanimation/REASnapshot.h +2 -2
  61. package/ios/LayoutReanimation/REASnapshot.m +8 -7
  62. package/ios/LayoutReanimation/REAUIManager.h +4 -4
  63. package/ios/LayoutReanimation/REAUIManager.mm +116 -70
  64. package/ios/Nodes/REAAlwaysNode.m +14 -15
  65. package/ios/Nodes/REABezierNode.m +8 -7
  66. package/ios/Nodes/REABlockNode.m +1 -1
  67. package/ios/Nodes/REACallFuncNode.h +0 -1
  68. package/ios/Nodes/REACallFuncNode.m +10 -8
  69. package/ios/Nodes/REAClockNodes.m +22 -20
  70. package/ios/Nodes/REAConcatNode.h +0 -1
  71. package/ios/Nodes/REAConcatNode.m +2 -2
  72. package/ios/Nodes/REACondNode.m +7 -5
  73. package/ios/Nodes/READebugNode.m +5 -4
  74. package/ios/Nodes/REAEventNode.m +1 -1
  75. package/ios/Nodes/REAFunctionNode.h +0 -1
  76. package/ios/Nodes/REAFunctionNode.m +2 -2
  77. package/ios/Nodes/REAJSCallNode.m +4 -5
  78. package/ios/Nodes/REANode.h +3 -4
  79. package/ios/Nodes/REANode.m +9 -11
  80. package/ios/Nodes/REAOperatorNode.m +68 -67
  81. package/ios/Nodes/REAParamNode.h +1 -3
  82. package/ios/Nodes/REAParamNode.m +15 -17
  83. package/ios/Nodes/REAPropsNode.h +1 -3
  84. package/ios/Nodes/REAPropsNode.m +19 -22
  85. package/ios/Nodes/REASetNode.h +0 -1
  86. package/ios/Nodes/REASetNode.m +7 -5
  87. package/ios/Nodes/REAStyleNode.h +0 -1
  88. package/ios/Nodes/REAStyleNode.m +2 -4
  89. package/ios/Nodes/REATransformNode.h +0 -1
  90. package/ios/Nodes/REATransformNode.m +3 -5
  91. package/ios/Nodes/REAValueNode.m +5 -7
  92. package/ios/REAEventDispatcher.m +4 -4
  93. package/ios/REAModule.h +0 -2
  94. package/ios/REAModule.m +29 -38
  95. package/ios/REANodesManager.h +11 -19
  96. package/ios/REANodesManager.m +106 -130
  97. package/ios/REAUtils.h +5 -3
  98. package/ios/RNGestureHandlerStateManager.h +5 -0
  99. package/ios/Transitioning/RCTConvert+REATransition.m +45 -29
  100. package/ios/Transitioning/REAAllTransitions.h +2 -2
  101. package/ios/Transitioning/REAAllTransitions.m +14 -25
  102. package/ios/Transitioning/REATransition.h +8 -7
  103. package/ios/Transitioning/REATransition.m +19 -16
  104. package/ios/Transitioning/REATransitionAnimation.h +1 -1
  105. package/ios/Transitioning/REATransitionAnimation.m +2 -3
  106. package/ios/Transitioning/REATransitionManager.m +3 -3
  107. package/ios/native/NativeMethods.h +20 -5
  108. package/ios/native/NativeMethods.mm +14 -6
  109. package/ios/native/NativeProxy.h +4 -2
  110. package/ios/native/NativeProxy.mm +84 -63
  111. package/ios/native/REAIOSErrorHandler.h +13 -10
  112. package/ios/native/REAIOSErrorHandler.mm +19 -15
  113. package/ios/native/REAIOSLogger.h +8 -8
  114. package/ios/native/REAIOSLogger.mm +10 -6
  115. package/ios/native/REAIOSScheduler.h +5 -5
  116. package/ios/native/REAIOSScheduler.mm +17 -10
  117. package/ios/native/REAInitializer.h +5 -7
  118. package/ios/native/REAInitializer.mm +43 -31
  119. package/ios/native/UIResponder+Reanimated.mm +2 -2
  120. package/lib/Animated.js +9 -1
  121. package/lib/ConfigHelper.js +121 -138
  122. package/lib/ReanimatedEventEmitter.js +0 -1
  123. package/lib/ReanimatedModule.js +0 -1
  124. package/lib/ReanimatedModule.macos.js +0 -1
  125. package/lib/ReanimatedModule.native.js +5 -6
  126. package/lib/ReanimatedModule.windows.js +0 -1
  127. package/lib/ReanimatedModuleCompat.js +64 -35
  128. package/lib/createAnimatedComponent.js +468 -487
  129. package/lib/index.js +9 -1
  130. package/lib/reanimated2/NativeMethods.js +7 -12
  131. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +37 -0
  132. package/lib/reanimated2/NativeReanimated/index.js +15 -0
  133. package/lib/reanimated2/PropAdapters.js +0 -1
  134. package/lib/reanimated2/UpdateProps.js +6 -7
  135. package/lib/reanimated2/ViewDescriptorsSet.js +4 -4
  136. package/lib/reanimated2/WorkletEventHandler.js +15 -13
  137. package/lib/reanimated2/animation/delay.js +8 -2
  138. package/lib/reanimated2/animation/spring.js +2 -0
  139. package/lib/reanimated2/animation/styleAnimation.js +7 -3
  140. package/lib/reanimated2/animation/util.js +25 -2
  141. package/lib/reanimated2/core.js +41 -17
  142. package/lib/reanimated2/globals.d.ts +21 -1
  143. package/lib/reanimated2/hook/useAnimatedRef.js +1 -1
  144. package/lib/reanimated2/hook/useAnimatedStyle.js +3 -3
  145. package/lib/reanimated2/index.js +1 -0
  146. package/lib/reanimated2/interpolation.js +95 -87
  147. package/lib/reanimated2/js-reanimated/JSReanimated.js +13 -10
  148. package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
  149. package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
  150. package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
  151. package/lib/reanimated2/js-reanimated/index.js +10 -8
  152. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +33 -2
  153. package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +27 -124
  154. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
  155. package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +1 -2
  156. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +115 -45
  157. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +7 -2
  158. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +21 -21
  159. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +25 -25
  160. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +19 -17
  161. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +5 -5
  162. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +9 -9
  163. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +17 -17
  164. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +19 -19
  165. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +9 -9
  166. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +33 -33
  167. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +78 -0
  168. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +128 -0
  169. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +37 -0
  170. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +41 -0
  171. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +34 -0
  172. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +46 -0
  173. package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +6 -0
  174. package/lib/reanimated2/layoutReanimation/index.js +1 -0
  175. package/lib/reanimated2/mock.js +3 -1
  176. package/lib/reanimated2/utils.js +9 -0
  177. package/lib/setAndForwardRef.js +14 -48
  178. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  179. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  180. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  181. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
  182. package/mock.js +1 -1
  183. package/package.json +28 -17
  184. package/plugin.js +220 -39
  185. package/react-native-reanimated.d.ts +542 -547
  186. package/src/Animated.js +9 -1
  187. package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
  188. package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
  189. package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
  190. package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
  191. package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
  192. package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
  193. package/src/ReanimatedModuleCompat.ts +51 -0
  194. package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +285 -126
  195. package/src/reanimated2/NativeMethods.ts +34 -13
  196. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +72 -0
  197. package/src/reanimated2/NativeReanimated/index.ts +18 -0
  198. package/src/reanimated2/PropAdapters.ts +0 -1
  199. package/src/reanimated2/UpdateProps.ts +31 -15
  200. package/src/reanimated2/ViewDescriptorsSet.ts +15 -12
  201. package/src/reanimated2/WorkletEventHandler.ts +41 -23
  202. package/src/reanimated2/animation/commonTypes.ts +4 -4
  203. package/src/reanimated2/animation/decay.ts +2 -2
  204. package/src/reanimated2/animation/delay.ts +11 -5
  205. package/src/reanimated2/animation/index.ts +7 -7
  206. package/src/reanimated2/animation/repeat.ts +4 -4
  207. package/src/reanimated2/animation/sequence.ts +2 -2
  208. package/src/reanimated2/animation/spring.ts +6 -5
  209. package/src/reanimated2/animation/styleAnimation.ts +27 -15
  210. package/src/reanimated2/animation/timing.ts +5 -5
  211. package/src/reanimated2/animation/util.ts +47 -8
  212. package/src/reanimated2/commonTypes.ts +3 -0
  213. package/src/reanimated2/core.ts +80 -34
  214. package/src/reanimated2/globals.d.ts +21 -1
  215. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -1
  216. package/src/reanimated2/hook/useAnimatedRef.ts +13 -15
  217. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -3
  218. package/src/reanimated2/hook/useAnimatedStyle.ts +7 -7
  219. package/src/reanimated2/hook/utils.ts +4 -3
  220. package/src/reanimated2/index.ts +1 -0
  221. package/src/reanimated2/interpolation.ts +170 -103
  222. package/src/reanimated2/js-reanimated/JSReanimated.ts +37 -23
  223. package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
  224. package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
  225. package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
  226. package/src/reanimated2/js-reanimated/index.ts +31 -14
  227. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +75 -0
  228. package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +29 -159
  229. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
  230. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -2
  231. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +3 -9
  232. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -5
  233. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +162 -82
  234. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +7 -2
  235. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +32 -32
  236. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +38 -38
  237. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +34 -32
  238. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -8
  239. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +14 -14
  240. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +26 -26
  241. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +28 -28
  242. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +14 -14
  243. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +50 -50
  244. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +104 -0
  245. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +213 -0
  246. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +60 -0
  247. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +58 -0
  248. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +41 -0
  249. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +78 -0
  250. package/src/reanimated2/layoutReanimation/defaultTransitions/index.ts +6 -0
  251. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  252. package/src/reanimated2/mock.ts +3 -1
  253. package/src/reanimated2/utils.ts +21 -0
  254. package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
  255. package/android/react-native-reanimated-62-hermes.aar +0 -0
  256. package/android/react-native-reanimated-62-jsc.aar +0 -0
  257. package/lib/reanimated2/NativeReanimated.js +0 -48
  258. package/lib/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.js +0 -55
  259. package/lib/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.js +0 -165
  260. package/src/ReanimatedModuleCompat.js +0 -37
  261. package/src/reanimated2/NativeReanimated.ts +0 -70
  262. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +0 -41
  263. package/src/reanimated2/layoutReanimation/animationBuilder/BaseBounceAnimationBuilder.ts +0 -82
  264. package/src/reanimated2/layoutReanimation/animationBuilder/LayoutAnimationBuilder.ts +0 -217
@@ -1,532 +1,513 @@
1
1
  import React from 'react';
2
2
  import { findNodeHandle, Platform, StyleSheet } from 'react-native';
3
3
  import ReanimatedEventEmitter from './ReanimatedEventEmitter';
4
-
4
+ // @ts-ignore JS file
5
5
  import AnimatedEvent from './reanimated1/core/AnimatedEvent';
6
+ // @ts-ignore JS file
6
7
  import AnimatedNode from './reanimated1/core/AnimatedNode';
8
+ // @ts-ignore JS file
7
9
  import AnimatedValue from './reanimated1/core/AnimatedValue';
10
+ // @ts-ignore JS file
8
11
  import { createOrReusePropsNode } from './reanimated1/core/AnimatedProps';
9
12
  import WorkletEventHandler from './reanimated2/WorkletEventHandler';
10
13
  import setAndForwardRef from './setAndForwardRef';
11
14
  import './reanimated2/layoutReanimation/LayoutAnimationRepository';
12
-
13
15
  import invariant from 'invariant';
14
16
  import { adaptViewConfig } from './ConfigHelper';
15
17
  import { RNRenderer } from './reanimated2/platform-specific/RNRenderer';
16
- import { makeMutable, runOnUI } from './reanimated2/core';
17
- import {
18
- DefaultEntering,
19
- DefaultExiting,
20
- DefaultLayout,
21
- } from './reanimated2/layoutReanimation/defaultAnimations/Default';
22
- import { isJest, isChromeDebugger } from './reanimated2/PlatformChecker';
23
-
18
+ import { makeMutable, runOnUI, enableLayoutAnimations, } from './reanimated2/core';
19
+ import { DefaultEntering, DefaultExiting, DefaultLayout, } from './reanimated2/layoutReanimation/defaultAnimations/Default';
20
+ import { isJest, isChromeDebugger, shouldBeUseWeb, } from './reanimated2/PlatformChecker';
21
+ import { initialUpdaterRun } from './reanimated2/animation';
24
22
  const NODE_MAPPING = new Map();
25
-
26
23
  function listener(data) {
27
- const component = NODE_MAPPING.get(data.viewTag);
28
- component && component._updateFromNative(data.props);
24
+ const component = NODE_MAPPING.get(data.viewTag);
25
+ component && component._updateFromNative(data.props);
29
26
  }
30
-
31
27
  function dummyListener() {
32
- // empty listener we use to assign to listener properties for which animated
33
- // event is used.
28
+ // empty listener we use to assign to listener properties for which animated
29
+ // event is used.
34
30
  }
35
-
36
31
  function hasAnimatedNodes(value) {
37
- if (value instanceof AnimatedNode) {
38
- return true;
39
- }
40
- if (Array.isArray(value)) {
41
- return value.some((item) => hasAnimatedNodes(item));
42
- }
43
- if (value && typeof value === 'object') {
44
- return Object.keys(value).some((key) => hasAnimatedNodes(value[key]));
45
- }
46
- return false;
47
- }
48
-
49
- function flattenArray(array) {
50
- if (!Array.isArray(array)) {
51
- return [array];
52
- }
53
- const resultArr = [];
54
-
55
- const _flattenArray = (arr) => {
56
- arr.forEach((item) => {
57
- if (Array.isArray(item)) {
58
- _flattenArray(item);
59
- } else {
60
- resultArr.push(item);
61
- }
62
- });
63
- };
64
- _flattenArray(array);
65
- return resultArr;
66
- }
67
-
68
- export default function createAnimatedComponent(Component, options = {}) {
69
- invariant(
70
- typeof Component !== 'function' ||
71
- (Component.prototype && Component.prototype.isReactComponent),
72
- '`createAnimatedComponent` does not support stateless functional components; ' +
73
- 'use a class component instead.'
74
- );
75
-
76
- class AnimatedComponent extends React.Component {
77
- _invokeAnimatedPropsCallbackOnMount = false;
78
- _styles = null;
79
- _viewTag = -1;
80
-
81
- constructor(props) {
82
- super(props);
83
- this._attachProps(this.props);
84
- if (isJest()) {
85
- this.animatedStyle = { value: {} };
86
- }
87
- this.sv = makeMutable({});
32
+ if (value instanceof AnimatedNode) {
33
+ return true;
88
34
  }
89
-
90
- componentWillUnmount() {
91
- this._detachPropUpdater();
92
- this._propsAnimated && this._propsAnimated.__detach();
93
- this._detachNativeEvents();
94
- this._detachStyles();
95
- this.sv = null;
35
+ if (Array.isArray(value)) {
36
+ return value.some((item) => hasAnimatedNodes(item));
96
37
  }
97
-
98
- componentDidMount() {
99
- if (this._invokeAnimatedPropsCallbackOnMount) {
100
- this._invokeAnimatedPropsCallbackOnMount = false;
101
- this._animatedPropsCallback();
102
- }
103
-
104
- this._propsAnimated && this._propsAnimated.setNativeView(this._component);
105
- this._attachNativeEvents();
106
- this._attachPropUpdater();
107
- this._attachAnimatedStyles();
38
+ if (value && typeof value === 'object') {
39
+ return Object.keys(value).some((key) => hasAnimatedNodes(value[key]));
108
40
  }
109
-
110
- _getEventViewRef() {
111
- // Make sure to get the scrollable node for components that implement
112
- // `ScrollResponder.Mixin`.
113
- return this._component.getScrollableNode
114
- ? this._component.getScrollableNode()
115
- : this._component;
41
+ return false;
42
+ }
43
+ function flattenArray(array) {
44
+ if (!Array.isArray(array)) {
45
+ return [array];
116
46
  }
117
-
118
- _attachNativeEvents() {
119
- const node = this._getEventViewRef();
120
- const viewTag = findNodeHandle(options.setNativeProps ? this : node);
121
- for (const key in this.props) {
122
- const prop = this.props[key];
123
- if (prop instanceof AnimatedEvent) {
124
- prop.attachEvent(node, key);
125
- } else if (
126
- prop?.current &&
127
- prop.current instanceof WorkletEventHandler
128
- ) {
129
- prop.current.registerForEvents(viewTag, key);
47
+ const resultArr = [];
48
+ const _flattenArray = (arr) => {
49
+ arr.forEach((item) => {
50
+ if (Array.isArray(item)) {
51
+ _flattenArray(item);
52
+ }
53
+ else {
54
+ resultArr.push(item);
55
+ }
56
+ });
57
+ };
58
+ _flattenArray(array);
59
+ return resultArr;
60
+ }
61
+ function onlyAnimatedStyles(styles) {
62
+ return styles.filter((style) => style === null || style === void 0 ? void 0 : style.viewDescriptors);
63
+ }
64
+ function isSameAnimatedStyle(style1, style2) {
65
+ // We cannot use equality check to compare useAnimatedStyle outputs directly.
66
+ // Instead, we can compare its viewsRefs.
67
+ return style1.viewsRef === style2.viewsRef;
68
+ }
69
+ const has = (key, x) => {
70
+ if (typeof x === 'function' || typeof x === 'object') {
71
+ if (x === null || x === undefined) {
72
+ return false;
130
73
  }
131
- }
132
- }
133
-
134
- _detachNativeEvents() {
135
- const node = this._getEventViewRef();
136
-
137
- for (const key in this.props) {
138
- const prop = this.props[key];
139
- if (prop instanceof AnimatedEvent) {
140
- prop.detachEvent(node, key);
141
- } else if (
142
- prop?.current &&
143
- prop.current instanceof WorkletEventHandler
144
- ) {
145
- prop.current.unregisterFromEvents();
74
+ else {
75
+ return key in x;
146
76
  }
147
- }
148
77
  }
149
-
150
- _detachStyles() {
151
- if (Platform.OS === 'web') {
152
- for (const style of this._styles) {
153
- if (style.viewsRef) {
154
- style.viewsRef.remove(this);
155
- }
78
+ return false;
79
+ };
80
+ export default function createAnimatedComponent(Component, options) {
81
+ invariant(typeof Component !== 'function' ||
82
+ (Component.prototype && Component.prototype.isReactComponent), '`createAnimatedComponent` does not support stateless functional components; ' +
83
+ 'use a class component instead.');
84
+ class AnimatedComponent extends React.Component {
85
+ constructor(props) {
86
+ super(props);
87
+ this._invokeAnimatedPropsCallbackOnMount = false;
88
+ this._styles = null;
89
+ this._viewTag = -1;
90
+ this._isFirstRender = true;
91
+ this.animatedStyle = { value: {} };
92
+ this._component = null;
93
+ // The system is best designed when setNativeProps is implemented. It is
94
+ // able to avoid re-rendering and directly set the attributes that changed.
95
+ // However, setNativeProps can only be implemented on native components
96
+ // If you want to animate a composite component, you need to re-render it.
97
+ // In this case, we have a fallback that uses forceUpdate.
98
+ this._animatedPropsCallback = () => {
99
+ if (this._component == null) {
100
+ // AnimatedProps is created in will-mount because it's used in render.
101
+ // But this callback may be invoked before mount in async mode,
102
+ // In which case we should defer the setNativeProps() call.
103
+ // React may throw away uncommitted work in async mode,
104
+ // So a deferred call won't always be invoked.
105
+ this._invokeAnimatedPropsCallbackOnMount = true;
106
+ }
107
+ else if (typeof this._component.setNativeProps !== 'function') {
108
+ this.forceUpdate();
109
+ }
110
+ else {
111
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
112
+ this._component.setNativeProps(this._propsAnimated.__getValue());
113
+ }
114
+ };
115
+ this._setComponentRef = setAndForwardRef({
116
+ getForwardedRef: () => this.props.forwardedRef,
117
+ setLocalRef: (ref) => {
118
+ // TODO update config
119
+ const tag = findNodeHandle(ref);
120
+ if ((this.props.layout || this.props.entering || this.props.exiting) &&
121
+ tag != null) {
122
+ if (!shouldBeUseWeb()) {
123
+ enableLayoutAnimations(true, false);
124
+ }
125
+ let layout = this.props.layout ? this.props.layout : DefaultLayout;
126
+ let entering = this.props.entering
127
+ ? this.props.entering
128
+ : DefaultEntering;
129
+ let exiting = this.props.exiting
130
+ ? this.props.exiting
131
+ : DefaultExiting;
132
+ if (has('build', layout)) {
133
+ layout = layout.build();
134
+ }
135
+ if (has('build', entering)) {
136
+ entering = entering.build();
137
+ }
138
+ if (has('build', exiting)) {
139
+ exiting = exiting.build();
140
+ }
141
+ const config = {
142
+ layout,
143
+ entering,
144
+ exiting,
145
+ sv: this.sv,
146
+ };
147
+ runOnUI(() => {
148
+ 'worklet';
149
+ global.LayoutAnimationRepository.registerConfig(tag, config);
150
+ })();
151
+ }
152
+ if (ref !== this._component) {
153
+ this._component = ref;
154
+ }
155
+ },
156
+ });
157
+ this._attachProps(this.props);
158
+ if (isJest()) {
159
+ this.animatedStyle = { value: {} };
160
+ }
161
+ this.sv = makeMutable({});
156
162
  }
157
- } else if (this._viewTag !== -1) {
158
- for (const style of this._styles) {
159
- if (style?.viewDescriptors) {
160
- style.viewDescriptors.remove(this._viewTag);
161
- }
163
+ componentWillUnmount() {
164
+ this._detachPropUpdater();
165
+ this._propsAnimated && this._propsAnimated.__detach();
166
+ this._detachNativeEvents();
167
+ this._detachStyles();
168
+ this.sv = null;
162
169
  }
163
- if (this.props.animatedProps?.viewDescriptors) {
164
- this.props.animatedProps.viewDescriptors.remove(this._viewTag);
170
+ componentDidMount() {
171
+ if (this._invokeAnimatedPropsCallbackOnMount) {
172
+ this._invokeAnimatedPropsCallbackOnMount = false;
173
+ this._animatedPropsCallback();
174
+ }
175
+ this._propsAnimated &&
176
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
177
+ this._propsAnimated.setNativeView(this._component);
178
+ this._attachNativeEvents();
179
+ this._attachPropUpdater();
180
+ this._attachAnimatedStyles();
165
181
  }
166
- }
167
- }
168
-
169
- _reattachNativeEvents(prevProps) {
170
- const node = this._getEventViewRef();
171
- const attached = new Set();
172
- const nextEvts = new Set();
173
- let viewTag;
174
-
175
- for (const key in this.props) {
176
- const prop = this.props[key];
177
- if (prop instanceof AnimatedEvent) {
178
- nextEvts.add(prop.__nodeID);
179
- } else if (
180
- prop?.current &&
181
- prop.current instanceof WorkletEventHandler
182
- ) {
183
- if (viewTag === undefined) {
184
- viewTag = prop.current.viewTag;
185
- }
182
+ _getEventViewRef() {
183
+ var _a;
184
+ // Make sure to get the scrollable node for components that implement
185
+ // `ScrollResponder.Mixin`.
186
+ return ((_a = this._component) === null || _a === void 0 ? void 0 : _a.getScrollableNode) ? this._component.getScrollableNode()
187
+ : this._component;
186
188
  }
187
- }
188
- for (const key in prevProps) {
189
- const prop = this.props[key];
190
- if (prop instanceof AnimatedEvent) {
191
- if (!nextEvts.has(prop.__nodeID)) {
192
- // event was in prev props but not in current props, we detach
193
- prop.detachEvent(node, key);
194
- } else {
195
- // event was in prev and is still in current props
196
- attached.add(prop.__nodeID);
197
- }
198
- } else if (
199
- prop?.current &&
200
- prop.current instanceof WorkletEventHandler &&
201
- prop.current.reattachNeeded
202
- ) {
203
- prop.current.unregisterFromEvents();
189
+ _attachNativeEvents() {
190
+ const node = this._getEventViewRef();
191
+ const viewTag = findNodeHandle((options === null || options === void 0 ? void 0 : options.setNativeProps) ? this : node);
192
+ for (const key in this.props) {
193
+ const prop = this.props[key];
194
+ if (prop instanceof AnimatedEvent) {
195
+ prop.attachEvent(node, key);
196
+ }
197
+ else if (has('current', prop) &&
198
+ prop.current instanceof WorkletEventHandler) {
199
+ prop.current.registerForEvents(viewTag, key);
200
+ }
201
+ }
204
202
  }
205
- }
206
-
207
- for (const key in this.props) {
208
- const prop = this.props[key];
209
- if (prop instanceof AnimatedEvent && !attached.has(prop.__nodeID)) {
210
- // not yet attached
211
- prop.attachEvent(node, key);
212
- } else if (
213
- prop?.current &&
214
- prop.current instanceof WorkletEventHandler &&
215
- prop.current.reattachNeeded
216
- ) {
217
- prop.current.registerForEvents(viewTag, key);
218
- prop.current.reattachNeeded = false;
203
+ _detachNativeEvents() {
204
+ const node = this._getEventViewRef();
205
+ for (const key in this.props) {
206
+ const prop = this.props[key];
207
+ if (prop instanceof AnimatedEvent) {
208
+ prop.detachEvent(node, key);
209
+ }
210
+ else if (has('current', prop) &&
211
+ prop.current instanceof WorkletEventHandler) {
212
+ prop.current.unregisterFromEvents();
213
+ }
214
+ }
219
215
  }
220
- }
221
- }
222
-
223
- // The system is best designed when setNativeProps is implemented. It is
224
- // able to avoid re-rendering and directly set the attributes that changed.
225
- // However, setNativeProps can only be implemented on native components
226
- // If you want to animate a composite component, you need to re-render it.
227
- // In this case, we have a fallback that uses forceUpdate.
228
- _animatedPropsCallback = () => {
229
- if (this._component == null) {
230
- // AnimatedProps is created in will-mount because it's used in render.
231
- // But this callback may be invoked before mount in async mode,
232
- // In which case we should defer the setNativeProps() call.
233
- // React may throw away uncommitted work in async mode,
234
- // So a deferred call won't always be invoked.
235
- this._invokeAnimatedPropsCallbackOnMount = true;
236
- } else if (typeof this._component.setNativeProps !== 'function') {
237
- this.forceUpdate();
238
- } else {
239
- this._component.setNativeProps(this._propsAnimated.__getValue());
240
- }
241
- };
242
-
243
- _attachProps(nextProps) {
244
- const oldPropsAnimated = this._propsAnimated;
245
-
246
- this._propsAnimated = createOrReusePropsNode(
247
- nextProps,
248
- this._animatedPropsCallback,
249
- oldPropsAnimated
250
- );
251
- // If prop node has been reused we don't need to call into "__detach"
252
- if (oldPropsAnimated !== this._propsAnimated) {
253
- // When you call detach, it removes the element from the parent list
254
- // of children. If it goes to 0, then the parent also detaches itself
255
- // and so on.
256
- // An optimization is to attach the new elements and THEN detach the old
257
- // ones instead of detaching and THEN attaching.
258
- // This way the intermediate state isn't to go to 0 and trigger
259
- // this expensive recursive detaching to then re-attach everything on
260
- // the very next operation.
261
- oldPropsAnimated && oldPropsAnimated.__detach();
262
- }
263
- }
264
-
265
- _updateFromNative(props) {
266
- if (options.setNativeProps) {
267
- options.setNativeProps(this._component, props);
268
- } else {
269
- // eslint-disable-next-line no-unused-expressions
270
- this._component.setNativeProps?.(props);
271
- }
272
- }
273
-
274
- _attachPropUpdater() {
275
- const viewTag = findNodeHandle(this);
276
- NODE_MAPPING.set(viewTag, this);
277
- if (NODE_MAPPING.size === 1) {
278
- ReanimatedEventEmitter.addListener('onReanimatedPropsChange', listener);
279
- }
280
- }
281
-
282
- _attachAnimatedStyles() {
283
- const styles = flattenArray(this.props.style);
284
- this._styles = styles;
285
- let viewTag, viewName;
286
- if (Platform.OS === 'web') {
287
- viewTag = findNodeHandle(this);
288
- viewName = null;
289
- } else {
290
- // hostInstance can be null for a component that doesn't render anything (render function returns null). Example: svg Stop: https://github.com/react-native-svg/react-native-svg/blob/develop/src/elements/Stop.tsx
291
- const hostInstance = RNRenderer.findHostInstance_DEPRECATED(this);
292
- if (!hostInstance) {
293
- throw new Error(
294
- 'Cannot find host instance for this component. Maybe it renders nothing?'
295
- );
216
+ _detachStyles() {
217
+ var _a;
218
+ if (Platform.OS === 'web' && this._styles !== null) {
219
+ for (const style of this._styles) {
220
+ if (style === null || style === void 0 ? void 0 : style.viewsRef) {
221
+ style.viewsRef.remove(this);
222
+ }
223
+ }
224
+ }
225
+ else if (this._viewTag !== -1 && this._styles !== null) {
226
+ for (const style of this._styles) {
227
+ style.viewDescriptors.remove(this._viewTag);
228
+ }
229
+ if ((_a = this.props.animatedProps) === null || _a === void 0 ? void 0 : _a.viewDescriptors) {
230
+ this.props.animatedProps.viewDescriptors.remove(this._viewTag);
231
+ }
232
+ }
296
233
  }
297
- // we can access view tag in the same way it's accessed here https://github.com/facebook/react/blob/e3f4eb7272d4ca0ee49f27577156b57eeb07cf73/packages/react-native-renderer/src/ReactFabric.js#L146
298
- viewTag = hostInstance?._nativeTag;
299
- /**
300
- * RN uses viewConfig for components for storing different properties of the component(example: https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollView/ScrollViewViewConfig.js#L16).
301
- * The name we're looking for is in the field named uiViewClassName.
302
- */
303
- viewName = hostInstance?.viewConfig?.uiViewClassName;
304
- // update UI props whitelist for this view
305
- if (
306
- hostInstance &&
307
- this._hasReanimated2Props(styles) &&
308
- hostInstance.viewConfig
309
- ) {
310
- adaptViewConfig(hostInstance.viewConfig);
234
+ _reattachNativeEvents(prevProps) {
235
+ const node = this._getEventViewRef();
236
+ const attached = new Set();
237
+ const nextEvts = new Set();
238
+ let viewTag;
239
+ for (const key in this.props) {
240
+ const prop = this.props[key];
241
+ if (prop instanceof AnimatedEvent) {
242
+ nextEvts.add(prop.__nodeID);
243
+ }
244
+ else if (has('current', prop) &&
245
+ prop.current instanceof WorkletEventHandler) {
246
+ if (viewTag === undefined) {
247
+ viewTag = prop.current.viewTag;
248
+ }
249
+ }
250
+ }
251
+ for (const key in prevProps) {
252
+ const prop = this.props[key];
253
+ if (prop instanceof AnimatedEvent) {
254
+ if (!nextEvts.has(prop.__nodeID)) {
255
+ // event was in prev props but not in current props, we detach
256
+ prop.detachEvent(node, key);
257
+ }
258
+ else {
259
+ // event was in prev and is still in current props
260
+ attached.add(prop.__nodeID);
261
+ }
262
+ }
263
+ else if (has('current', prop) &&
264
+ prop.current instanceof WorkletEventHandler &&
265
+ prop.current.reattachNeeded) {
266
+ prop.current.unregisterFromEvents();
267
+ }
268
+ }
269
+ for (const key in this.props) {
270
+ const prop = this.props[key];
271
+ if (prop instanceof AnimatedEvent &&
272
+ !attached.has(prop.__nodeID)) {
273
+ // not yet attached
274
+ prop.attachEvent(node, key);
275
+ }
276
+ else if (has('current', prop) &&
277
+ prop.current instanceof WorkletEventHandler &&
278
+ prop.current.reattachNeeded) {
279
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
280
+ prop.current.registerForEvents(viewTag, key);
281
+ prop.current.reattachNeeded = false;
282
+ }
283
+ }
311
284
  }
312
- }
313
- this._viewTag = viewTag;
314
-
315
- styles.forEach((style) => {
316
- if (style?.viewDescriptors) {
317
- style.viewDescriptors.add({ tag: viewTag, name: viewName });
318
- if (isJest()) {
319
- /**
320
- * We need to connect Jest's TestObject instance whose contains just props object
321
- * with the updateProps() function where we update the properties of the component.
322
- * We can't update props object directly because TestObject contains a copy of props - look at render function:
323
- * const props = this._filterNonAnimatedProps(this.props);
324
- */
325
- this.animatedStyle.value = {
326
- ...this.animatedStyle.value,
327
- ...style.initial.value,
328
- };
329
- style.animatedStyle.current = this.animatedStyle;
330
- }
285
+ _attachProps(nextProps) {
286
+ const oldPropsAnimated = this._propsAnimated;
287
+ this._propsAnimated = createOrReusePropsNode(nextProps, this._animatedPropsCallback, oldPropsAnimated);
288
+ // If prop node has been reused we don't need to call into "__detach"
289
+ if (oldPropsAnimated !== this._propsAnimated) {
290
+ // When you call detach, it removes the element from the parent list
291
+ // of children. If it goes to 0, then the parent also detaches itself
292
+ // and so on.
293
+ // An optimization is to attach the new elements and THEN detach the old
294
+ // ones instead of detaching and THEN attaching.
295
+ // This way the intermediate state isn't to go to 0 and trigger
296
+ // this expensive recursive detaching to then re-attach everything on
297
+ // the very next operation.
298
+ oldPropsAnimated && oldPropsAnimated.__detach();
299
+ }
331
300
  }
332
- });
333
- // attach animatedProps property
334
- if (this.props.animatedProps?.viewDescriptors) {
335
- this.props.animatedProps.viewDescriptors.add({
336
- tag: viewTag,
337
- name: viewName,
338
- });
339
- }
340
- }
341
-
342
- _hasReanimated2Props(flattenStyles) {
343
- if (this.props.animatedProps?.viewDescriptors) {
344
- return true;
345
- }
346
- if (this.props.style) {
347
- for (const style of flattenStyles) {
348
- // eslint-disable-next-line no-prototype-builtins
349
- if (style?.hasOwnProperty('viewDescriptors')) {
350
- return true;
351
- }
301
+ _updateFromNative(props) {
302
+ var _a, _b;
303
+ if (options === null || options === void 0 ? void 0 : options.setNativeProps) {
304
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
305
+ options.setNativeProps(this._component, props);
306
+ }
307
+ else {
308
+ // eslint-disable-next-line no-unused-expressions
309
+ (_b = (_a = this._component) === null || _a === void 0 ? void 0 : _a.setNativeProps) === null || _b === void 0 ? void 0 : _b.call(_a, props);
310
+ }
352
311
  }
353
- }
354
- return false;
355
- }
356
-
357
- _detachPropUpdater() {
358
- const viewTag = findNodeHandle(this);
359
- NODE_MAPPING.delete(viewTag);
360
- if (NODE_MAPPING.size === 0) {
361
- ReanimatedEventEmitter.removeAllListeners('onReanimatedPropsChange');
362
- }
363
- }
364
-
365
- componentDidUpdate(prevProps) {
366
- this._attachProps(this.props);
367
- this._reattachNativeEvents(prevProps);
368
-
369
- this._propsAnimated && this._propsAnimated.setNativeView(this._component);
370
- this._attachAnimatedStyles();
371
- }
372
-
373
- _setComponentRef = setAndForwardRef({
374
- getForwardedRef: () => this.props.forwardedRef,
375
- setLocalRef: (ref) => {
376
- // TODO update config
377
- const tag = findNodeHandle(ref);
378
- if (
379
- (this.props.layout || this.props.entering || this.props.exiting) &&
380
- tag != null
381
- ) {
382
- let layout = this.props.layout ? this.props.layout : DefaultLayout;
383
- let entering = this.props.entering
384
- ? this.props.entering
385
- : DefaultEntering;
386
- let exiting = this.props.exiting
387
- ? this.props.exiting
388
- : DefaultExiting;
389
-
390
- if (layout.build) {
391
- layout = layout.build();
392
- }
393
-
394
- if (entering.build) {
395
- entering = entering.build();
396
- }
397
-
398
- if (exiting.build) {
399
- exiting = exiting.build();
400
- }
401
-
402
- const config = {
403
- layout,
404
- entering,
405
- exiting,
406
- sv: this.sv,
407
- };
408
- runOnUI(() => {
409
- 'worklet';
410
- global.LayoutAnimationRepository.registerConfig(tag, config);
411
- })();
312
+ _attachPropUpdater() {
313
+ const viewTag = findNodeHandle(this);
314
+ NODE_MAPPING.set(viewTag, this);
315
+ if (NODE_MAPPING.size === 1) {
316
+ ReanimatedEventEmitter.addListener('onReanimatedPropsChange', listener);
317
+ }
412
318
  }
413
-
414
- if (ref !== this._component) {
415
- this._component = ref;
319
+ _attachAnimatedStyles() {
320
+ var _a, _b, _c;
321
+ const styles = this.props.style
322
+ ? onlyAnimatedStyles(flattenArray(this.props.style))
323
+ : [];
324
+ const prevStyles = this._styles;
325
+ this._styles = styles;
326
+ const prevAnimatedProps = this._animatedProps;
327
+ this._animatedProps = this.props.animatedProps;
328
+ let viewTag;
329
+ let viewName;
330
+ if (Platform.OS === 'web') {
331
+ viewTag = findNodeHandle(this);
332
+ viewName = null;
333
+ }
334
+ else {
335
+ // hostInstance can be null for a component that doesn't render anything (render function returns null). Example: svg Stop: https://github.com/react-native-svg/react-native-svg/blob/develop/src/elements/Stop.tsx
336
+ const hostInstance = RNRenderer.findHostInstance_DEPRECATED(this);
337
+ if (!hostInstance) {
338
+ throw new Error('Cannot find host instance for this component. Maybe it renders nothing?');
339
+ }
340
+ // we can access view tag in the same way it's accessed here https://github.com/facebook/react/blob/e3f4eb7272d4ca0ee49f27577156b57eeb07cf73/packages/react-native-renderer/src/ReactFabric.js#L146
341
+ viewTag = hostInstance === null || hostInstance === void 0 ? void 0 : hostInstance._nativeTag;
342
+ /**
343
+ * RN uses viewConfig for components for storing different properties of the component(example: https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollView/ScrollViewViewConfig.js#L16).
344
+ * The name we're looking for is in the field named uiViewClassName.
345
+ */
346
+ viewName = (_a = hostInstance === null || hostInstance === void 0 ? void 0 : hostInstance.viewConfig) === null || _a === void 0 ? void 0 : _a.uiViewClassName;
347
+ // update UI props whitelist for this view
348
+ const hasReanimated2Props = ((_b = this.props.animatedProps) === null || _b === void 0 ? void 0 : _b.viewDescriptors) || styles.length;
349
+ if (hasReanimated2Props && (hostInstance === null || hostInstance === void 0 ? void 0 : hostInstance.viewConfig)) {
350
+ adaptViewConfig(hostInstance.viewConfig);
351
+ }
352
+ }
353
+ this._viewTag = viewTag;
354
+ // remove old styles
355
+ if (prevStyles) {
356
+ // in most of the cases, views have only a single animated style and it remains unchanged
357
+ const hasOneSameStyle = styles.length === 1 &&
358
+ prevStyles.length === 1 &&
359
+ isSameAnimatedStyle(styles[0], prevStyles[0]);
360
+ if (!hasOneSameStyle) {
361
+ // otherwise, remove each style that is not present in new styles
362
+ for (const prevStyle of prevStyles) {
363
+ const isPresent = styles.some((style) => isSameAnimatedStyle(style, prevStyle));
364
+ if (!isPresent) {
365
+ prevStyle.viewDescriptors.remove(viewTag);
366
+ }
367
+ }
368
+ }
369
+ }
370
+ styles.forEach((style) => {
371
+ style.viewDescriptors.add({ tag: viewTag, name: viewName });
372
+ if (isJest()) {
373
+ /**
374
+ * We need to connect Jest's TestObject instance whose contains just props object
375
+ * with the updateProps() function where we update the properties of the component.
376
+ * We can't update props object directly because TestObject contains a copy of props - look at render function:
377
+ * const props = this._filterNonAnimatedProps(this.props);
378
+ */
379
+ this.animatedStyle.value = Object.assign(Object.assign({}, this.animatedStyle.value), style.initial.value);
380
+ style.animatedStyle.current = this.animatedStyle;
381
+ }
382
+ });
383
+ // detach old animatedProps
384
+ if (prevAnimatedProps && prevAnimatedProps !== this.props.animatedProps) {
385
+ prevAnimatedProps.viewDescriptors.remove(viewTag);
386
+ }
387
+ // attach animatedProps property
388
+ if ((_c = this.props.animatedProps) === null || _c === void 0 ? void 0 : _c.viewDescriptors) {
389
+ this.props.animatedProps.viewDescriptors.add({
390
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
391
+ tag: viewTag,
392
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
393
+ name: viewName,
394
+ });
395
+ }
416
396
  }
417
-
418
- // TODO: Delete this after React Native also deletes this deprecation helper.
419
- if (ref != null && ref.getNode == null) {
420
- ref.getNode = () => {
421
- console.warn(
422
- '%s: Calling %s on the ref of an Animated component ' +
423
- 'is no longer necessary. You can now directly use the ref ' +
424
- 'instead. This method will be removed in a future release.',
425
- ref.constructor.name ?? '<<anonymous>>',
426
- 'getNode()'
427
- );
428
- return ref;
429
- };
397
+ _detachPropUpdater() {
398
+ const viewTag = findNodeHandle(this);
399
+ NODE_MAPPING.delete(viewTag);
400
+ if (NODE_MAPPING.size === 0) {
401
+ ReanimatedEventEmitter.removeAllListeners('onReanimatedPropsChange');
402
+ }
430
403
  }
431
- },
432
- });
433
-
434
- _filterNonAnimatedStyle(inputStyle) {
435
- const style = {};
436
- for (const key in inputStyle) {
437
- const value = inputStyle[key];
438
- if (!hasAnimatedNodes(value)) {
439
- style[key] = value;
440
- } else if (value instanceof AnimatedValue) {
441
- // if any style in animated component is set directly to the `Value` we set those styles to the first value of `Value` node in order
442
- // to avoid flash of default styles when `Value` is being asynchrounously sent via bridge and initialized in the native side.
443
- style[key] = value._startingValue;
404
+ componentDidUpdate(prevProps) {
405
+ this._attachProps(this.props);
406
+ this._reattachNativeEvents(prevProps);
407
+ this._propsAnimated &&
408
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
409
+ this._propsAnimated.setNativeView(this._component);
410
+ this._attachAnimatedStyles();
444
411
  }
445
- }
446
- return style;
447
- }
448
-
449
- _filterNonAnimatedProps(inputProps) {
450
- const props = {};
451
- for (const key in inputProps) {
452
- const value = inputProps[key];
453
- if (key === 'style') {
454
- const styles = flattenArray(value);
455
- const processedStyle = styles.map((style) => {
456
- if (style && style.viewDescriptors) {
457
- // this is how we recognize styles returned by useAnimatedStyle
458
- style.viewsRef.add(this);
459
- return style.initial.value;
460
- } else {
461
- return style;
412
+ _filterNonAnimatedStyle(inputStyle) {
413
+ const style = {};
414
+ for (const key in inputStyle) {
415
+ const value = inputStyle[key];
416
+ if (!hasAnimatedNodes(value)) {
417
+ style[key] = value;
418
+ }
419
+ else if (value instanceof AnimatedValue) {
420
+ // if any style in animated component is set directly to the `Value` we set those styles to the first value of `Value` node in order
421
+ // to avoid flash of default styles when `Value` is being asynchrounously sent via bridge and initialized in the native side.
422
+ style[key] = value._startingValue;
423
+ }
462
424
  }
463
- });
464
- props[key] = this._filterNonAnimatedStyle(
465
- StyleSheet.flatten(processedStyle)
466
- );
467
- } else if (key === 'animatedProps') {
468
- Object.keys(value.initial.value).forEach((key) => {
469
- props[key] = value.initial.value[key];
470
- value.viewsRef.add(this);
471
- });
472
- } else if (value instanceof AnimatedEvent) {
473
- // we cannot filter out event listeners completely as some components
474
- // rely on having a callback registered in order to generate events
475
- // alltogether. Therefore we provide a dummy callback here to allow
476
- // native event dispatcher to hijack events.
477
- props[key] = dummyListener;
478
- } else if (
479
- value?.current &&
480
- value.current instanceof WorkletEventHandler
481
- ) {
482
- if (value.current.eventNames.length > 0) {
483
- value.current.eventNames.forEach((eventName) => {
484
- props[eventName] = value.current.listeners
485
- ? value.current.listeners[eventName]
486
- : dummyListener;
425
+ return style;
426
+ }
427
+ _filterNonAnimatedProps(inputProps) {
428
+ const props = {};
429
+ for (const key in inputProps) {
430
+ const value = inputProps[key];
431
+ if (key === 'style') {
432
+ const styleProp = inputProps.style;
433
+ const styles = flattenArray(styleProp !== null && styleProp !== void 0 ? styleProp : []);
434
+ const processedStyle = styles.map((style) => {
435
+ if (style && style.viewDescriptors) {
436
+ // this is how we recognize styles returned by useAnimatedStyle
437
+ style.viewsRef.add(this);
438
+ if (this._isFirstRender) {
439
+ return Object.assign(Object.assign({}, style.initial.value), initialUpdaterRun(style.initial.updater));
440
+ }
441
+ else {
442
+ return style.initial.value;
443
+ }
444
+ }
445
+ else {
446
+ return style;
447
+ }
448
+ });
449
+ props[key] = this._filterNonAnimatedStyle(StyleSheet.flatten(processedStyle));
450
+ }
451
+ else if (key === 'animatedProps') {
452
+ const animatedProp = inputProps.animatedProps;
453
+ if (animatedProp.initial !== undefined) {
454
+ Object.keys(animatedProp.initial.value).forEach((key) => {
455
+ var _a, _b;
456
+ props[key] = (_a = animatedProp.initial) === null || _a === void 0 ? void 0 : _a.value[key];
457
+ (_b = animatedProp.viewsRef) === null || _b === void 0 ? void 0 : _b.add(this);
458
+ });
459
+ }
460
+ }
461
+ else if (value instanceof AnimatedEvent) {
462
+ // we cannot filter out event listeners completely as some components
463
+ // rely on having a callback registered in order to generate events
464
+ // alltogether. Therefore we provide a dummy callback here to allow
465
+ // native event dispatcher to hijack events.
466
+ props[key] = dummyListener;
467
+ }
468
+ else if (has('current', value) &&
469
+ value.current instanceof WorkletEventHandler) {
470
+ if (value.current.eventNames.length > 0) {
471
+ value.current.eventNames.forEach((eventName) => {
472
+ props[eventName] = has('listeners', value.current)
473
+ ? value.current.listeners[eventName]
474
+ : dummyListener;
475
+ });
476
+ }
477
+ else {
478
+ props[key] = dummyListener;
479
+ }
480
+ }
481
+ else if (!(value instanceof AnimatedNode)) {
482
+ if (key !== 'onGestureHandlerStateChange' || !isChromeDebugger()) {
483
+ props[key] = value;
484
+ }
485
+ }
486
+ else if (value instanceof AnimatedValue) {
487
+ // if any prop in animated component is set directly to the `Value` we set those props to the first value of `Value` node in order
488
+ // to avoid default values for a short moment when `Value` is being asynchrounously sent via bridge and initialized in the native side.
489
+ props[key] = value._startingValue;
490
+ }
491
+ }
492
+ return props;
493
+ }
494
+ render() {
495
+ const props = this._filterNonAnimatedProps(this.props);
496
+ if (isJest()) {
497
+ props.animatedStyle = this.animatedStyle;
498
+ }
499
+ if (this._isFirstRender) {
500
+ this._isFirstRender = false;
501
+ }
502
+ const platformProps = Platform.select({
503
+ web: {},
504
+ default: { collapsable: false },
487
505
  });
488
- } else {
489
- props[key] = dummyListener;
490
- }
491
- } else if (!(value instanceof AnimatedNode)) {
492
- if (key !== 'onGestureHandlerStateChange' || !isChromeDebugger()) {
493
- props[key] = value;
494
- }
495
- } else if (value instanceof AnimatedValue) {
496
- // if any prop in animated component is set directly to the `Value` we set those props to the first value of `Value` node in order
497
- // to avoid default values for a short moment when `Value` is being asynchrounously sent via bridge and initialized in the native side.
498
- props[key] = value._startingValue;
506
+ return (<Component {...props} ref={this._setComponentRef} {...platformProps}/>);
499
507
  }
500
- }
501
- return props;
502
- }
503
-
504
- render() {
505
- const props = this._filterNonAnimatedProps(this.props);
506
- if (isJest()) {
507
- props.animatedStyle = this.animatedStyle;
508
- }
509
-
510
- const platformProps = Platform.select({
511
- web: {},
512
- default: { collapsable: false },
513
- });
514
- return (
515
- <Component {...props} ref={this._setComponentRef} {...platformProps} />
516
- );
517
508
  }
518
- }
519
-
520
- AnimatedComponent.displayName = `AnimatedComponent(${
521
- Component.displayName || Component.name || 'Component'
522
- })`;
523
-
524
- return React.forwardRef(function AnimatedComponentWrapper(props, ref) {
525
- return (
526
- <AnimatedComponent
527
- {...props}
528
- {...(ref == null ? null : { forwardedRef: ref })}
529
- />
530
- );
531
- });
509
+ AnimatedComponent.displayName = `AnimatedComponent(${Component.displayName || Component.name || 'Component'})`;
510
+ return React.forwardRef((props, ref) => {
511
+ return (<AnimatedComponent {...props} {...(ref === null ? null : { forwardedRef: ref })}/>);
512
+ });
532
513
  }