react-native-reanimated 2.3.0-beta.1 → 2.3.0

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