react-native-reanimated 3.0.0-rc.7 → 3.0.0-rc.8

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 (177) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +32 -37
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +4 -3
  3. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +76 -0
  4. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +41 -0
  5. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +161 -165
  6. package/Common/cpp/NativeModules/NativeReanimatedModule.h +36 -34
  7. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +22 -34
  8. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +13 -14
  9. package/Common/cpp/SharedItems/RuntimeManager.h +1 -34
  10. package/Common/cpp/SharedItems/Shareables.cpp +142 -0
  11. package/Common/cpp/SharedItems/Shareables.h +455 -0
  12. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +6 -0
  13. package/Common/cpp/Tools/RuntimeDecorator.cpp +54 -26
  14. package/Common/cpp/Tools/RuntimeDecorator.h +11 -2
  15. package/Common/cpp/Tools/Scheduler.cpp +10 -0
  16. package/Common/cpp/Tools/SingleInstanceChecker.h +1 -1
  17. package/android/src/main/cpp/LayoutAnimations.cpp +6 -16
  18. package/android/src/main/cpp/LayoutAnimations.h +4 -4
  19. package/android/src/main/cpp/NativeProxy.cpp +50 -63
  20. package/ios/native/NativeProxy.mm +26 -42
  21. package/lib/commonjs/createAnimatedComponent.js +7 -11
  22. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  23. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  24. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  25. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +27 -55
  26. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
  27. package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -3
  28. package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
  29. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  30. package/lib/commonjs/reanimated2/commonTypes.js +7 -0
  31. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  32. package/lib/commonjs/reanimated2/core.js +111 -209
  33. package/lib/commonjs/reanimated2/core.js.map +1 -1
  34. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  35. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +15 -9
  36. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  37. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +18 -8
  38. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  39. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +27 -36
  40. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  41. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +24 -50
  42. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  43. package/lib/commonjs/reanimated2/hook/useSharedValue.js +3 -2
  44. package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
  45. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  46. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  47. package/lib/commonjs/reanimated2/jestUtils.js +8 -33
  48. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  49. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +16 -100
  50. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  51. package/lib/commonjs/reanimated2/js-reanimated/index.js +5 -0
  52. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  53. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  54. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  55. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +91 -0
  56. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  57. package/lib/commonjs/reanimated2/layoutReanimation/index.js +1 -1
  58. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  59. package/lib/commonjs/reanimated2/mappers.js +186 -0
  60. package/lib/commonjs/reanimated2/mappers.js.map +1 -0
  61. package/lib/commonjs/reanimated2/mutables.js +173 -0
  62. package/lib/commonjs/reanimated2/mutables.js.map +1 -0
  63. package/lib/commonjs/reanimated2/shareables.js +153 -0
  64. package/lib/commonjs/reanimated2/shareables.js.map +1 -0
  65. package/lib/commonjs/reanimated2/threads.js +58 -0
  66. package/lib/commonjs/reanimated2/threads.js.map +1 -0
  67. package/lib/commonjs/reanimated2/time.js +55 -0
  68. package/lib/commonjs/reanimated2/time.js.map +1 -0
  69. package/lib/commonjs/reanimated2/valueSetter.js +81 -0
  70. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -0
  71. package/lib/module/createAnimatedComponent.js +7 -12
  72. package/lib/module/createAnimatedComponent.js.map +1 -1
  73. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  74. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  75. package/lib/module/reanimated2/ViewDescriptorsSet.js +27 -53
  76. package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
  77. package/lib/module/reanimated2/WorkletEventHandler.js +4 -3
  78. package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
  79. package/lib/module/reanimated2/animation/util.js.map +1 -1
  80. package/lib/module/reanimated2/commonTypes.js +7 -0
  81. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  82. package/lib/module/reanimated2/core.js +66 -188
  83. package/lib/module/reanimated2/core.js.map +1 -1
  84. package/lib/module/reanimated2/globals.d.js.map +1 -1
  85. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +16 -6
  86. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  87. package/lib/module/reanimated2/hook/useAnimatedRef.js +17 -8
  88. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  89. package/lib/module/reanimated2/hook/useAnimatedSensor.js +29 -34
  90. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  91. package/lib/module/reanimated2/hook/useAnimatedStyle.js +26 -52
  92. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  93. package/lib/module/reanimated2/hook/useSharedValue.js +3 -2
  94. package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
  95. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  96. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  97. package/lib/module/reanimated2/jestUtils.js +8 -31
  98. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  99. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +16 -95
  100. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  101. package/lib/module/reanimated2/js-reanimated/index.js +5 -0
  102. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  103. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  104. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  105. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +84 -0
  106. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  107. package/lib/module/reanimated2/layoutReanimation/index.js +1 -1
  108. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  109. package/lib/module/reanimated2/mappers.js +173 -0
  110. package/lib/module/reanimated2/mappers.js.map +1 -0
  111. package/lib/module/reanimated2/mutables.js +149 -0
  112. package/lib/module/reanimated2/mutables.js.map +1 -0
  113. package/lib/module/reanimated2/shareables.js +133 -0
  114. package/lib/module/reanimated2/shareables.js.map +1 -0
  115. package/lib/module/reanimated2/threads.js +45 -0
  116. package/lib/module/reanimated2/threads.js.map +1 -0
  117. package/lib/module/reanimated2/time.js +37 -0
  118. package/lib/module/reanimated2/time.js.map +1 -0
  119. package/lib/module/reanimated2/valueSetter.js +66 -0
  120. package/lib/module/reanimated2/valueSetter.js.map +1 -0
  121. package/package.json +1 -1
  122. package/plugin.js +31 -15
  123. package/src/createAnimatedComponent.tsx +8 -24
  124. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +34 -53
  125. package/src/reanimated2/ViewDescriptorsSet.ts +30 -69
  126. package/src/reanimated2/WorkletEventHandler.ts +4 -11
  127. package/src/reanimated2/animation/util.ts +1 -0
  128. package/src/reanimated2/commonTypes.ts +29 -4
  129. package/src/reanimated2/core.ts +103 -230
  130. package/src/reanimated2/globals.d.ts +26 -26
  131. package/src/reanimated2/hook/useAnimatedKeyboard.ts +18 -9
  132. package/src/reanimated2/hook/useAnimatedRef.ts +27 -9
  133. package/src/reanimated2/hook/useAnimatedSensor.ts +33 -31
  134. package/src/reanimated2/hook/useAnimatedStyle.ts +26 -64
  135. package/src/reanimated2/hook/useSharedValue.ts +6 -3
  136. package/src/reanimated2/hook/utils.ts +1 -1
  137. package/src/reanimated2/interpolateColor.ts +2 -2
  138. package/src/reanimated2/jestUtils.ts +14 -29
  139. package/src/reanimated2/js-reanimated/JSReanimated.ts +19 -93
  140. package/src/reanimated2/js-reanimated/index.ts +4 -0
  141. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +7 -0
  142. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  143. package/src/reanimated2/layoutReanimation/animationsManager.ts +94 -0
  144. package/src/reanimated2/layoutReanimation/index.ts +1 -1
  145. package/src/reanimated2/mappers.ts +179 -0
  146. package/src/reanimated2/mutables.ts +151 -0
  147. package/src/reanimated2/shareables.ts +121 -0
  148. package/src/reanimated2/threads.ts +46 -0
  149. package/src/reanimated2/time.ts +30 -0
  150. package/src/reanimated2/valueSetter.ts +64 -0
  151. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +0 -127
  152. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +0 -56
  153. package/Common/cpp/Registries/MapperRegistry.cpp +0 -147
  154. package/Common/cpp/Registries/MapperRegistry.h +0 -29
  155. package/Common/cpp/Registries/WorkletsCache.cpp +0 -45
  156. package/Common/cpp/Registries/WorkletsCache.h +0 -24
  157. package/Common/cpp/SharedItems/FrozenObject.cpp +0 -35
  158. package/Common/cpp/SharedItems/FrozenObject.h +0 -36
  159. package/Common/cpp/SharedItems/HostFunctionHandler.h +0 -28
  160. package/Common/cpp/SharedItems/MutableValue.cpp +0 -134
  161. package/Common/cpp/SharedItems/MutableValue.h +0 -54
  162. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +0 -47
  163. package/Common/cpp/SharedItems/MutableValueSetterProxy.h +0 -25
  164. package/Common/cpp/SharedItems/RemoteObject.cpp +0 -45
  165. package/Common/cpp/SharedItems/RemoteObject.h +0 -35
  166. package/Common/cpp/SharedItems/ShareableValue.cpp +0 -529
  167. package/Common/cpp/SharedItems/ShareableValue.h +0 -63
  168. package/Common/cpp/SharedItems/ValueWrapper.h +0 -183
  169. package/Common/cpp/Tools/JSIStoreValueUser.cpp +0 -55
  170. package/Common/cpp/Tools/JSIStoreValueUser.h +0 -37
  171. package/Common/cpp/Tools/Mapper.cpp +0 -86
  172. package/Common/cpp/Tools/Mapper.h +0 -51
  173. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -58
  174. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  175. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -52
  176. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  177. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +0 -49
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["globals.d.ts"],"sourcesContent":["import type {\n AnimatedStyle,\n StyleProps,\n MeasuredDimensions,\n} from './commonTypes';\nimport type { ReanimatedConsole } from './core';\nimport type { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';\nimport type { ShadowNodeWrapper } from './hook/commonTypes';\nimport type { NativeReanimated } from './NativeReanimated/NativeReanimated';\n\ndeclare global {\n const _WORKLET: boolean;\n const _IS_FABRIC: boolean;\n const _REANIMATED_VERSION_CPP: string;\n const _frameTimestamp: number | null;\n const _eventTimestamp: number;\n const __reanimatedModuleProxy: NativeReanimated;\n const _setGlobalConsole: (console?: ReanimatedConsole) => void;\n const _log: (s: string) => void;\n const _getCurrentTime: () => number;\n const _stopObservingProgress: (\n tag: number,\n cancelled: boolean,\n removeView: boolean\n ) => void;\n const _startObservingProgress: (\n tag: number,\n viewSharedValue: { value: unknown; _value: unknown },\n type: string\n ) => void;\n const _setGestureState: (handlerTag: number, newState: number) => void;\n const _updatePropsPaper: (\n tag: number,\n name: string,\n updates: StyleProps | AnimatedStyle\n ) => void;\n const _updatePropsFabric: (\n shadowNodeWrapper: ShadowNodeWrapper,\n props: StyleProps | AnimatedStyle\n ) => void;\n const _removeShadowNodeFromRegistry: (\n shadowNodeWrapper: ShadowNodeWrapper\n ) => void;\n const _measure: (viewTag: number) => MeasuredDimensions;\n const _scrollTo: (\n viewTag: number,\n x: number,\n y: number,\n animated: boolean\n ) => void;\n const _dispatchCommand: (\n shadowNodeWrapper: ShadowNodeWrapper,\n commandName: string,\n args: Array<unknown>\n ) => void;\n const _chronoNow: () => number;\n const performance: { now: () => number };\n const LayoutAnimationRepository: {\n configs: Record<string, unknown>;\n registerConfig(tag: number, config: Record<string, unknown>): void;\n removeConfig(tag: number): void;\n startAnimationForTag(tag: number, type: string, yogaValues: unknown): void;\n };\n const ReanimatedDataMock: {\n now: () => number;\n };\n const _frameCallbackRegistry: FrameCallbackRegistryUI;\n\n namespace NodeJS {\n interface Global {\n _WORKLET: boolean;\n _IS_FABRIC: boolean;\n _REANIMATED_VERSION_CPP: string;\n _frameTimestamp: number | null;\n _eventTimestamp: number;\n __reanimatedModuleProxy: NativeReanimated;\n _setGlobalConsole: (console?: ReanimatedConsole) => void;\n _log: (s: string) => void;\n _getCurrentTime: () => number;\n _stopObservingProgress: (tag: number, flag: boolean) => void;\n _startObservingProgress: (\n tag: number,\n flag: { value: boolean; _value: boolean }\n ) => void;\n _setGestureState: (handlerTag: number, newState: number) => void;\n _updatePropsPaper: (\n tag: number,\n name: string,\n updates: StyleProps | AnimatedStyle\n ) => void;\n _updatePropsFabric: (\n shadowNodeWrapper: ShadowNodeWrapper,\n props: StyleProps | AnimatedStyle\n ) => void;\n _removeShadowNodeFromRegistry: (\n shadowNodeWrapper: ShadowNodeWrapper\n ) => void;\n _measure: (viewTag: number) => MeasuredDimensions;\n _scrollTo: (\n viewTag: number,\n x: number,\n y: number,\n animated: boolean\n ) => void;\n _dispatchCommand: (\n shadowNodeWrapper: ShadowNodeWrapper,\n commandName: string,\n args: Array<unknown>\n ) => void;\n _chronoNow: () => number;\n performance: { now: () => number };\n LayoutAnimationRepository: {\n startAnimationForTag(\n tag: number,\n type: string,\n yogaValues: Record<string, number>,\n config: LayoutAnimationFunction | Keyframe,\n viewSharedValue: { value: unknown; _value: unknown }\n ): void;\n };\n ReanimatedDataMock: {\n now: () => number;\n };\n _frameCallbackRegistry: FrameCallbackRegistryUI;\n }\n }\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["globals.d.ts"],"sourcesContent":["import type {\n AnimatedStyle,\n StyleProps,\n MeasuredDimensions,\n MapperRegistry,\n ShareableRef,\n ShareableSyncDataHolderRef,\n} from './commonTypes';\nimport type { ReanimatedConsole } from './core';\nimport type { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';\nimport type { ShadowNodeWrapper } from './hook/commonTypes';\nimport { LayoutAnimationStartFunction } from './layoutReanimation';\nimport type { NativeReanimated } from './NativeReanimated/NativeReanimated';\n\ndeclare global {\n const _WORKLET: boolean;\n const _IS_FABRIC: boolean;\n const _REANIMATED_VERSION_CPP: string;\n const _frameTimestamp: number | null;\n const _eventTimestamp: number;\n const __reanimatedModuleProxy: NativeReanimated;\n const _setGlobalConsole: (console?: ReanimatedConsole) => void;\n const _log: (s: string) => void;\n const _getCurrentTime: () => number;\n const _getTimestamp: () => number;\n const _notifyAboutProgress: (tag: number, value: number) => void;\n const _notifyAboutEnd: (\n tag: number,\n finished: boolean,\n removeView: boolean\n ) => void;\n const _setGestureState: (handlerTag: number, newState: number) => void;\n const _makeShareableClone: (value: any) => any;\n const _updateDataSynchronously: (\n dataHolder: ShareableSyncDataHolderRef,\n data: ShareableRef\n ) => void;\n const _scheduleOnJS: (fun: ShareableRef, args?: ShareableRef) => void;\n const _updatePropsPaper: (\n tag: number,\n name: string,\n updates: StyleProps | AnimatedStyle\n ) => void;\n const _updatePropsFabric: (\n shadowNodeWrapper: ShadowNodeWrapper,\n props: StyleProps | AnimatedStyle\n ) => void;\n const _removeShadowNodeFromRegistry: (\n shadowNodeWrapper: ShadowNodeWrapper\n ) => void;\n const _measure: (viewTag: number) => MeasuredDimensions;\n const _scrollTo: (\n viewTag: number,\n x: number,\n y: number,\n animated: boolean\n ) => void;\n const _dispatchCommand: (\n shadowNodeWrapper: ShadowNodeWrapper,\n commandName: string,\n args: Array<unknown>\n ) => void;\n const _chronoNow: () => number;\n const performance: { now: () => number };\n const ReanimatedDataMock: {\n now: () => number;\n };\n const _frameCallbackRegistry: FrameCallbackRegistryUI;\n\n namespace NodeJS {\n interface Global {\n _WORKLET: boolean;\n _IS_FABRIC: boolean;\n _REANIMATED_VERSION_CPP: string;\n _frameTimestamp: number | null;\n _eventTimestamp: number;\n __reanimatedModuleProxy: NativeReanimated;\n _setGlobalConsole: (console?: ReanimatedConsole) => void;\n _log: (s: string) => void;\n _getCurrentTime: () => number;\n _getTimestamp: () => number;\n _setGestureState: (handlerTag: number, newState: number) => void;\n _makeShareableClone: (value: any) => any;\n _updateDataSynchronously: (\n ShareableSyncDataHolderRef,\n ShareableRef\n ) => void;\n _scheduleOnJS: (fun: ShareableRef, args?: ShareableRef) => void;\n _updatePropsPaper: (\n tag: number,\n name: string,\n updates: StyleProps | AnimatedStyle\n ) => void;\n _updatePropsFabric: (\n shadowNodeWrapper: ShadowNodeWrapper,\n props: StyleProps | AnimatedStyle\n ) => void;\n _removeShadowNodeFromRegistry: (\n shadowNodeWrapper: ShadowNodeWrapper\n ) => void;\n _measure: (viewTag: number) => MeasuredDimensions;\n _scrollTo: (\n viewTag: number,\n x: number,\n y: number,\n animated: boolean\n ) => void;\n _dispatchCommand: (\n shadowNodeWrapper: ShadowNodeWrapper,\n commandName: string,\n args: Array<unknown>\n ) => void;\n _chronoNow: () => number;\n performance: { now: () => number };\n LayoutAnimationsManager: {\n start: LayoutAnimationStartFunction;\n };\n ReanimatedDataMock: {\n now: () => number;\n };\n _frameCallbackRegistry: FrameCallbackRegistryUI;\n __workletsCache?: Map<string, (...args: any[]) => any>;\n __handleCache?: WeakMap<any, any>;\n __mapperRegistry?: MapperRegistry;\n }\n }\n}\n"],"mappings":""}
@@ -1,6 +1,5 @@
1
1
  import { useEffect, useRef } from 'react';
2
- import NativeReanimated from '../NativeReanimated';
3
- import { makeMutable } from '../core';
2
+ import { makeMutable, subscribeForKeyboardEvents, unsubscribeFromKeyboardEvents } from '../core';
4
3
  import { KeyboardState } from '../commonTypes';
5
4
  export function useAnimatedKeyboard() {
6
5
  const ref = useRef(null);
@@ -12,20 +11,31 @@ export function useAnimatedKeyboard() {
12
11
  state: makeMutable(KeyboardState.UNKNOWN),
13
12
  height: makeMutable(0)
14
13
  };
15
- listenerId.current = NativeReanimated.subscribeForKeyboardEvents(keyboardEventData);
14
+ listenerId.current = subscribeForKeyboardEvents((state, height) => {
15
+ 'worklet';
16
+
17
+ keyboardEventData.state.value = state;
18
+ keyboardEventData.height.value = height;
19
+ });
16
20
  ref.current = keyboardEventData;
17
21
  isSubscribed.current = true;
18
22
  }
19
23
 
20
24
  useEffect(() => {
21
25
  if (isSubscribed.current === false && ref.current !== null) {
22
- // subscribe again after Fast Refresh
23
- listenerId.current = NativeReanimated.subscribeForKeyboardEvents(ref.current);
26
+ const keyboardEventData = ref.current; // subscribe again after Fast Refresh
27
+
28
+ listenerId.current = subscribeForKeyboardEvents((state, height) => {
29
+ 'worklet';
30
+
31
+ keyboardEventData.state.value = state;
32
+ keyboardEventData.height.value = height;
33
+ });
24
34
  isSubscribed.current = true;
25
35
  }
26
36
 
27
37
  return () => {
28
- NativeReanimated.unsubscribeFromKeyboardEvents(listenerId.current);
38
+ unsubscribeFromKeyboardEvents(listenerId.current);
29
39
  isSubscribed.current = false;
30
40
  };
31
41
  }, []);
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","NativeReanimated","makeMutable","KeyboardState","useAnimatedKeyboard","ref","listenerId","isSubscribed","current","keyboardEventData","state","UNKNOWN","height","subscribeForKeyboardEvents","unsubscribeFromKeyboardEvents"],"sources":["useAnimatedKeyboard.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport NativeReanimated from '../NativeReanimated';\nimport { makeMutable } from '../core';\nimport { AnimatedKeyboardInfo, KeyboardState } from '../commonTypes';\n\nexport function useAnimatedKeyboard(): AnimatedKeyboardInfo {\n const ref = useRef<AnimatedKeyboardInfo | null>(null);\n const listenerId = useRef<number>(-1);\n const isSubscribed = useRef<boolean>(false);\n\n if (ref.current === null) {\n const keyboardEventData: AnimatedKeyboardInfo = {\n state: makeMutable(KeyboardState.UNKNOWN),\n height: makeMutable(0),\n };\n listenerId.current =\n NativeReanimated.subscribeForKeyboardEvents(keyboardEventData);\n ref.current = keyboardEventData;\n isSubscribed.current = true;\n }\n useEffect(() => {\n if (isSubscribed.current === false && ref.current !== null) {\n // subscribe again after Fast Refresh\n listenerId.current = NativeReanimated.subscribeForKeyboardEvents(\n ref.current\n );\n isSubscribed.current = true;\n }\n return () => {\n NativeReanimated.unsubscribeFromKeyboardEvents(listenerId.current);\n isSubscribed.current = false;\n };\n }, []);\n return ref.current;\n}\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,OAAOC,gBAAP,MAA6B,qBAA7B;AACA,SAASC,WAAT,QAA4B,SAA5B;AACA,SAA+BC,aAA/B,QAAoD,gBAApD;AAEA,OAAO,SAASC,mBAAT,GAAqD;EAC1D,MAAMC,GAAG,GAAGL,MAAM,CAA8B,IAA9B,CAAlB;EACA,MAAMM,UAAU,GAAGN,MAAM,CAAS,CAAC,CAAV,CAAzB;EACA,MAAMO,YAAY,GAAGP,MAAM,CAAU,KAAV,CAA3B;;EAEA,IAAIK,GAAG,CAACG,OAAJ,KAAgB,IAApB,EAA0B;IACxB,MAAMC,iBAAuC,GAAG;MAC9CC,KAAK,EAAER,WAAW,CAACC,aAAa,CAACQ,OAAf,CAD4B;MAE9CC,MAAM,EAAEV,WAAW,CAAC,CAAD;IAF2B,CAAhD;IAIAI,UAAU,CAACE,OAAX,GACEP,gBAAgB,CAACY,0BAAjB,CAA4CJ,iBAA5C,CADF;IAEAJ,GAAG,CAACG,OAAJ,GAAcC,iBAAd;IACAF,YAAY,CAACC,OAAb,GAAuB,IAAvB;EACD;;EACDT,SAAS,CAAC,MAAM;IACd,IAAIQ,YAAY,CAACC,OAAb,KAAyB,KAAzB,IAAkCH,GAAG,CAACG,OAAJ,KAAgB,IAAtD,EAA4D;MAC1D;MACAF,UAAU,CAACE,OAAX,GAAqBP,gBAAgB,CAACY,0BAAjB,CACnBR,GAAG,CAACG,OADe,CAArB;MAGAD,YAAY,CAACC,OAAb,GAAuB,IAAvB;IACD;;IACD,OAAO,MAAM;MACXP,gBAAgB,CAACa,6BAAjB,CAA+CR,UAAU,CAACE,OAA1D;MACAD,YAAY,CAACC,OAAb,GAAuB,KAAvB;IACD,CAHD;EAID,CAZQ,EAYN,EAZM,CAAT;EAaA,OAAOH,GAAG,CAACG,OAAX;AACD"}
1
+ {"version":3,"names":["useEffect","useRef","makeMutable","subscribeForKeyboardEvents","unsubscribeFromKeyboardEvents","KeyboardState","useAnimatedKeyboard","ref","listenerId","isSubscribed","current","keyboardEventData","state","UNKNOWN","height","value"],"sources":["useAnimatedKeyboard.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport {\n makeMutable,\n subscribeForKeyboardEvents,\n unsubscribeFromKeyboardEvents,\n} from '../core';\nimport { AnimatedKeyboardInfo, KeyboardState } from '../commonTypes';\n\nexport function useAnimatedKeyboard(): AnimatedKeyboardInfo {\n const ref = useRef<AnimatedKeyboardInfo | null>(null);\n const listenerId = useRef<number>(-1);\n const isSubscribed = useRef<boolean>(false);\n\n if (ref.current === null) {\n const keyboardEventData: AnimatedKeyboardInfo = {\n state: makeMutable<KeyboardState>(KeyboardState.UNKNOWN),\n height: makeMutable(0),\n };\n listenerId.current = subscribeForKeyboardEvents((state, height) => {\n 'worklet';\n keyboardEventData.state.value = state;\n keyboardEventData.height.value = height;\n });\n ref.current = keyboardEventData;\n isSubscribed.current = true;\n }\n useEffect(() => {\n if (isSubscribed.current === false && ref.current !== null) {\n const keyboardEventData = ref.current;\n // subscribe again after Fast Refresh\n listenerId.current = subscribeForKeyboardEvents((state, height) => {\n 'worklet';\n keyboardEventData.state.value = state;\n keyboardEventData.height.value = height;\n });\n isSubscribed.current = true;\n }\n return () => {\n unsubscribeFromKeyboardEvents(listenerId.current);\n isSubscribed.current = false;\n };\n }, []);\n return ref.current;\n}\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,SACEC,WADF,EAEEC,0BAFF,EAGEC,6BAHF,QAIO,SAJP;AAKA,SAA+BC,aAA/B,QAAoD,gBAApD;AAEA,OAAO,SAASC,mBAAT,GAAqD;EAC1D,MAAMC,GAAG,GAAGN,MAAM,CAA8B,IAA9B,CAAlB;EACA,MAAMO,UAAU,GAAGP,MAAM,CAAS,CAAC,CAAV,CAAzB;EACA,MAAMQ,YAAY,GAAGR,MAAM,CAAU,KAAV,CAA3B;;EAEA,IAAIM,GAAG,CAACG,OAAJ,KAAgB,IAApB,EAA0B;IACxB,MAAMC,iBAAuC,GAAG;MAC9CC,KAAK,EAAEV,WAAW,CAAgBG,aAAa,CAACQ,OAA9B,CAD4B;MAE9CC,MAAM,EAAEZ,WAAW,CAAC,CAAD;IAF2B,CAAhD;IAIAM,UAAU,CAACE,OAAX,GAAqBP,0BAA0B,CAAC,CAACS,KAAD,EAAQE,MAAR,KAAmB;MACjE;;MACAH,iBAAiB,CAACC,KAAlB,CAAwBG,KAAxB,GAAgCH,KAAhC;MACAD,iBAAiB,CAACG,MAAlB,CAAyBC,KAAzB,GAAiCD,MAAjC;IACD,CAJ8C,CAA/C;IAKAP,GAAG,CAACG,OAAJ,GAAcC,iBAAd;IACAF,YAAY,CAACC,OAAb,GAAuB,IAAvB;EACD;;EACDV,SAAS,CAAC,MAAM;IACd,IAAIS,YAAY,CAACC,OAAb,KAAyB,KAAzB,IAAkCH,GAAG,CAACG,OAAJ,KAAgB,IAAtD,EAA4D;MAC1D,MAAMC,iBAAiB,GAAGJ,GAAG,CAACG,OAA9B,CAD0D,CAE1D;;MACAF,UAAU,CAACE,OAAX,GAAqBP,0BAA0B,CAAC,CAACS,KAAD,EAAQE,MAAR,KAAmB;QACjE;;QACAH,iBAAiB,CAACC,KAAlB,CAAwBG,KAAxB,GAAgCH,KAAhC;QACAD,iBAAiB,CAACG,MAAlB,CAAyBC,KAAzB,GAAiCD,MAAjC;MACD,CAJ8C,CAA/C;MAKAL,YAAY,CAACC,OAAb,GAAuB,IAAvB;IACD;;IACD,OAAO,MAAM;MACXN,6BAA6B,CAACI,UAAU,CAACE,OAAZ,CAA7B;MACAD,YAAY,CAACC,OAAb,GAAuB,KAAvB;IACD,CAHD;EAID,CAfQ,EAeN,EAfM,CAAT;EAgBA,OAAOH,GAAG,CAACG,OAAX;AACD"}
@@ -2,28 +2,37 @@ import { useRef } from 'react';
2
2
  import { useSharedValue } from './useSharedValue';
3
3
  import { getTag } from '../NativeMethods';
4
4
  import { getShadowNodeWrapperFromHostInstance } from '../fabricUtils';
5
+ import { makeShareableCloneRecursive, makeShareableShadowNodeWrapper, registerShareableMapping } from '../shareables';
6
+
7
+ function getShareableShadowNodeFromComponent(component) {
8
+ return makeShareableShadowNodeWrapper(getShadowNodeWrapperFromHostInstance(component));
9
+ }
10
+
11
+ const getTagValueFunction = global._IS_FABRIC ? getShareableShadowNodeFromComponent : getTag;
5
12
  export function useAnimatedRef() {
6
13
  const tag = useSharedValue(-1);
7
14
  const ref = useRef();
8
- const isFabric = global._IS_FABRIC;
9
15
 
10
16
  if (!ref.current) {
11
17
  const fun = component => {
12
- 'worklet'; // enters when ref is set by attaching to a component
13
-
18
+ // enters when ref is set by attaching to a component
14
19
  if (component) {
15
- tag.value = isFabric ? getShadowNodeWrapperFromHostInstance(component) : getTag(component);
20
+ tag.value = getTagValueFunction(component);
16
21
  fun.current = component;
17
22
  }
18
23
 
19
24
  return tag.value;
20
25
  };
21
26
 
22
- Object.defineProperty(fun, 'current', {
23
- value: null,
24
- writable: true,
25
- enumerable: false
27
+ fun.current = null;
28
+ const remoteRef = makeShareableCloneRecursive({
29
+ __init: () => {
30
+ 'worklet';
31
+
32
+ return () => tag.value;
33
+ }
26
34
  });
35
+ registerShareableMapping(fun, remoteRef);
27
36
  ref.current = fun;
28
37
  }
29
38
 
@@ -1 +1 @@
1
- {"version":3,"names":["useRef","useSharedValue","getTag","getShadowNodeWrapperFromHostInstance","useAnimatedRef","tag","ref","isFabric","global","_IS_FABRIC","current","fun","component","value","Object","defineProperty","writable","enumerable"],"sources":["useAnimatedRef.ts"],"sourcesContent":["import { Component, useRef } from 'react';\nimport { useSharedValue } from './useSharedValue';\nimport { RefObjectFunction } from './commonTypes';\nimport { ShadowNodeWrapper } from '../commonTypes';\nimport { getTag } from '../NativeMethods';\nimport { getShadowNodeWrapperFromHostInstance } from '../fabricUtils';\n\nexport function useAnimatedRef<T extends Component>(): RefObjectFunction<T> {\n const tag = useSharedValue<number | ShadowNodeWrapper | null>(-1);\n const ref = useRef<RefObjectFunction<T>>();\n const isFabric = global._IS_FABRIC;\n\n if (!ref.current) {\n const fun: RefObjectFunction<T> = <RefObjectFunction<T>>((component) => {\n 'worklet';\n // enters when ref is set by attaching to a component\n if (component) {\n tag.value = isFabric\n ? getShadowNodeWrapperFromHostInstance(component)\n : getTag(component);\n fun.current = component;\n }\n return tag.value;\n });\n\n Object.defineProperty(fun, 'current', {\n value: null,\n writable: true,\n enumerable: false,\n });\n ref.current = fun;\n }\n\n return ref.current;\n}\n"],"mappings":"AAAA,SAAoBA,MAApB,QAAkC,OAAlC;AACA,SAASC,cAAT,QAA+B,kBAA/B;AAGA,SAASC,MAAT,QAAuB,kBAAvB;AACA,SAASC,oCAAT,QAAqD,gBAArD;AAEA,OAAO,SAASC,cAAT,GAAqE;EAC1E,MAAMC,GAAG,GAAGJ,cAAc,CAAoC,CAAC,CAArC,CAA1B;EACA,MAAMK,GAAG,GAAGN,MAAM,EAAlB;EACA,MAAMO,QAAQ,GAAGC,MAAM,CAACC,UAAxB;;EAEA,IAAI,CAACH,GAAG,CAACI,OAAT,EAAkB;IAChB,MAAMC,GAAyB,GAA2BC,SAAD,IAAe;MACtE,UADsE,CAEtE;;MACA,IAAIA,SAAJ,EAAe;QACbP,GAAG,CAACQ,KAAJ,GAAYN,QAAQ,GAChBJ,oCAAoC,CAACS,SAAD,CADpB,GAEhBV,MAAM,CAACU,SAAD,CAFV;QAGAD,GAAG,CAACD,OAAJ,GAAcE,SAAd;MACD;;MACD,OAAOP,GAAG,CAACQ,KAAX;IACD,CAVD;;IAYAC,MAAM,CAACC,cAAP,CAAsBJ,GAAtB,EAA2B,SAA3B,EAAsC;MACpCE,KAAK,EAAE,IAD6B;MAEpCG,QAAQ,EAAE,IAF0B;MAGpCC,UAAU,EAAE;IAHwB,CAAtC;IAKAX,GAAG,CAACI,OAAJ,GAAcC,GAAd;EACD;;EAED,OAAOL,GAAG,CAACI,OAAX;AACD"}
1
+ {"version":3,"names":["useRef","useSharedValue","getTag","getShadowNodeWrapperFromHostInstance","makeShareableCloneRecursive","makeShareableShadowNodeWrapper","registerShareableMapping","getShareableShadowNodeFromComponent","component","getTagValueFunction","global","_IS_FABRIC","useAnimatedRef","tag","ref","current","fun","value","remoteRef","__init"],"sources":["useAnimatedRef.ts"],"sourcesContent":["import { Component, useRef } from 'react';\nimport { useSharedValue } from './useSharedValue';\nimport { RefObjectFunction } from './commonTypes';\nimport { ShadowNodeWrapper } from '../commonTypes';\nimport { getTag } from '../NativeMethods';\nimport { getShadowNodeWrapperFromHostInstance } from '../fabricUtils';\nimport {\n makeShareableCloneRecursive,\n makeShareableShadowNodeWrapper,\n registerShareableMapping,\n} from '../shareables';\n\nfunction getShareableShadowNodeFromComponent(\n component: Component\n): ShadowNodeWrapper {\n return makeShareableShadowNodeWrapper(\n getShadowNodeWrapperFromHostInstance(component)\n );\n}\n\nconst getTagValueFunction = global._IS_FABRIC\n ? getShareableShadowNodeFromComponent\n : getTag;\n\nexport function useAnimatedRef<T extends Component>(): RefObjectFunction<T> {\n const tag = useSharedValue<number | ShadowNodeWrapper | null>(-1);\n const ref = useRef<RefObjectFunction<T>>();\n\n if (!ref.current) {\n const fun: RefObjectFunction<T> = <RefObjectFunction<T>>((component) => {\n // enters when ref is set by attaching to a component\n if (component) {\n tag.value = getTagValueFunction(component);\n fun.current = component;\n }\n return tag.value;\n });\n\n fun.current = null;\n\n const remoteRef = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return () => tag.value;\n },\n });\n registerShareableMapping(fun, remoteRef);\n\n ref.current = fun;\n }\n\n return ref.current;\n}\n"],"mappings":"AAAA,SAAoBA,MAApB,QAAkC,OAAlC;AACA,SAASC,cAAT,QAA+B,kBAA/B;AAGA,SAASC,MAAT,QAAuB,kBAAvB;AACA,SAASC,oCAAT,QAAqD,gBAArD;AACA,SACEC,2BADF,EAEEC,8BAFF,EAGEC,wBAHF,QAIO,eAJP;;AAMA,SAASC,mCAAT,CACEC,SADF,EAEqB;EACnB,OAAOH,8BAA8B,CACnCF,oCAAoC,CAACK,SAAD,CADD,CAArC;AAGD;;AAED,MAAMC,mBAAmB,GAAGC,MAAM,CAACC,UAAP,GACxBJ,mCADwB,GAExBL,MAFJ;AAIA,OAAO,SAASU,cAAT,GAAqE;EAC1E,MAAMC,GAAG,GAAGZ,cAAc,CAAoC,CAAC,CAArC,CAA1B;EACA,MAAMa,GAAG,GAAGd,MAAM,EAAlB;;EAEA,IAAI,CAACc,GAAG,CAACC,OAAT,EAAkB;IAChB,MAAMC,GAAyB,GAA2BR,SAAD,IAAe;MACtE;MACA,IAAIA,SAAJ,EAAe;QACbK,GAAG,CAACI,KAAJ,GAAYR,mBAAmB,CAACD,SAAD,CAA/B;QACAQ,GAAG,CAACD,OAAJ,GAAcP,SAAd;MACD;;MACD,OAAOK,GAAG,CAACI,KAAX;IACD,CAPD;;IASAD,GAAG,CAACD,OAAJ,GAAc,IAAd;IAEA,MAAMG,SAAS,GAAGd,2BAA2B,CAAC;MAC5Ce,MAAM,EAAE,MAAM;QACZ;;QACA,OAAO,MAAMN,GAAG,CAACI,KAAjB;MACD;IAJ2C,CAAD,CAA7C;IAMAX,wBAAwB,CAACU,GAAD,EAAME,SAAN,CAAxB;IAEAJ,GAAG,CAACC,OAAJ,GAAcC,GAAd;EACD;;EAED,OAAOF,GAAG,CAACC,OAAX;AACD"}
@@ -1,6 +1,5 @@
1
1
  import { useEffect, useRef } from 'react';
2
- import { makeMutable } from '../core';
3
- import NativeReanimated from '../NativeReanimated';
2
+ import { makeMutable, registerSensor, unregisterSensor } from '../core';
4
3
  export let SensorType;
5
4
 
6
5
  (function (SensorType) {
@@ -11,9 +10,29 @@ export let SensorType;
11
10
  SensorType[SensorType["ROTATION"] = 5] = "ROTATION";
12
11
  })(SensorType || (SensorType = {}));
13
12
 
13
+ function initSensorData(sensorType) {
14
+ if (sensorType === SensorType.ROTATION) {
15
+ return makeMutable({
16
+ qw: 0,
17
+ qx: 0,
18
+ qy: 0,
19
+ qz: 0,
20
+ yaw: 0,
21
+ pitch: 0,
22
+ roll: 0
23
+ });
24
+ } else {
25
+ return makeMutable({
26
+ x: 0,
27
+ y: 0,
28
+ z: 0
29
+ });
30
+ }
31
+ }
32
+
14
33
  export function useAnimatedSensor(sensorType, userConfig) {
15
34
  const ref = useRef({
16
- sensor: null,
35
+ sensor: initSensorData(sensorType),
17
36
  unregister: () => {// NOOP
18
37
  },
19
38
  isAvailable: false,
@@ -21,45 +40,21 @@ export function useAnimatedSensor(sensorType, userConfig) {
21
40
  interval: 0
22
41
  }
23
42
  });
24
-
25
- if (ref.current.sensor === null) {
26
- ref.current.config = {
27
- interval: 'auto',
28
- ...userConfig
29
- };
30
- let sensorData;
31
-
32
- if (sensorType === SensorType.ROTATION) {
33
- sensorData = {
34
- qw: 0,
35
- qx: 0,
36
- qy: 0,
37
- qz: 0,
38
- yaw: 0,
39
- pitch: 0,
40
- roll: 0
41
- };
42
- } else {
43
- sensorData = {
44
- x: 0,
45
- y: 0,
46
- z: 0
47
- };
48
- }
49
-
50
- ref.current.sensor = makeMutable(sensorData);
51
- }
52
-
53
43
  useEffect(() => {
54
44
  ref.current.config = {
55
45
  interval: 'auto',
56
46
  ...userConfig
57
47
  };
58
- const id = NativeReanimated.registerSensor(sensorType, ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval, ref.current.sensor);
48
+ const sensorData = ref.current.sensor;
49
+ const id = registerSensor(sensorType, ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval, data => {
50
+ 'worklet';
51
+
52
+ sensorData.value = data;
53
+ });
59
54
 
60
55
  if (id !== -1) {
61
56
  // if sensor is available
62
- ref.current.unregister = () => NativeReanimated.unregisterSensor(id);
57
+ ref.current.unregister = () => unregisterSensor(id);
63
58
 
64
59
  ref.current.isAvailable = true;
65
60
  } else {
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","makeMutable","NativeReanimated","SensorType","useAnimatedSensor","sensorType","userConfig","ref","sensor","unregister","isAvailable","config","interval","current","sensorData","ROTATION","qw","qx","qy","qz","yaw","pitch","roll","x","y","z","id","registerSensor","unregisterSensor"],"sources":["useAnimatedSensor.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { makeMutable } from '../core';\nimport NativeReanimated from '../NativeReanimated';\nimport { SensorValue3D, SensorValueRotation } from '../commonTypes';\n\nexport enum SensorType {\n ACCELEROMETER = 1,\n GYROSCOPE = 2,\n GRAVITY = 3,\n MAGNETIC_FIELD = 4,\n ROTATION = 5,\n}\n\nexport type SensorConfig = {\n interval: number | 'auto';\n};\n\nexport type AnimatedSensor = {\n sensor: SensorValue3D | SensorValueRotation | null;\n unregister: () => void;\n isAvailable: boolean;\n config: SensorConfig;\n};\n\nexport function useAnimatedSensor(\n sensorType: SensorType,\n userConfig?: SensorConfig\n): AnimatedSensor {\n const ref = useRef<AnimatedSensor>({\n sensor: null,\n unregister: () => {\n // NOOP\n },\n isAvailable: false,\n config: {\n interval: 0,\n },\n });\n\n if (ref.current.sensor === null) {\n ref.current.config = { interval: 'auto', ...userConfig };\n let sensorData;\n if (sensorType === SensorType.ROTATION) {\n sensorData = {\n qw: 0,\n qx: 0,\n qy: 0,\n qz: 0,\n yaw: 0,\n pitch: 0,\n roll: 0,\n };\n } else {\n sensorData = {\n x: 0,\n y: 0,\n z: 0,\n };\n }\n ref.current.sensor = makeMutable(sensorData) as any;\n }\n\n useEffect(() => {\n ref.current.config = { interval: 'auto', ...userConfig };\n const id = NativeReanimated.registerSensor(\n sensorType,\n ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval,\n ref.current.sensor as any\n );\n\n if (id !== -1) {\n // if sensor is available\n ref.current.unregister = () => NativeReanimated.unregisterSensor(id);\n ref.current.isAvailable = true;\n } else {\n // if sensor is unavailable\n ref.current.unregister = () => {\n // NOOP\n };\n ref.current.isAvailable = false;\n }\n\n return () => {\n ref.current.unregister();\n };\n }, [sensorType, userConfig]);\n\n return ref.current;\n}\n"],"mappings":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MAAZ,GAAqB;MAAEC,QAAQ,EAAE,MAAZ;MAAoB,GAAGN;IAAvB,CAArB;IACA,MAAMoB,EAAE,GAAGxB,gBAAgB,CAACyB,cAAjB,CACTtB,UADS,EAETE,GAAG,CAACM,OAAJ,CAAYF,MAAZ,CAAmBC,QAAnB,KAAgC,MAAhC,GAAyC,CAAC,CAA1C,GAA8CL,GAAG,CAACM,OAAJ,CAAYF,MAAZ,CAAmBC,QAFxD,EAGTL,GAAG,CAACM,OAAJ,CAAYL,MAHH,CAAX;;IAMA,IAAIkB,EAAE,KAAK,CAAC,CAAZ,EAAe;MACb;MACAnB,GAAG,CAACM,OAAJ,CAAYJ,UAAZ,GAAyB,MAAMP,gBAAgB,CAAC0B,gBAAjB,CAAkCF,EAAlC,CAA/B;;MACAnB,GAAG,CAACM,OAAJ,CAAYH,WAAZ,GAA0B,IAA1B;IACD,CAJD,MAIO;MACL;MACAH,GAAG,CAACM,OAAJ,CAAYJ,UAAZ,GAAyB,MAAM,CAC7B;MACD,CAFD;;MAGAF,GAAG,CAACM,OAAJ,CAAYH,WAAZ,GAA0B,KAA1B;IACD;;IAED,OAAO,MAAM;MACXH,GAAG,CAACM,OAAJ,CAAYJ,UAAZ;IACD,CAFD;EAGD,CAvBQ,EAuBN,CAACJ,UAAD,EAAaC,UAAb,CAvBM,CAAT;EAyBA,OAAOC,GAAG,CAACM,OAAX;AACD"}
1
+ {"version":3,"names":["useEffect","useRef","makeMutable","registerSensor","unregisterSensor","SensorType","initSensorData","sensorType","ROTATION","qw","qx","qy","qz","yaw","pitch","roll","x","y","z","useAnimatedSensor","userConfig","ref","sensor","unregister","isAvailable","config","interval","current","sensorData","id","data","value"],"sources":["useAnimatedSensor.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { makeMutable, registerSensor, unregisterSensor } from '../core';\nimport { SharedValue, Value3D, ValueRotation } from '../commonTypes';\n\nexport enum SensorType {\n ACCELEROMETER = 1,\n GYROSCOPE = 2,\n GRAVITY = 3,\n MAGNETIC_FIELD = 4,\n ROTATION = 5,\n}\n\nexport type SensorConfig = {\n interval: number | 'auto';\n};\n\nexport type AnimatedSensor = {\n sensor: SharedValue<Value3D | ValueRotation>;\n unregister: () => void;\n isAvailable: boolean;\n config: SensorConfig;\n};\n\nfunction initSensorData(\n sensorType: SensorType\n): SharedValue<Value3D | ValueRotation> {\n if (sensorType === SensorType.ROTATION) {\n return makeMutable<Value3D | ValueRotation>({\n qw: 0,\n qx: 0,\n qy: 0,\n qz: 0,\n yaw: 0,\n pitch: 0,\n roll: 0,\n });\n } else {\n return makeMutable<Value3D | ValueRotation>({\n x: 0,\n y: 0,\n z: 0,\n });\n }\n}\n\nexport function useAnimatedSensor(\n sensorType: SensorType,\n userConfig?: SensorConfig\n): AnimatedSensor {\n const ref = useRef<AnimatedSensor>({\n sensor: initSensorData(sensorType),\n unregister: () => {\n // NOOP\n },\n isAvailable: false,\n config: {\n interval: 0,\n },\n });\n\n useEffect(() => {\n ref.current.config = { interval: 'auto', ...userConfig };\n const sensorData = ref.current.sensor!;\n const id = registerSensor(\n sensorType,\n ref.current.config.interval === 'auto' ? -1 : ref.current.config.interval,\n (data) => {\n 'worklet';\n sensorData.value = data;\n }\n );\n\n if (id !== -1) {\n // if sensor is available\n ref.current.unregister = () => unregisterSensor(id);\n ref.current.isAvailable = true;\n } else {\n // if sensor is unavailable\n ref.current.unregister = () => {\n // NOOP\n };\n ref.current.isAvailable = false;\n }\n\n return () => {\n ref.current.unregister();\n };\n }, [sensorType, userConfig]);\n\n return ref.current;\n}\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,SAASC,WAAT,EAAsBC,cAAtB,EAAsCC,gBAAtC,QAA8D,SAA9D;AAGA,WAAYC,UAAZ;;WAAYA,U;EAAAA,U,CAAAA,U;EAAAA,U,CAAAA,U;EAAAA,U,CAAAA,U;EAAAA,U,CAAAA,U;EAAAA,U,CAAAA,U;GAAAA,U,KAAAA,U;;AAmB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AE,KAAK,CAAC,CAAZ,EAAe;MACb;MACAR,GAAG,CAACM,OAAJ,CAAYJ,UAAZ,GAAyB,MAAMnB,gBAAgB,CAACyB,EAAD,CAA/C;;MACAR,GAAG,CAACM,OAAJ,CAAYH,WAAZ,GAA0B,IAA1B;IACD,CAJD,MAIO;MACL;MACAH,GAAG,CAACM,OAAJ,CAAYJ,UAAZ,GAAyB,MAAM,CAC7B;MACD,CAFD;;MAGAF,GAAG,CAACM,OAAJ,CAAYH,WAAZ,GAA0B,KAA1B;IACD;;IAED,OAAO,MAAM;MACXH,GAAG,CAACM,OAAJ,CAAYJ,UAAZ;IACD,CAFD;EAGD,CA3BQ,EA2BN,CAAChB,UAAD,EAAaa,UAAb,CA3BM,CAAT;EA6BA,OAAOC,GAAG,CAACM,OAAX;AACD"}
@@ -1,11 +1,11 @@
1
1
  /* global _frameTimestamp */
2
2
  import { useEffect, useRef } from 'react';
3
- import { startMapper, stopMapper, makeRemote, requestFrame, getTimestamp, makeMutable } from '../core';
3
+ import { startMapper, stopMapper, makeRemote, getTimestamp } from '../core';
4
4
  import updateProps, { updatePropsJestWrapper } from '../UpdateProps';
5
5
  import { initialUpdaterRun } from '../animation';
6
6
  import NativeReanimatedModule from '../NativeReanimated';
7
7
  import { useSharedValue } from './useSharedValue';
8
- import { buildWorkletsHash, canApplyOptimalisation, getStyleWithoutAnimations, hasColorProps, isAnimated, parseColors, styleDiff, validateAnimatedStyles } from './utils';
8
+ import { buildWorkletsHash, getStyleWithoutAnimations, isAnimated, parseColors, styleDiff, validateAnimatedStyles } from './utils';
9
9
  import { makeViewDescriptorsSet, makeViewsRefSet } from '../ViewDescriptorsSet';
10
10
  import { isJest, shouldBeUseWeb } from '../PlatformChecker';
11
11
 
@@ -13,7 +13,9 @@ function prepareAnimation(animatedProp, lastAnimation, lastValue) {
13
13
  'worklet';
14
14
 
15
15
  if (Array.isArray(animatedProp)) {
16
- animatedProp.forEach((prop, index) => prepareAnimation(prop, lastAnimation && lastAnimation[index], lastValue && lastValue[index])); // return animatedProp;
16
+ animatedProp.forEach((prop, index) => {
17
+ prepareAnimation(prop, lastAnimation && lastAnimation[index], lastValue && lastValue[index]);
18
+ }); // return animatedProp;
17
19
  }
18
20
 
19
21
  if (typeof animatedProp === 'object' && animatedProp.onFrame) {
@@ -126,13 +128,15 @@ function styleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsA
126
128
  }
127
129
 
128
130
  if (hasAnimations) {
129
- const frame = timestamp => {
131
+ const frame = _timestamp => {
130
132
  const {
131
133
  animations,
132
134
  last,
133
135
  isAnimationCancelled
134
136
  } = state;
135
137
 
138
+ const timestamp = _timestamp ?? getTimestamp();
139
+
136
140
  if (isAnimationCancelled) {
137
141
  state.isAnimationRunning = false;
138
142
  return;
@@ -157,7 +161,7 @@ function styleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsA
157
161
  }
158
162
 
159
163
  if (!allFinished) {
160
- requestFrame(frame);
164
+ requestAnimationFrame(frame);
161
165
  } else {
162
166
  state.isAnimationRunning = false;
163
167
  }
@@ -172,7 +176,7 @@ function styleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsA
172
176
  if (_frameTimestamp) {
173
177
  frame(_frameTimestamp);
174
178
  } else {
175
- requestFrame(frame);
179
+ requestAnimationFrame(frame);
176
180
  }
177
181
  }
178
182
 
@@ -220,13 +224,15 @@ function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animati
220
224
  }
221
225
  });
222
226
 
223
- function frame(timestamp) {
227
+ function frame(_timestamp) {
224
228
  const {
225
229
  animations,
226
230
  last,
227
231
  isAnimationCancelled
228
232
  } = state;
229
233
 
234
+ const timestamp = _timestamp ?? getTimestamp();
235
+
230
236
  if (isAnimationCancelled) {
231
237
  state.isAnimationRunning = false;
232
238
  return;
@@ -250,7 +256,7 @@ function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animati
250
256
  }
251
257
 
252
258
  if (!allFinished) {
253
- requestFrame(frame);
259
+ requestAnimationFrame(frame);
254
260
  } else {
255
261
  state.isAnimationRunning = false;
256
262
  }
@@ -266,7 +272,7 @@ function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animati
266
272
  if (_frameTimestamp) {
267
273
  frame(_frameTimestamp);
268
274
  } else {
269
- requestFrame(frame);
275
+ requestAnimationFrame(frame);
270
276
  }
271
277
  }
272
278
  } else {
@@ -302,10 +308,7 @@ function checkSharedValueUsage(prop, currentKey) {
302
308
  }
303
309
 
304
310
  export function useAnimatedStyle(updater, dependencies, adapters) {
305
- var _initRef$current;
306
-
307
311
  const viewsRef = makeViewsRefSet();
308
- const viewDescriptors = makeViewDescriptorsSet();
309
312
  const initRef = useRef();
310
313
  const inputs = Object.values(updater._closure ?? {});
311
314
  const adaptersArray = adapters ? Array.isArray(adapters) ? adapters : [adapters] : [];
@@ -330,26 +333,27 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
330
333
  updater: updater
331
334
  },
332
335
  remoteState: makeRemote({
333
- last: initialStyle
336
+ last: initialStyle,
337
+ animations: {},
338
+ isAnimationCancelled: false,
339
+ isAnimationRunning: false
334
340
  }),
335
- sharableViewDescriptors: makeMutable([])
341
+ viewDescriptors: makeViewDescriptorsSet()
336
342
  };
337
- viewDescriptors.rebuildsharableViewDescriptors( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
338
- initRef.current.sharableViewDescriptors);
339
- }
343
+ } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
340
344
 
341
- dependencies.push((_initRef$current = initRef.current) === null || _initRef$current === void 0 ? void 0 : _initRef$current.sharableViewDescriptors.value); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
342
345
 
343
346
  const {
344
347
  initial,
345
348
  remoteState,
346
- sharableViewDescriptors
349
+ viewDescriptors
347
350
  } = initRef.current;
351
+ const sharableViewDescriptors = viewDescriptors.sharableViewDescriptors;
348
352
  const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;
353
+ dependencies.push(sharableViewDescriptors);
349
354
  useEffect(() => {
350
355
  let fun;
351
356
  let updaterFn = updater;
352
- let optimalization = updater.__optimalization;
353
357
 
354
358
  if (adapters) {
355
359
  updaterFn = () => {
@@ -363,32 +367,7 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
363
367
  };
364
368
  }
365
369
 
366
- if (canApplyOptimalisation(updaterFn) && !shouldBeUseWeb()) {
367
- if (hasColorProps(updaterFn())) {
368
- updaterFn = () => {
369
- 'worklet';
370
-
371
- const newValues = updaterFn();
372
- const oldValues = remoteState.last;
373
- const diff = styleDiff(oldValues, newValues);
374
- remoteState.last = Object.assign({}, oldValues, newValues);
375
- parseColors(diff);
376
- return diff;
377
- };
378
- } else {
379
- updaterFn = () => {
380
- 'worklet';
381
-
382
- const newValues = updaterFn();
383
- const oldValues = remoteState.last;
384
- const diff = styleDiff(oldValues, newValues);
385
- remoteState.last = Object.assign({}, oldValues, newValues);
386
- return diff;
387
- };
388
- }
389
- } else if (!shouldBeUseWeb()) {
390
- optimalization = 0;
391
-
370
+ if (!shouldBeUseWeb()) {
392
371
  updaterFn = () => {
393
372
  'worklet';
394
373
 
@@ -398,10 +377,6 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
398
377
  };
399
378
  }
400
379
 
401
- if (typeof updater.__optimalization !== undefined) {
402
- updaterFn.__optimalization = optimalization;
403
- }
404
-
405
380
  if (isJest()) {
406
381
  fun = () => {
407
382
  'worklet';
@@ -416,8 +391,7 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
416
391
  };
417
392
  }
418
393
 
419
- const mapperId = startMapper(fun, inputs, [], updaterFn, // TODO fix this
420
- sharableViewDescriptors);
394
+ const mapperId = startMapper(fun, inputs);
421
395
  return () => {
422
396
  stopMapper(mapperId);
423
397
  };
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","startMapper","stopMapper","makeRemote","requestFrame","getTimestamp","makeMutable","updateProps","updatePropsJestWrapper","initialUpdaterRun","NativeReanimatedModule","useSharedValue","buildWorkletsHash","canApplyOptimalisation","getStyleWithoutAnimations","hasColorProps","isAnimated","parseColors","styleDiff","validateAnimatedStyles","makeViewDescriptorsSet","makeViewsRefSet","isJest","shouldBeUseWeb","prepareAnimation","animatedProp","lastAnimation","lastValue","Array","isArray","forEach","prop","index","onFrame","animation","value","current","undefined","callStart","timestamp","onStart","Object","keys","key","runAnimations","result","animationsActive","allFinished","entry","finished","callback","k","styleUpdater","viewDescriptors","updater","state","maybeViewRef","animations","newValues","oldValues","last","hasAnimations","frame","isAnimationCancelled","isAnimationRunning","updates","propName","_frameTimestamp","assign","style","diff","jestStyleUpdater","animatedStyle","adapters","length","checkSharedValueUsage","currentKey","element","Error","useAnimatedStyle","dependencies","viewsRef","initRef","inputs","values","_closure","adaptersArray","adaptersHash","__workletHash","push","initialStyle","initial","remoteState","sharableViewDescriptors","rebuildsharableViewDescriptors","native","fun","updaterFn","optimalization","__optimalization","adapter","mapperId","process","env","JEST_WORKER_ID"],"sources":["useAnimatedStyle.ts"],"sourcesContent":["/* global _frameTimestamp */\nimport { MutableRefObject, useEffect, useRef } from 'react';\n\nimport {\n startMapper,\n stopMapper,\n makeRemote,\n requestFrame,\n getTimestamp,\n makeMutable,\n} from '../core';\nimport updateProps, { updatePropsJestWrapper } from '../UpdateProps';\nimport { initialUpdaterRun } from '../animation';\nimport NativeReanimatedModule from '../NativeReanimated';\nimport { useSharedValue } from './useSharedValue';\nimport {\n buildWorkletsHash,\n canApplyOptimalisation,\n getStyleWithoutAnimations,\n hasColorProps,\n isAnimated,\n parseColors,\n styleDiff,\n validateAnimatedStyles,\n} from './utils';\nimport { DependencyList, Descriptor } from './commonTypes';\nimport {\n makeViewDescriptorsSet,\n makeViewsRefSet,\n ViewDescriptorsSet,\n ViewRefSet,\n} from '../ViewDescriptorsSet';\nimport { isJest, shouldBeUseWeb } from '../PlatformChecker';\nimport {\n AnimationObject,\n Timestamp,\n AdapterWorkletFunction,\n AnimatedStyle,\n BasicWorkletFunction,\n BasicWorkletFunctionOptional,\n NestedObjectValues,\n SharedValue,\n} from '../commonTypes';\nexport interface AnimatedStyleResult {\n viewDescriptors: ViewDescriptorsSet;\n initial: AnimatedStyle;\n viewsRef: ViewRefSet<any>;\n animatedStyle?: MutableRefObject<AnimatedStyle>;\n}\n\ninterface AnimatedState {\n last: AnimatedStyle;\n animations: AnimatedStyle;\n isAnimationRunning: boolean;\n isAnimationCancelled: boolean;\n}\n\ninterface AnimationRef {\n initial: {\n value: AnimatedStyle;\n updater: () => AnimatedStyle;\n };\n remoteState: AnimatedState;\n sharableViewDescriptors: SharedValue<Descriptor[]>;\n}\n\nfunction prepareAnimation(\n animatedProp: AnimatedStyle,\n lastAnimation: AnimatedStyle,\n lastValue: AnimatedStyle\n): void {\n 'worklet';\n if (Array.isArray(animatedProp)) {\n animatedProp.forEach((prop, index) =>\n prepareAnimation(\n prop,\n lastAnimation && lastAnimation[index],\n lastValue && lastValue[index]\n )\n );\n // return animatedProp;\n }\n if (typeof animatedProp === 'object' && animatedProp.onFrame) {\n const animation = animatedProp;\n\n let value = animation.current;\n if (lastValue !== undefined) {\n if (typeof lastValue === 'object') {\n if (lastValue.value !== undefined) {\n // previously it was a shared value\n value = lastValue.value;\n } else if (lastValue.onFrame !== undefined) {\n if (lastAnimation?.current !== undefined) {\n // it was an animation before, copy its state\n value = lastAnimation.current;\n } else if (lastValue?.current !== undefined) {\n // it was initialized\n value = lastValue.current;\n }\n }\n } else {\n // previously it was a plain value, just set it as starting point\n value = lastValue;\n }\n }\n\n animation.callStart = (timestamp: Timestamp) => {\n animation.onStart(animation, value, timestamp, lastAnimation);\n };\n animation.callStart(getTimestamp());\n animation.callStart = null;\n } else if (typeof animatedProp === 'object') {\n // it is an object\n Object.keys(animatedProp).forEach((key) =>\n prepareAnimation(\n animatedProp[key],\n lastAnimation && lastAnimation[key],\n lastValue && lastValue[key]\n )\n );\n }\n}\n\nfunction runAnimations(\n animation: AnimatedStyle,\n timestamp: Timestamp,\n key: number | string,\n result: AnimatedStyle,\n animationsActive: SharedValue<boolean>\n): boolean {\n 'worklet';\n if (!animationsActive.value) {\n return true;\n }\n if (Array.isArray(animation)) {\n result[key] = [];\n let allFinished = true;\n animation.forEach((entry, index) => {\n if (\n !runAnimations(entry, timestamp, index, result[key], animationsActive)\n ) {\n allFinished = false;\n }\n });\n return allFinished;\n } else if (typeof animation === 'object' && animation.onFrame) {\n let finished = true;\n if (!animation.finished) {\n if (animation.callStart) {\n animation.callStart(timestamp);\n animation.callStart = null;\n }\n finished = animation.onFrame(animation, timestamp);\n animation.timestamp = timestamp;\n if (finished) {\n animation.finished = true;\n animation.callback && animation.callback(true /* finished */);\n }\n }\n result[key] = animation.current;\n return finished;\n } else if (typeof animation === 'object') {\n result[key] = {};\n let allFinished = true;\n Object.keys(animation).forEach((k) => {\n if (\n !runAnimations(\n animation[k],\n timestamp,\n k,\n result[key],\n animationsActive\n )\n ) {\n allFinished = false;\n }\n });\n return allFinished;\n } else {\n result[key] = animation;\n return true;\n }\n}\n\nfunction styleUpdater(\n viewDescriptors: SharedValue<Descriptor[]>,\n updater: BasicWorkletFunction<AnimatedStyle>,\n state: AnimatedState,\n maybeViewRef: ViewRefSet<any> | undefined,\n animationsActive: SharedValue<boolean>\n): void {\n 'worklet';\n const animations = state.animations ?? {};\n const newValues = updater() ?? {};\n const oldValues = state.last;\n\n let hasAnimations = false;\n for (const key in newValues) {\n const value = newValues[key];\n if (isAnimated(value)) {\n prepareAnimation(value, animations[key], oldValues[key]);\n animations[key] = value;\n hasAnimations = true;\n } else {\n delete animations[key];\n }\n }\n\n if (hasAnimations) {\n const frame = (timestamp: Timestamp) => {\n const { animations, last, isAnimationCancelled } = state;\n if (isAnimationCancelled) {\n state.isAnimationRunning = false;\n return;\n }\n\n const updates: AnimatedStyle = {};\n let allFinished = true;\n for (const propName in animations) {\n const finished = runAnimations(\n animations[propName],\n timestamp,\n propName,\n updates,\n animationsActive\n );\n if (finished) {\n last[propName] = updates[propName];\n delete animations[propName];\n } else {\n allFinished = false;\n }\n }\n\n if (updates) {\n updateProps(viewDescriptors, updates, maybeViewRef);\n }\n\n if (!allFinished) {\n requestFrame(frame);\n } else {\n state.isAnimationRunning = false;\n }\n };\n\n state.animations = animations;\n if (!state.isAnimationRunning) {\n state.isAnimationCancelled = false;\n state.isAnimationRunning = true;\n if (_frameTimestamp) {\n frame(_frameTimestamp);\n } else {\n requestFrame(frame);\n }\n }\n state.last = Object.assign({}, oldValues, newValues);\n const style = getStyleWithoutAnimations(state.last);\n if (style) {\n updateProps(viewDescriptors, style, maybeViewRef);\n }\n } else {\n state.isAnimationCancelled = true;\n state.animations = [];\n\n const diff = styleDiff(oldValues, newValues);\n state.last = Object.assign({}, oldValues, newValues);\n if (diff) {\n updateProps(viewDescriptors, newValues, maybeViewRef);\n }\n }\n}\n\nfunction jestStyleUpdater(\n viewDescriptors: SharedValue<Descriptor[]>,\n updater: BasicWorkletFunction<AnimatedStyle>,\n state: AnimatedState,\n maybeViewRef: ViewRefSet<any> | undefined,\n animationsActive: SharedValue<boolean>,\n animatedStyle: MutableRefObject<AnimatedStyle>,\n adapters: AdapterWorkletFunction[] = []\n): void {\n 'worklet';\n const animations: AnimatedStyle = state.animations ?? {};\n const newValues = updater() ?? {};\n const oldValues = state.last;\n\n // extract animated props\n let hasAnimations = false;\n Object.keys(animations).forEach((key) => {\n const value = newValues[key];\n if (!isAnimated(value)) {\n delete animations[key];\n }\n });\n Object.keys(newValues).forEach((key) => {\n const value = newValues[key];\n if (isAnimated(value)) {\n prepareAnimation(value, animations[key], oldValues[key]);\n animations[key] = value;\n hasAnimations = true;\n }\n });\n\n function frame(timestamp: Timestamp) {\n const { animations, last, isAnimationCancelled } = state;\n if (isAnimationCancelled) {\n state.isAnimationRunning = false;\n return;\n }\n\n const updates: AnimatedStyle = {};\n let allFinished = true;\n Object.keys(animations).forEach((propName) => {\n const finished = runAnimations(\n animations[propName],\n timestamp,\n propName,\n updates,\n animationsActive\n );\n if (finished) {\n last[propName] = updates[propName];\n delete animations[propName];\n } else {\n allFinished = false;\n }\n });\n\n if (Object.keys(updates).length) {\n updatePropsJestWrapper(\n viewDescriptors,\n updates,\n maybeViewRef,\n animatedStyle,\n adapters\n );\n }\n\n if (!allFinished) {\n requestFrame(frame);\n } else {\n state.isAnimationRunning = false;\n }\n }\n\n if (hasAnimations) {\n state.animations = animations;\n if (!state.isAnimationRunning) {\n state.isAnimationCancelled = false;\n state.isAnimationRunning = true;\n if (_frameTimestamp) {\n frame(_frameTimestamp);\n } else {\n requestFrame(frame);\n }\n }\n } else {\n state.isAnimationCancelled = true;\n state.animations = [];\n }\n\n // calculate diff\n const diff = styleDiff(oldValues, newValues);\n state.last = Object.assign({}, oldValues, newValues);\n\n if (Object.keys(diff).length !== 0) {\n updatePropsJestWrapper(\n viewDescriptors,\n diff,\n maybeViewRef,\n animatedStyle,\n adapters\n );\n }\n}\n\n// check for invalid usage of shared values in returned object\nfunction checkSharedValueUsage(\n prop: NestedObjectValues<AnimationObject>,\n currentKey?: string\n): void {\n if (Array.isArray(prop)) {\n // if it's an array (i.ex. transform) validate all its elements\n for (const element of prop) {\n checkSharedValueUsage(element, currentKey);\n }\n } else if (typeof prop === 'object' && prop.value === undefined) {\n // if it's a nested object, run validation for all its props\n for (const key of Object.keys(prop)) {\n checkSharedValueUsage(prop[key], key);\n }\n } else if (\n currentKey !== undefined &&\n typeof prop === 'object' &&\n prop.value !== undefined\n ) {\n // if shared value is passed insted of its value, throw an error\n throw new Error(\n `invalid value passed to \\`${currentKey}\\`, maybe you forgot to use \\`.value\\`?`\n );\n }\n}\n\nexport function useAnimatedStyle<T extends AnimatedStyle>(\n updater: BasicWorkletFunction<T>,\n dependencies?: DependencyList,\n adapters?: AdapterWorkletFunction | AdapterWorkletFunction[]\n): AnimatedStyleResult {\n const viewsRef: ViewRefSet<any> = makeViewsRefSet();\n const viewDescriptors: ViewDescriptorsSet = makeViewDescriptorsSet();\n const initRef = useRef<AnimationRef>();\n const inputs = Object.values(updater._closure ?? {});\n const adaptersArray: AdapterWorkletFunction[] = adapters\n ? Array.isArray(adapters)\n ? adapters\n : [adapters]\n : [];\n const adaptersHash = adapters ? buildWorkletsHash(adaptersArray) : null;\n const animationsActive = useSharedValue<boolean>(true);\n const animatedStyle: MutableRefObject<AnimatedStyle> = useRef<AnimatedStyle>(\n {}\n );\n\n // build dependencies\n if (!dependencies) {\n dependencies = [...inputs, updater.__workletHash];\n } else {\n dependencies.push(updater.__workletHash);\n }\n adaptersHash && dependencies.push(adaptersHash);\n\n if (!initRef.current) {\n const initialStyle: AnimatedStyle = initialUpdaterRun(updater);\n validateAnimatedStyles(initialStyle);\n initRef.current = {\n initial: {\n value: initialStyle,\n updater: updater,\n },\n remoteState: makeRemote({ last: initialStyle }),\n sharableViewDescriptors: makeMutable([]),\n };\n viewDescriptors.rebuildsharableViewDescriptors(\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n initRef.current!.sharableViewDescriptors\n );\n }\n dependencies.push(initRef.current?.sharableViewDescriptors.value);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { initial, remoteState, sharableViewDescriptors } = initRef.current!;\n const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;\n\n useEffect(() => {\n let fun;\n let updaterFn = updater as BasicWorkletFunctionOptional<T>;\n let optimalization = updater.__optimalization;\n if (adapters) {\n updaterFn = () => {\n 'worklet';\n const newValues = updater();\n adaptersArray.forEach((adapter) => {\n adapter(newValues);\n });\n return newValues;\n };\n }\n\n if (canApplyOptimalisation(updaterFn) && !shouldBeUseWeb()) {\n if (hasColorProps(updaterFn())) {\n updaterFn = () => {\n 'worklet';\n const newValues = updaterFn();\n const oldValues = remoteState.last;\n const diff = styleDiff<T>(oldValues, newValues);\n remoteState.last = Object.assign({}, oldValues, newValues);\n parseColors(diff);\n return diff;\n };\n } else {\n updaterFn = () => {\n 'worklet';\n const newValues = updaterFn();\n const oldValues = remoteState.last;\n const diff = styleDiff<T>(oldValues, newValues);\n remoteState.last = Object.assign({}, oldValues, newValues);\n return diff;\n };\n }\n } else if (!shouldBeUseWeb()) {\n optimalization = 0;\n updaterFn = () => {\n 'worklet';\n const style = updaterFn();\n parseColors(style);\n return style;\n };\n }\n if (typeof updater.__optimalization !== undefined) {\n updaterFn.__optimalization = optimalization;\n }\n\n if (isJest()) {\n fun = () => {\n 'worklet';\n jestStyleUpdater(\n sharableViewDescriptors,\n updater,\n remoteState,\n maybeViewRef,\n animationsActive,\n animatedStyle,\n adaptersArray\n );\n };\n } else {\n fun = () => {\n 'worklet';\n styleUpdater(\n sharableViewDescriptors,\n updaterFn,\n remoteState,\n maybeViewRef,\n animationsActive\n );\n };\n }\n const mapperId = startMapper(\n fun,\n inputs,\n [],\n updaterFn,\n // TODO fix this\n sharableViewDescriptors\n );\n return () => {\n stopMapper(mapperId);\n };\n }, dependencies);\n\n useEffect(() => {\n animationsActive.value = true;\n return () => {\n // initRef.current = null;\n // viewsRef = null;\n animationsActive.value = false;\n };\n }, []);\n\n checkSharedValueUsage(initial.value);\n\n if (process.env.JEST_WORKER_ID) {\n return { viewDescriptors, initial: initial, viewsRef, animatedStyle };\n } else {\n return { viewDescriptors, initial: initial, viewsRef };\n }\n}\n"],"mappings":"AAAA;AACA,SAA2BA,SAA3B,EAAsCC,MAAtC,QAAoD,OAApD;AAEA,SACEC,WADF,EAEEC,UAFF,EAGEC,UAHF,EAIEC,YAJF,EAKEC,YALF,EAMEC,WANF,QAOO,SAPP;AAQA,OAAOC,WAAP,IAAsBC,sBAAtB,QAAoD,gBAApD;AACA,SAASC,iBAAT,QAAkC,cAAlC;AACA,OAAOC,sBAAP,MAAmC,qBAAnC;AACA,SAASC,cAAT,QAA+B,kBAA/B;AACA,SACEC,iBADF,EAEEC,sBAFF,EAGEC,yBAHF,EAIEC,aAJF,EAKEC,UALF,EAMEC,WANF,EAOEC,SAPF,EAQEC,sBARF,QASO,SATP;AAWA,SACEC,sBADF,EAEEC,eAFF,QAKO,uBALP;AAMA,SAASC,MAAT,EAAiBC,cAAjB,QAAuC,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AI,OAAOf,OAAO,CAAC6C,gBAAf,KAAoC9D,SAAxC,EAAmD;MACjD4D,SAAS,CAACE,gBAAV,GAA6BD,cAA7B;IACD;;IAED,IAAI5E,MAAM,EAAV,EAAc;MACZ0E,GAAG,GAAG,MAAM;QACV;;QACAzB,gBAAgB,CACdsB,uBADc,EAEdvC,OAFc,EAGdsC,WAHc,EAIdpC,YAJc,EAKdV,gBALc,EAMd0B,aANc,EAOdc,aAPc,CAAhB;MASD,CAXD;IAYD,CAbD,MAaO;MACLU,GAAG,GAAG,MAAM;QACV;;QACA5C,YAAY,CACVyC,uBADU,EAEVI,SAFU,EAGVL,WAHU,EAIVpC,YAJU,EAKVV,gBALU,CAAZ;MAOD,CATD;IAUD;;IACD,MAAMuD,QAAQ,GAAGpG,WAAW,CAC1B+F,GAD0B,EAE1Bb,MAF0B,EAG1B,EAH0B,EAI1Bc,SAJ0B,EAK1B;IACAJ,uBAN0B,CAA5B;IAQA,OAAO,MAAM;MACX3F,UAAU,CAACmG,QAAD,CAAV;IACD,CAFD;EAGD,CArFQ,EAqFNrB,YArFM,CAAT;EAuFAjF,SAAS,CAAC,MAAM;IACd+C,gBAAgB,CAACX,KAAjB,GAAyB,IAAzB;IACA,OAAO,MAAM;MACX;MACA;MACAW,gBAAgB,CAACX,KAAjB,GAAyB,KAAzB;IACD,CAJD;EAKD,CAPQ,EAON,EAPM,CAAT;EASAwC,qBAAqB,CAACgB,OAAO,CAACxD,KAAT,CAArB;;EAEA,IAAImE,OAAO,CAACC,GAAR,CAAYC,cAAhB,EAAgC;IAC9B,OAAO;MAAEnD,eAAF;MAAmBsC,OAAO,EAAEA,OAA5B;MAAqCV,QAArC;MAA+CT;IAA/C,CAAP;EACD,CAFD,MAEO;IACL,OAAO;MAAEnB,eAAF;MAAmBsC,OAAO,EAAEA,OAA5B;MAAqCV;IAArC,CAAP;EACD;AACF"}
1
+ {"version":3,"names":["useEffect","useRef","startMapper","stopMapper","makeRemote","getTimestamp","updateProps","updatePropsJestWrapper","initialUpdaterRun","NativeReanimatedModule","useSharedValue","buildWorkletsHash","getStyleWithoutAnimations","isAnimated","parseColors","styleDiff","validateAnimatedStyles","makeViewDescriptorsSet","makeViewsRefSet","isJest","shouldBeUseWeb","prepareAnimation","animatedProp","lastAnimation","lastValue","Array","isArray","forEach","prop","index","onFrame","animation","value","current","undefined","callStart","timestamp","onStart","Object","keys","key","runAnimations","result","animationsActive","allFinished","entry","finished","callback","k","styleUpdater","viewDescriptors","updater","state","maybeViewRef","animations","newValues","oldValues","last","hasAnimations","frame","_timestamp","isAnimationCancelled","isAnimationRunning","updates","propName","requestAnimationFrame","_frameTimestamp","assign","style","diff","jestStyleUpdater","animatedStyle","adapters","length","checkSharedValueUsage","currentKey","element","Error","useAnimatedStyle","dependencies","viewsRef","initRef","inputs","values","_closure","adaptersArray","adaptersHash","__workletHash","push","initialStyle","initial","remoteState","sharableViewDescriptors","native","fun","updaterFn","adapter","mapperId","process","env","JEST_WORKER_ID"],"sources":["useAnimatedStyle.ts"],"sourcesContent":["/* global _frameTimestamp */\nimport { MutableRefObject, useEffect, useRef } from 'react';\n\nimport { startMapper, stopMapper, makeRemote, getTimestamp } from '../core';\nimport updateProps, { updatePropsJestWrapper } from '../UpdateProps';\nimport { initialUpdaterRun } from '../animation';\nimport NativeReanimatedModule from '../NativeReanimated';\nimport { useSharedValue } from './useSharedValue';\nimport {\n buildWorkletsHash,\n getStyleWithoutAnimations,\n isAnimated,\n parseColors,\n styleDiff,\n validateAnimatedStyles,\n} from './utils';\nimport { DependencyList, Descriptor } from './commonTypes';\nimport {\n makeViewDescriptorsSet,\n makeViewsRefSet,\n ViewDescriptorsSet,\n ViewRefSet,\n} from '../ViewDescriptorsSet';\nimport { isJest, shouldBeUseWeb } from '../PlatformChecker';\nimport {\n AnimationObject,\n Timestamp,\n AdapterWorkletFunction,\n AnimatedStyle,\n BasicWorkletFunction,\n BasicWorkletFunctionOptional,\n NestedObjectValues,\n SharedValue,\n} from '../commonTypes';\nexport interface AnimatedStyleResult {\n viewDescriptors: ViewDescriptorsSet;\n initial: AnimatedStyle;\n viewsRef: ViewRefSet<any>;\n animatedStyle?: MutableRefObject<AnimatedStyle>;\n}\n\ninterface AnimatedState {\n last: AnimatedStyle;\n animations: AnimatedStyle;\n isAnimationRunning: boolean;\n isAnimationCancelled: boolean;\n}\n\ninterface AnimationRef {\n initial: {\n value: AnimatedStyle;\n updater: () => AnimatedStyle;\n };\n remoteState: AnimatedState;\n viewDescriptors: ViewDescriptorsSet;\n}\n\nfunction prepareAnimation(\n animatedProp: AnimatedStyle,\n lastAnimation: AnimatedStyle,\n lastValue: AnimatedStyle\n): void {\n 'worklet';\n if (Array.isArray(animatedProp)) {\n animatedProp.forEach((prop, index) => {\n prepareAnimation(\n prop,\n lastAnimation && lastAnimation[index],\n lastValue && lastValue[index]\n );\n });\n // return animatedProp;\n }\n if (typeof animatedProp === 'object' && animatedProp.onFrame) {\n const animation = animatedProp;\n\n let value = animation.current;\n if (lastValue !== undefined) {\n if (typeof lastValue === 'object') {\n if (lastValue.value !== undefined) {\n // previously it was a shared value\n value = lastValue.value;\n } else if (lastValue.onFrame !== undefined) {\n if (lastAnimation?.current !== undefined) {\n // it was an animation before, copy its state\n value = lastAnimation.current;\n } else if (lastValue?.current !== undefined) {\n // it was initialized\n value = lastValue.current;\n }\n }\n } else {\n // previously it was a plain value, just set it as starting point\n value = lastValue;\n }\n }\n\n animation.callStart = (timestamp: Timestamp) => {\n animation.onStart(animation, value, timestamp, lastAnimation);\n };\n animation.callStart(getTimestamp());\n animation.callStart = null;\n } else if (typeof animatedProp === 'object') {\n // it is an object\n Object.keys(animatedProp).forEach((key) =>\n prepareAnimation(\n animatedProp[key],\n lastAnimation && lastAnimation[key],\n lastValue && lastValue[key]\n )\n );\n }\n}\n\nfunction runAnimations(\n animation: AnimatedStyle,\n timestamp: Timestamp,\n key: number | string,\n result: AnimatedStyle,\n animationsActive: SharedValue<boolean>\n): boolean {\n 'worklet';\n if (!animationsActive.value) {\n return true;\n }\n if (Array.isArray(animation)) {\n result[key] = [];\n let allFinished = true;\n animation.forEach((entry, index) => {\n if (\n !runAnimations(entry, timestamp, index, result[key], animationsActive)\n ) {\n allFinished = false;\n }\n });\n return allFinished;\n } else if (typeof animation === 'object' && animation.onFrame) {\n let finished = true;\n if (!animation.finished) {\n if (animation.callStart) {\n animation.callStart(timestamp);\n animation.callStart = null;\n }\n finished = animation.onFrame(animation, timestamp);\n animation.timestamp = timestamp;\n if (finished) {\n animation.finished = true;\n animation.callback && animation.callback(true /* finished */);\n }\n }\n result[key] = animation.current;\n return finished;\n } else if (typeof animation === 'object') {\n result[key] = {};\n let allFinished = true;\n Object.keys(animation).forEach((k) => {\n if (\n !runAnimations(\n animation[k],\n timestamp,\n k,\n result[key],\n animationsActive\n )\n ) {\n allFinished = false;\n }\n });\n return allFinished;\n } else {\n result[key] = animation;\n return true;\n }\n}\n\nfunction styleUpdater(\n viewDescriptors: SharedValue<Descriptor[]>,\n updater: BasicWorkletFunction<AnimatedStyle>,\n state: AnimatedState,\n maybeViewRef: ViewRefSet<any> | undefined,\n animationsActive: SharedValue<boolean>\n): void {\n 'worklet';\n const animations = state.animations ?? {};\n const newValues = updater() ?? {};\n const oldValues = state.last;\n\n let hasAnimations = false;\n for (const key in newValues) {\n const value = newValues[key];\n if (isAnimated(value)) {\n prepareAnimation(value, animations[key], oldValues[key]);\n animations[key] = value;\n hasAnimations = true;\n } else {\n delete animations[key];\n }\n }\n\n if (hasAnimations) {\n const frame = (_timestamp?: Timestamp) => {\n const { animations, last, isAnimationCancelled } = state;\n const timestamp = _timestamp ?? getTimestamp();\n if (isAnimationCancelled) {\n state.isAnimationRunning = false;\n return;\n }\n\n const updates: AnimatedStyle = {};\n let allFinished = true;\n for (const propName in animations) {\n const finished = runAnimations(\n animations[propName],\n timestamp,\n propName,\n updates,\n animationsActive\n );\n if (finished) {\n last[propName] = updates[propName];\n delete animations[propName];\n } else {\n allFinished = false;\n }\n }\n\n if (updates) {\n updateProps(viewDescriptors, updates, maybeViewRef);\n }\n\n if (!allFinished) {\n requestAnimationFrame(frame);\n } else {\n state.isAnimationRunning = false;\n }\n };\n\n state.animations = animations;\n if (!state.isAnimationRunning) {\n state.isAnimationCancelled = false;\n state.isAnimationRunning = true;\n if (_frameTimestamp) {\n frame(_frameTimestamp);\n } else {\n requestAnimationFrame(frame);\n }\n }\n state.last = Object.assign({}, oldValues, newValues);\n const style = getStyleWithoutAnimations(state.last);\n if (style) {\n updateProps(viewDescriptors, style, maybeViewRef);\n }\n } else {\n state.isAnimationCancelled = true;\n state.animations = [];\n\n const diff = styleDiff(oldValues, newValues);\n state.last = Object.assign({}, oldValues, newValues);\n if (diff) {\n updateProps(viewDescriptors, newValues, maybeViewRef);\n }\n }\n}\n\nfunction jestStyleUpdater(\n viewDescriptors: SharedValue<Descriptor[]>,\n updater: BasicWorkletFunction<AnimatedStyle>,\n state: AnimatedState,\n maybeViewRef: ViewRefSet<any> | undefined,\n animationsActive: SharedValue<boolean>,\n animatedStyle: MutableRefObject<AnimatedStyle>,\n adapters: AdapterWorkletFunction[] = []\n): void {\n 'worklet';\n const animations: AnimatedStyle = state.animations ?? {};\n const newValues = updater() ?? {};\n const oldValues = state.last;\n\n // extract animated props\n let hasAnimations = false;\n Object.keys(animations).forEach((key) => {\n const value = newValues[key];\n if (!isAnimated(value)) {\n delete animations[key];\n }\n });\n Object.keys(newValues).forEach((key) => {\n const value = newValues[key];\n if (isAnimated(value)) {\n prepareAnimation(value, animations[key], oldValues[key]);\n animations[key] = value;\n hasAnimations = true;\n }\n });\n\n function frame(_timestamp?: Timestamp) {\n const { animations, last, isAnimationCancelled } = state;\n const timestamp = _timestamp ?? getTimestamp();\n if (isAnimationCancelled) {\n state.isAnimationRunning = false;\n return;\n }\n\n const updates: AnimatedStyle = {};\n let allFinished = true;\n Object.keys(animations).forEach((propName) => {\n const finished = runAnimations(\n animations[propName],\n timestamp,\n propName,\n updates,\n animationsActive\n );\n if (finished) {\n last[propName] = updates[propName];\n delete animations[propName];\n } else {\n allFinished = false;\n }\n });\n\n if (Object.keys(updates).length) {\n updatePropsJestWrapper(\n viewDescriptors,\n updates,\n maybeViewRef,\n animatedStyle,\n adapters\n );\n }\n\n if (!allFinished) {\n requestAnimationFrame(frame);\n } else {\n state.isAnimationRunning = false;\n }\n }\n\n if (hasAnimations) {\n state.animations = animations;\n if (!state.isAnimationRunning) {\n state.isAnimationCancelled = false;\n state.isAnimationRunning = true;\n if (_frameTimestamp) {\n frame(_frameTimestamp);\n } else {\n requestAnimationFrame(frame);\n }\n }\n } else {\n state.isAnimationCancelled = true;\n state.animations = [];\n }\n\n // calculate diff\n const diff = styleDiff(oldValues, newValues);\n state.last = Object.assign({}, oldValues, newValues);\n\n if (Object.keys(diff).length !== 0) {\n updatePropsJestWrapper(\n viewDescriptors,\n diff,\n maybeViewRef,\n animatedStyle,\n adapters\n );\n }\n}\n\n// check for invalid usage of shared values in returned object\nfunction checkSharedValueUsage(\n prop: NestedObjectValues<AnimationObject>,\n currentKey?: string\n): void {\n if (Array.isArray(prop)) {\n // if it's an array (i.ex. transform) validate all its elements\n for (const element of prop) {\n checkSharedValueUsage(element, currentKey);\n }\n } else if (typeof prop === 'object' && prop.value === undefined) {\n // if it's a nested object, run validation for all its props\n for (const key of Object.keys(prop)) {\n checkSharedValueUsage(prop[key], key);\n }\n } else if (\n currentKey !== undefined &&\n typeof prop === 'object' &&\n prop.value !== undefined\n ) {\n // if shared value is passed insted of its value, throw an error\n throw new Error(\n `invalid value passed to \\`${currentKey}\\`, maybe you forgot to use \\`.value\\`?`\n );\n }\n}\n\nexport function useAnimatedStyle<T extends AnimatedStyle>(\n updater: BasicWorkletFunction<T>,\n dependencies?: DependencyList,\n adapters?: AdapterWorkletFunction | AdapterWorkletFunction[]\n): AnimatedStyleResult {\n const viewsRef: ViewRefSet<any> = makeViewsRefSet();\n const initRef = useRef<AnimationRef>();\n const inputs = Object.values(updater._closure ?? {});\n const adaptersArray: AdapterWorkletFunction[] = adapters\n ? Array.isArray(adapters)\n ? adapters\n : [adapters]\n : [];\n const adaptersHash = adapters ? buildWorkletsHash(adaptersArray) : null;\n const animationsActive = useSharedValue<boolean>(true);\n const animatedStyle: MutableRefObject<AnimatedStyle> = useRef<AnimatedStyle>(\n {}\n );\n\n // build dependencies\n if (!dependencies) {\n dependencies = [...inputs, updater.__workletHash];\n } else {\n dependencies.push(updater.__workletHash);\n }\n adaptersHash && dependencies.push(adaptersHash);\n\n if (!initRef.current) {\n const initialStyle: AnimatedStyle = initialUpdaterRun(updater);\n validateAnimatedStyles(initialStyle);\n initRef.current = {\n initial: {\n value: initialStyle,\n updater: updater,\n },\n remoteState: makeRemote<AnimatedState>({\n last: initialStyle,\n animations: {},\n isAnimationCancelled: false,\n isAnimationRunning: false,\n }),\n viewDescriptors: makeViewDescriptorsSet(),\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { initial, remoteState, viewDescriptors } = initRef.current!;\n const sharableViewDescriptors = viewDescriptors.sharableViewDescriptors;\n const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;\n\n dependencies.push(sharableViewDescriptors);\n\n useEffect(() => {\n let fun;\n let updaterFn = updater as BasicWorkletFunctionOptional<T>;\n if (adapters) {\n updaterFn = () => {\n 'worklet';\n const newValues = updater();\n adaptersArray.forEach((adapter) => {\n adapter(newValues);\n });\n return newValues;\n };\n }\n\n if (!shouldBeUseWeb()) {\n updaterFn = () => {\n 'worklet';\n const style = updaterFn();\n parseColors(style);\n return style;\n };\n }\n\n if (isJest()) {\n fun = () => {\n 'worklet';\n jestStyleUpdater(\n sharableViewDescriptors,\n updater,\n remoteState,\n maybeViewRef,\n animationsActive,\n animatedStyle,\n adaptersArray\n );\n };\n } else {\n fun = () => {\n 'worklet';\n styleUpdater(\n sharableViewDescriptors,\n updaterFn,\n remoteState,\n maybeViewRef,\n animationsActive\n );\n };\n }\n const mapperId = startMapper(fun, inputs);\n return () => {\n stopMapper(mapperId);\n };\n }, dependencies);\n\n useEffect(() => {\n animationsActive.value = true;\n return () => {\n // initRef.current = null;\n // viewsRef = null;\n animationsActive.value = false;\n };\n }, []);\n\n checkSharedValueUsage(initial.value);\n\n if (process.env.JEST_WORKER_ID) {\n return { viewDescriptors, initial: initial, viewsRef, animatedStyle };\n } else {\n return { viewDescriptors, initial: initial, viewsRef };\n }\n}\n"],"mappings":"AAAA;AACA,SAA2BA,SAA3B,EAAsCC,MAAtC,QAAoD,OAApD;AAEA,SAASC,WAAT,EAAsBC,UAAtB,EAAkCC,UAAlC,EAA8CC,YAA9C,QAAkE,SAAlE;AACA,OAAOC,WAAP,IAAsBC,sBAAtB,QAAoD,gBAApD;AACA,SAASC,iBAAT,QAAkC,cAAlC;AACA,OAAOC,sBAAP,MAAmC,qBAAnC;AACA,SAASC,cAAT,QAA+B,kBAA/B;AACA,SACEC,iBADF,EAEEC,yBAFF,EAGEC,UAHF,EAIEC,WAJF,EAKEC,SALF,EAMEC,sBANF,QAOO,SAPP;AASA,SACEC,sBADF,EAEEC,eAFF,QAKO,uBALP;AAMA,SAASC,MAAT,EAAiBC,cAAjB,QAAuC,oBAAvC;;AAkCA,SAASC,gBAAT,CACEC,YADF,EAEEC,aAFF,EAGEC,SAHF,EAIQ;EACN;;EACA,IAAIC,KAAK,CAACC,OAAN,CAAcJ,YAAd,CAAJ,EAAiC;IAC/BA,YAAY,CAACK,OAAb,CAAqB,CAACC,IAAD,EAAOC,KAAP,KAAiB;MACpCR,gBAAgB,CACdO,IADc,EAEdL,aAAa,IAAIA,aAAa,CAACM,KAAD,CAFhB,EAGdL,SAAS,IAAIA,SAAS,CAACK,KAAD,CAHR,CAAhB;IAKD,CAND,EAD+B,CAQ/B;EACD;;EACD,IAAI,OAAOP,YAAP,KAAwB,QAAxB,IAAoCA,YAAY,CAACQ,OAArD,EAA8D;IAC5D,MAAMC,SAAS,GAAGT,YAAlB;IAEA,IAAIU,KAAK,GAAGD,SAAS,CAACE,OAAtB;;IACA,IAA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hB;MASD,CAXD;IAYD,CAbD,MAaO;MACLS,GAAG,GAAG,MAAM;QACV;;QACA7C,YAAY,CACV2C,uBADU,EAEVG,SAFU,EAGVJ,WAHU,EAIVtC,YAJU,EAKVV,gBALU,CAAZ;MAOD,CATD;IAUD;;IACD,MAAMsD,QAAQ,GAAG/F,WAAW,CAAC4F,GAAD,EAAMZ,MAAN,CAA5B;IACA,OAAO,MAAM;MACX/E,UAAU,CAAC8F,QAAD,CAAV;IACD,CAFD;EAGD,CApDQ,EAoDNlB,YApDM,CAAT;EAsDA/E,SAAS,CAAC,MAAM;IACd2C,gBAAgB,CAACX,KAAjB,GAAyB,IAAzB;IACA,OAAO,MAAM;MACX;MACA;MACAW,gBAAgB,CAACX,KAAjB,GAAyB,KAAzB;IACD,CAJD;EAKD,CAPQ,EAON,EAPM,CAAT;EASA0C,qBAAqB,CAACgB,OAAO,CAAC1D,KAAT,CAArB;;EAEA,IAAIkE,OAAO,CAACC,GAAR,CAAYC,cAAhB,EAAgC;IAC9B,OAAO;MAAElD,eAAF;MAAmBwC,OAAO,EAAEA,OAA5B;MAAqCV,QAArC;MAA+CT;IAA/C,CAAP;EACD,CAFD,MAEO;IACL,OAAO;MAAErB,eAAF;MAAmBwC,OAAO,EAAEA,OAA5B;MAAqCV;IAArC,CAAP;EACD;AACF"}
@@ -2,10 +2,11 @@ import { useEffect, useRef } from 'react';
2
2
  import { cancelAnimation } from '../animation';
3
3
  import { makeMutable } from '../core';
4
4
  export function useSharedValue(init) {
5
- const ref = useRef(makeMutable(init));
5
+ let oneWayReadsOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
6
+ const ref = useRef(makeMutable(init, oneWayReadsOnly));
6
7
 
7
8
  if (ref.current === null) {
8
- ref.current = makeMutable(init);
9
+ ref.current = makeMutable(init, oneWayReadsOnly);
9
10
  }
10
11
 
11
12
  useEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useRef","cancelAnimation","makeMutable","useSharedValue","init","ref","current"],"sources":["useSharedValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { cancelAnimation } from '../animation';\nimport { SharedValue } from '../commonTypes';\nimport { makeMutable } from '../core';\n\nexport function useSharedValue<T>(init: T): SharedValue<T> {\n const ref = useRef<SharedValue<T>>(makeMutable(init));\n\n if (ref.current === null) {\n ref.current = makeMutable(init);\n }\n\n useEffect(() => {\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n cancelAnimation(ref.current!);\n };\n }, []);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return ref.current!;\n}\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,SAASC,eAAT,QAAgC,cAAhC;AAEA,SAASC,WAAT,QAA4B,SAA5B;AAEA,OAAO,SAASC,cAAT,CAA2BC,IAA3B,EAAoD;EACzD,MAAMC,GAAG,GAAGL,MAAM,CAAiBE,WAAW,CAACE,IAAD,CAA5B,CAAlB;;EAEA,IAAIC,GAAG,CAACC,OAAJ,KAAgB,IAApB,EAA0B;IACxBD,GAAG,CAACC,OAAJ,GAAcJ,WAAW,CAACE,IAAD,CAAzB;EACD;;EAEDL,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX;MACAE,eAAe,CAACI,GAAG,CAACC,OAAL,CAAf;IACD,CAHD;EAID,CALQ,EAKN,EALM,CAAT,CAPyD,CAczD;;EACA,OAAOD,GAAG,CAACC,OAAX;AACD"}
1
+ {"version":3,"names":["useEffect","useRef","cancelAnimation","makeMutable","useSharedValue","init","oneWayReadsOnly","ref","current"],"sources":["useSharedValue.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { cancelAnimation } from '../animation';\nimport { SharedValue } from '../commonTypes';\nimport { makeMutable } from '../core';\n\nexport function useSharedValue<T>(\n init: T,\n oneWayReadsOnly = false\n): SharedValue<T> {\n const ref = useRef<SharedValue<T>>(makeMutable(init, oneWayReadsOnly));\n\n if (ref.current === null) {\n ref.current = makeMutable(init, oneWayReadsOnly);\n }\n\n useEffect(() => {\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n cancelAnimation(ref.current!);\n };\n }, []);\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return ref.current!;\n}\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,SAASC,eAAT,QAAgC,cAAhC;AAEA,SAASC,WAAT,QAA4B,SAA5B;AAEA,OAAO,SAASC,cAAT,CACLC,IADK,EAGW;EAAA,IADhBC,eACgB,uEADE,KACF;EAChB,MAAMC,GAAG,GAAGN,MAAM,CAAiBE,WAAW,CAACE,IAAD,EAAOC,eAAP,CAA5B,CAAlB;;EAEA,IAAIC,GAAG,CAACC,OAAJ,KAAgB,IAApB,EAA0B;IACxBD,GAAG,CAACC,OAAJ,GAAcL,WAAW,CAACE,IAAD,EAAOC,eAAP,CAAzB;EACD;;EAEDN,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX;MACAE,eAAe,CAACK,GAAG,CAACC,OAAL,CAAf;IACD,CAHD;EAID,CALQ,EAKN,EALM,CAAT,CAPgB,CAchB;;EACA,OAAOD,GAAG,CAACC,OAAX;AACD"}