react-native-reanimated 2.10.0 → 2.12.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 (146) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +3 -0
  2. package/Common/cpp/{headers/AnimatedSensor → AnimatedSensor}/AnimatedSensorModule.h +0 -0
  3. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +2 -0
  4. package/Common/cpp/{headers/LayoutAnimations → LayoutAnimations}/LayoutAnimationsProxy.h +0 -0
  5. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +2 -0
  6. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModule.h +5 -0
  7. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +2 -0
  8. package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModuleSpec.h +1 -1
  9. package/Common/cpp/{headers/Registries → Registries}/EventHandlerRegistry.h +0 -0
  10. package/Common/cpp/Registries/MapperRegistry.cpp +3 -1
  11. package/Common/cpp/{headers/Registries → Registries}/MapperRegistry.h +0 -0
  12. package/Common/cpp/Registries/WorkletsCache.cpp +3 -0
  13. package/Common/cpp/{headers/Registries → Registries}/WorkletsCache.h +0 -0
  14. package/Common/cpp/{headers/SharedItems → SharedItems}/FrozenObject.h +0 -0
  15. package/Common/cpp/{headers/SharedItems → SharedItems}/HostFunctionHandler.h +0 -0
  16. package/Common/cpp/SharedItems/MutableValue.cpp +2 -0
  17. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValue.h +0 -0
  18. package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValueSetterProxy.h +0 -0
  19. package/Common/cpp/{headers/SharedItems → SharedItems}/RemoteObject.h +0 -0
  20. package/Common/cpp/{headers/SharedItems → SharedItems}/RuntimeManager.h +0 -0
  21. package/Common/cpp/SharedItems/ShareableValue.cpp +7 -2
  22. package/Common/cpp/{headers/SharedItems → SharedItems}/ShareableValue.h +0 -0
  23. package/Common/cpp/{headers/SharedItems → SharedItems}/SharedParent.h +0 -0
  24. package/Common/cpp/{headers/SharedItems → SharedItems}/ValueWrapper.h +0 -0
  25. package/Common/cpp/{headers/SpecTools → SpecTools}/ErrorHandler.h +0 -0
  26. package/Common/cpp/{headers/Tools → Tools}/FeaturesConfig.h +0 -0
  27. package/Common/cpp/Tools/JSIStoreValueUser.cpp +2 -2
  28. package/Common/cpp/{headers/Tools → Tools}/JSIStoreValueUser.h +0 -0
  29. package/Common/cpp/{headers/Tools → Tools}/Mapper.h +0 -0
  30. package/Common/cpp/{headers/Tools → Tools}/PlatformDepMethodsHolder.h +0 -0
  31. package/Common/cpp/{headers/Tools → Tools}/ReanimatedHiddenHeaders.h +1 -1
  32. package/Common/cpp/{headers/Tools → Tools}/RuntimeDecorator.h +0 -0
  33. package/Common/cpp/{headers/Tools → Tools}/Scheduler.h +0 -0
  34. package/Common/cpp/Tools/SingleInstanceChecker.h +58 -0
  35. package/Common/cpp/{headers/Tools → Tools}/WorkletEventHandler.h +0 -0
  36. package/RNReanimated.podspec +19 -75
  37. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  38. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  39. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  40. package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  41. package/android/.gradle/{7.2 → 7.5.1}/dependencies-accessors/gc.properties +0 -0
  42. package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
  43. package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
  44. package/android/.gradle/{7.2 → 7.5.1}/fileChanges/last-build.bin +0 -0
  45. package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
  46. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  47. package/android/.gradle/{7.2 → 7.5.1}/fileHashes/resourceHashesCache.bin +0 -0
  48. package/android/.gradle/{7.2 → 7.5.1}/gc.properties +0 -0
  49. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  50. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  51. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  52. package/android/.gradle/file-system.probe +0 -0
  53. package/android/CMakeLists.txt +56 -65
  54. package/android/build.gradle +422 -120
  55. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  56. package/android/react-native-reanimated-66-hermes.aar +0 -0
  57. package/android/react-native-reanimated-66-jsc.aar +0 -0
  58. package/android/react-native-reanimated-67-hermes.aar +0 -0
  59. package/android/react-native-reanimated-67-jsc.aar +0 -0
  60. package/android/react-native-reanimated-68-hermes.aar +0 -0
  61. package/android/react-native-reanimated-68-jsc.aar +0 -0
  62. package/android/react-native-reanimated-69-hermes.aar +0 -0
  63. package/android/react-native-reanimated-69-jsc.aar +0 -0
  64. package/android/react-native-reanimated-70-hermes.aar +0 -0
  65. package/android/react-native-reanimated-70-jsc.aar +0 -0
  66. package/android/src/main/cpp/AndroidErrorHandler.cpp +3 -4
  67. package/android/src/main/cpp/{headers/AndroidErrorHandler.h → AndroidErrorHandler.h} +1 -4
  68. package/android/src/main/cpp/AndroidLogger.cpp +4 -1
  69. package/android/src/main/cpp/{headers/AndroidLogger.h → AndroidLogger.h} +0 -0
  70. package/android/src/main/cpp/{headers/AndroidScheduler.h → AndroidScheduler.h} +0 -0
  71. package/android/src/main/cpp/{headers/JNIHelper.h → JNIHelper.h} +0 -0
  72. package/android/src/main/cpp/{headers/LayoutAnimations.h → LayoutAnimations.h} +0 -0
  73. package/android/src/main/cpp/NativeProxy.cpp +6 -8
  74. package/android/src/main/cpp/{headers/NativeProxy.h → NativeProxy.h} +0 -0
  75. package/android/src/main/cpp/{headers/TurboModule.h → TurboModule.h} +0 -0
  76. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +4 -5
  77. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +2 -1
  78. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +2 -2
  79. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +1 -1
  80. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/UIImplementation/64/com/swmansion/reanimated}/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  81. package/android/src/{main/java → reactNativeVersionPatch/UIImplementation/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  82. package/android/src/reactNativeVersionPatch/messageQueueThread/67/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  83. package/android/src/reactNativeVersionPatch/messageQueueThread/latest/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  84. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/nativeHierarchyManager/62/com/swmansion/reanimated}/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  85. package/android/src/{main/java → reactNativeVersionPatch/nativeHierarchyManager/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  86. package/ios/{REAModule.m → REAModule.mm} +29 -0
  87. package/ios/keyboardObserver/REAKeyboardEventObserver.m +1 -1
  88. package/ios/native/NativeProxy.mm +4 -2
  89. package/ios/native/REAInitializer.h +2 -2
  90. package/ios/native/REAInitializer.mm +2 -2
  91. package/ios/native/UIResponder+Reanimated.mm +1 -1
  92. package/lib/createAnimatedComponent.js +3 -4
  93. package/lib/index.web.js +2 -0
  94. package/lib/reanimated2/NativeMethods.js +79 -30
  95. package/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
  96. package/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.js +47 -18
  97. package/lib/reanimated2/globals.d.ts +38 -12
  98. package/lib/reanimated2/hook/index.js +1 -0
  99. package/lib/reanimated2/hook/useScrollViewOffset.js +27 -0
  100. package/lib/reanimated2/utils.js +10 -3
  101. package/lib/types/index.web.d.ts +1 -0
  102. package/lib/types/reanimated2/NativeMethods.d.ts +4 -11
  103. package/lib/types/reanimated2/commonTypes.d.ts +8 -0
  104. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryJS.d.ts +4 -3
  105. package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryUI.d.ts +17 -7
  106. package/lib/types/reanimated2/hook/index.d.ts +1 -0
  107. package/lib/types/reanimated2/hook/useAnimatedScrollHandler.d.ts +1 -2
  108. package/lib/types/reanimated2/hook/useFrameCallback.d.ts +2 -1
  109. package/lib/types/reanimated2/hook/useScrollViewOffset.d.ts +4 -0
  110. package/lib/types/reanimated2/utils.d.ts +5 -1
  111. package/package.json +8 -6
  112. package/plugin.js +1 -1
  113. package/react-native-reanimated.d.ts +13 -9
  114. package/scripts/reanimated_utils.rb +77 -0
  115. package/src/createAnimatedComponent.tsx +2 -3
  116. package/src/index.web.ts +2 -0
  117. package/src/reanimated2/NativeMethods.ts +104 -48
  118. package/src/reanimated2/commonTypes.ts +9 -0
  119. package/src/reanimated2/frameCallback/FrameCallbackRegistryJS.ts +6 -9
  120. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +78 -27
  121. package/src/reanimated2/globals.d.ts +38 -12
  122. package/src/reanimated2/hook/index.ts +1 -0
  123. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -1
  124. package/src/reanimated2/hook/useFrameCallback.ts +2 -1
  125. package/src/reanimated2/hook/useScrollViewOffset.ts +37 -0
  126. package/src/reanimated2/utils.ts +12 -5
  127. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  128. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  129. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  130. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  131. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  132. package/android/.gradle/checksums/checksums.lock +0 -0
  133. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  134. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  135. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  136. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  137. package/android/rnVersionPatch/65/.gitkeep +0 -0
  138. package/android/rnVersionPatch/66/.gitkeep +0 -0
  139. package/android/rnVersionPatch/67/.gitkeep +0 -0
  140. package/android/rnVersionPatch/68/.gitkeep +0 -0
  141. package/android/rnVersionPatch/69/.gitkeep +0 -0
  142. package/android/rnVersionPatch/70/.gitkeep +0 -0
  143. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  144. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +0 -8
  145. package/lib/reanimated2/__mocks__/NativeReanimated.native.js +0 -20
  146. package/lib/types/reanimated2/__mocks__/NativeReanimated.native.d.ts +0 -13
@@ -1,13 +1,19 @@
1
- import { AnimatedStyle, StyleProps } from './commonTypes';
2
- import { ReanimatedConsole } from './core';
3
- import FrameCallbackRegistryUI from './frameCallback/FrameCallbackRegistryUI';
4
- import { MeasuredDimensions } from './NativeMethods';
5
- import { NativeReanimated } from './NativeReanimated/NativeReanimated';
1
+ import type {
2
+ AnimatedStyle,
3
+ StyleProps,
4
+ MeasuredDimensions,
5
+ } from './commonTypes';
6
+ import type { ReanimatedConsole } from './core';
7
+ import type { NativeReanimated } from './NativeReanimated/NativeReanimated';
8
+ import type { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';
9
+
6
10
  declare global {
7
11
  const _WORKLET: boolean;
8
- const _frameTimestamp: number;
12
+ const _frameTimestamp: number | null;
9
13
  const _eventTimestamp: number;
14
+ const __reanimatedModuleProxy: NativeReanimated;
10
15
  const _setGlobalConsole: (console?: ReanimatedConsole) => void;
16
+ const _log: (s: string) => void;
11
17
  const _getCurrentTime: () => number;
12
18
  const _stopObservingProgress: (tag: number, flag: boolean) => void;
13
19
  const _startObservingProgress: (
@@ -28,20 +34,40 @@ declare global {
28
34
  animated: boolean
29
35
  ) => void;
30
36
  const _chronoNow: () => number;
37
+ const performance: { now: () => number };
38
+ const LayoutAnimationRepository: {
39
+ configs: Record<string, unknown>;
40
+ registerConfig(tag: number, config: Record<string, unknown>): void;
41
+ removeConfig(tag: number): void;
42
+ startAnimationForTag(tag: number, type: string, yogaValues: unknown): void;
43
+ };
31
44
  const ReanimatedDataMock: {
32
45
  now: () => number;
33
46
  };
34
47
  const _frameCallbackRegistry: FrameCallbackRegistryUI;
35
48
  namespace NodeJS {
36
49
  interface Global {
37
- _setGlobalConsole: (console?: ReanimatedConsole) => void;
38
- _log: (s: string) => void;
39
- _setGestureState: () => void;
40
50
  _WORKLET: boolean;
41
- __reanimatedModuleProxy: NativeReanimated;
51
+ _IS_FABRIC: boolean;
42
52
  _frameTimestamp: number | null;
43
- _measure: () => MeasuredDimensions;
44
- _scrollTo: () => void;
53
+ _eventTimestamp: number;
54
+ __reanimatedModuleProxy: NativeReanimated;
55
+ _setGlobalConsole: (console?: ReanimatedConsole) => void;
56
+ _log: (s: string) => void;
57
+ _getCurrentTime: () => number;
58
+ _stopObservingProgress: (tag: number, flag: boolean) => void;
59
+ _startObservingProgress: (
60
+ tag: number,
61
+ flag: { value: boolean; _value: boolean }
62
+ ) => void;
63
+ _setGestureState: (handlerTag: number, newState: number) => void;
64
+ _measure: (viewTag: number) => MeasuredDimensions;
65
+ _scrollTo: (
66
+ viewTag: number,
67
+ x: number,
68
+ y: number,
69
+ animated: boolean
70
+ ) => void;
45
71
  _chronoNow: () => number;
46
72
  performance: { now: () => number };
47
73
  LayoutAnimationRepository: {
@@ -9,3 +9,4 @@ export { useDerivedValue } from './useDerivedValue';
9
9
  export { useAnimatedSensor, SensorType } from './useAnimatedSensor';
10
10
  export { useFrameCallback } from './useFrameCallback';
11
11
  export { useAnimatedKeyboard } from './useAnimatedKeyboard';
12
+ export { useScrollViewOffset } from './useScrollViewOffset';
@@ -0,0 +1,27 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { findNodeHandle } from 'react-native';
3
+ import { useEvent } from './utils';
4
+ import { useSharedValue } from './useSharedValue';
5
+ const subscribeForEvents = [
6
+ 'onScroll',
7
+ 'onScrollBeginDrag',
8
+ 'onScrollEndDrag',
9
+ 'onMomentumScrollBegin',
10
+ 'onMomentumScrollEnd',
11
+ ];
12
+ export function useScrollViewOffset(aref) {
13
+ const offsetRef = useRef(useSharedValue(0));
14
+ const event = useEvent((event) => {
15
+ 'worklet';
16
+ offsetRef.current.value =
17
+ event.contentOffset.x === 0
18
+ ? event.contentOffset.y
19
+ : event.contentOffset.x;
20
+ }, subscribeForEvents);
21
+ useEffect(() => {
22
+ var _a;
23
+ const viewTag = findNodeHandle(aref.current);
24
+ (_a = event.current) === null || _a === void 0 ? void 0 : _a.registerForEvents(viewTag);
25
+ }, [aref.current]);
26
+ return offsetRef.current;
27
+ }
@@ -1,9 +1,16 @@
1
1
  import { measure } from './NativeMethods';
2
- export function getRelativeCoords(parentRef, x, y) {
2
+ /**
3
+ * Given an absolute position and a component ref, returns the relative
4
+ * position in the component's local coordinate space.
5
+ */
6
+ export function getRelativeCoords(parentRef, absoluteX, absoluteY) {
3
7
  'worklet';
4
8
  const parentCoords = measure(parentRef);
9
+ if (parentCoords === null) {
10
+ return null;
11
+ }
5
12
  return {
6
- x: x - parentCoords.x,
7
- y: y - parentCoords.y,
13
+ x: absoluteX - parentCoords.x,
14
+ y: absoluteY - parentCoords.y,
8
15
  };
9
16
  }
@@ -1,3 +1,4 @@
1
1
  import './reanimated2/js-reanimated/global';
2
+ export * from './reanimated1';
2
3
  export * from './reanimated2';
3
4
  export * as default from './Animated';
@@ -1,14 +1,7 @@
1
1
  import { Component } from 'react';
2
- import { RefObjectFunction } from './commonTypes';
2
+ import { MeasuredDimensions } from './commonTypes';
3
+ import { RefObjectFunction } from './hook/commonTypes';
3
4
  export declare function getTag(view: null | number | React.Component<any, any> | React.ComponentClass<any>): null | number;
4
- export interface MeasuredDimensions {
5
- x: number;
6
- y: number;
7
- width: number;
8
- height: number;
9
- pageX: number;
10
- pageY: number;
11
- }
12
- export declare function measure(animatedRef: RefObjectFunction<Component>): MeasuredDimensions;
13
- export declare function scrollTo(animatedRef: RefObjectFunction<Component>, x: number, y: number, animated: boolean): void;
5
+ export declare let measure: (animatedRef: RefObjectFunction<Component>) => MeasuredDimensions | null;
6
+ export declare let scrollTo: (animatedRef: RefObjectFunction<Component>, x: number, y: number, animated: boolean) => void;
14
7
  export declare function setGestureState(handlerTag: number, newState: number): void;
@@ -89,3 +89,11 @@ export declare type AnimatedKeyboardInfo = {
89
89
  height: SharedValue<number>;
90
90
  state: SharedValue<KeyboardState>;
91
91
  };
92
+ export interface MeasuredDimensions {
93
+ x: number;
94
+ y: number;
95
+ width: number;
96
+ height: number;
97
+ pageX: number;
98
+ pageY: number;
99
+ }
@@ -1,7 +1,8 @@
1
+ import { FrameInfo } from './FrameCallbackRegistryUI';
1
2
  export default class FrameCallbackRegistryJS {
2
3
  private nextCallbackId;
3
4
  constructor();
4
- registerFrameCallback(callback: () => void): number;
5
- unregisterFrameCallback(frameCallbackId: number): void;
6
- manageStateFrameCallback(frameCallbackId: number, state: boolean): void;
5
+ registerFrameCallback(callback: (frameInfo: FrameInfo) => void): number;
6
+ unregisterFrameCallback(callbackId: number): void;
7
+ manageStateFrameCallback(callbackId: number, state: boolean): void;
7
8
  }
@@ -1,10 +1,20 @@
1
- export default interface FrameCallbackRegistryUI {
2
- frameCallbackRegistry: Map<number, () => void>;
3
- frameCallbackActive: Set<number>;
4
- isFrameCallbackRunning: boolean;
1
+ declare type CallbackDetails = {
2
+ callback: (frameInfo: FrameInfo) => void;
3
+ startTime: number | null;
4
+ };
5
+ export declare type FrameInfo = {
6
+ timestamp: number;
7
+ timeSincePreviousFrame: number | null;
8
+ timeSinceFirstFrame: number;
9
+ };
10
+ export interface FrameCallbackRegistryUI {
11
+ frameCallbackRegistry: Map<number, CallbackDetails>;
12
+ activeFrameCallbacks: Set<number>;
13
+ previousFrameTimestamp: number | null;
5
14
  runCallbacks: () => void;
6
- registerFrameCallback: (callback: () => void, callbackId: number) => void;
7
- unregisterFrameCallback: (frameCallbackId: number) => void;
8
- manageStateFrameCallback: (frameCallbackId: number, state: boolean) => void;
15
+ registerFrameCallback: (callback: (frameInfo: FrameInfo) => void, callbackId: number) => void;
16
+ unregisterFrameCallback: (callbackId: number) => void;
17
+ manageStateFrameCallback: (callbackId: number, state: boolean) => void;
9
18
  }
10
19
  export declare const prepareUIRegistry: () => void;
20
+ export {};
@@ -11,3 +11,4 @@ export { useAnimatedSensor, SensorType } from './useAnimatedSensor';
11
11
  export { useFrameCallback } from './useFrameCallback';
12
12
  export type { FrameCallback } from './useFrameCallback';
13
13
  export { useAnimatedKeyboard } from './useAnimatedKeyboard';
14
+ export { useScrollViewOffset } from './useScrollViewOffset';
@@ -6,7 +6,7 @@ import { Context, DependencyList } from './commonTypes';
6
6
  export interface ScrollHandler<TContext extends Context> extends WorkletFunction {
7
7
  (event: NativeScrollEvent, context?: TContext): void;
8
8
  }
9
- interface ScrollEvent extends NativeScrollEvent, NativeEvent<ScrollEvent> {
9
+ export interface ScrollEvent extends NativeScrollEvent, NativeEvent<ScrollEvent> {
10
10
  eventName: string;
11
11
  }
12
12
  export interface ScrollHandlers<TContext extends Context> {
@@ -18,4 +18,3 @@ export interface ScrollHandlers<TContext extends Context> {
18
18
  onMomentumEnd?: ScrollHandler<TContext>;
19
19
  }
20
20
  export declare function useAnimatedScrollHandler<TContext extends Context>(handlers: ScrollHandlers<TContext> | ScrollHandler<TContext>, dependencies?: DependencyList): RefObject<WorkletEventHandler<ScrollEvent>>;
21
- export {};
@@ -1,6 +1,7 @@
1
+ import { FrameInfo } from '../frameCallback/FrameCallbackRegistryUI';
1
2
  export declare type FrameCallback = {
2
3
  setActive: (isActive: boolean) => void;
3
4
  isActive: boolean;
4
5
  callbackId: number;
5
6
  };
6
- export declare function useFrameCallback(callback: () => void, autostart?: boolean): FrameCallback;
7
+ export declare function useFrameCallback(callback: (frameInfo: FrameInfo) => void, autostart?: boolean): FrameCallback;
@@ -0,0 +1,4 @@
1
+ import { RefObject } from 'react';
2
+ import type Animated from 'react-native-reanimated';
3
+ import { SharedValue } from '../commonTypes';
4
+ export declare function useScrollViewOffset(aref: RefObject<Animated.ScrollView>): SharedValue<number>;
@@ -4,4 +4,8 @@ export interface ComponentCoords {
4
4
  x: number;
5
5
  y: number;
6
6
  }
7
- export declare function getRelativeCoords(parentRef: RefObjectFunction<Component>, x: number, y: number): ComponentCoords;
7
+ /**
8
+ * Given an absolute position and a component ref, returns the relative
9
+ * position in the component's local coordinate space.
10
+ */
11
+ export declare function getRelativeCoords(parentRef: RefObjectFunction<Component>, absoluteX: number, absoluteY: number): ComponentCoords | null;
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "react-native-reanimated",
3
- "version": "2.10.0",
3
+ "version": "2.12.0",
4
4
  "description": "More powerful alternative to Animated library for React Native.",
5
5
  "scripts": {
6
6
  "test": "yarn run format:js && yarn run lint:js && yarn run test:unit",
7
7
  "test:unit": "jest",
8
- "lint": "yarn lint:js && yarn lint:cpp && yarn lint:java",
8
+ "lint": "yarn lint:js && yarn lint:cpp && yarn lint:java && yarn lint:ios && yarn lint:docs",
9
9
  "lint:js": "eslint --ext '.js,.ts,.tsx' src/ && yarn prettier --check src/",
10
10
  "lint:java": "./android/gradlew -p android spotlessCheck -q",
11
11
  "lint:cpp": "./scripts/cpplint.sh",
12
+ "lint:ios": "./scripts/validate-ios.sh",
12
13
  "format": "yarn format:js && yarn format:java && yarn format:ios && yarn format:android && yarn format:common",
13
14
  "format:js": "prettier --write --list-different './src/'",
14
15
  "format:java": "node ./scripts/format-java.js",
@@ -26,7 +27,7 @@
26
27
  "type:generate:remove.tsx": "find ./lib -type f -name \"*.tsx\" -and -not -name \"*.d.ts\" -delete",
27
28
  "type:generate:remove.js:from-src": "find ./src/reanimated2 -type f -name \"*.js\" -delete",
28
29
  "prepare": "husky install",
29
- "circular_dependency_check": "yarn madge --extensions js,ts,tsx --circular ./src",
30
+ "circular_dependency_check": "yarn madge --extensions js,ts,tsx --circular src lib",
30
31
  "setup": "yarn && cd Example && yarn && cd ios && pod install --verbose && cd ../..",
31
32
  "clean": "rm -rf node_modules && cd Example && rm -rf node_modules && cd ios && pod deintegrate && cd ../..",
32
33
  "reset": "yarn clean && yarn setup",
@@ -50,6 +51,7 @@
50
51
  "!ios/build/",
51
52
  "!android/build/",
52
53
  "RNReanimated.podspec",
54
+ "scripts/reanimated_utils.rb",
53
55
  "README.md",
54
56
  "react-native-reanimated.d.ts",
55
57
  "mock.js",
@@ -93,7 +95,7 @@
93
95
  "@react-native-community/bob": "^0.17.1",
94
96
  "@react-native-community/eslint-config": "^0.0.5",
95
97
  "@testing-library/jest-native": "^4.0.4",
96
- "@testing-library/react-hooks": "^5.0.3",
98
+ "@testing-library/react-hooks": "^8.0.0",
97
99
  "@testing-library/react-native": "^7.1.0",
98
100
  "@types/babel-types": "^7.0.11",
99
101
  "@types/babel__core": "^7.1.18",
@@ -121,11 +123,11 @@
121
123
  "madge": "^5.0.1",
122
124
  "prettier": "^2.5.1",
123
125
  "react": "17.0.2",
124
- "react-native": "0.70.0-rc.3",
126
+ "react-native": "0.70.3",
125
127
  "react-native-builder-bob": "^0.18.3",
126
128
  "react-native-codegen": "^0.0.7",
127
129
  "react-native-gesture-handler": "^1.6.1",
128
- "react-test-renderer": "18.0.0",
130
+ "react-test-renderer": "17.0.2",
129
131
  "release-it": "^13.7.2",
130
132
  "typescript": "^4.1.3"
131
133
  },
package/plugin.js CHANGED
@@ -447,7 +447,7 @@ function makeWorklet(t, fun, state) {
447
447
  const workletHash = hash(funString);
448
448
 
449
449
  let location = state.file.opts.filename;
450
- if (state.opts.relativeSourceLocation) {
450
+ if (state.opts && state.opts.relativeSourceLocation) {
451
451
  const path = require('path');
452
452
  location = path.relative(state.cwd, location);
453
453
  }
@@ -54,6 +54,8 @@ declare module 'react-native-reanimated' {
54
54
  import('./lib/types/lib/reanimated2/animation/index').StyleLayoutAnimation;
55
55
  export type Animation<T> =
56
56
  import('./lib/types/lib/reanimated2/commonTypes').Animation<T>;
57
+ export type MeasuredDimensions =
58
+ import('./lib/types/lib/reanimated2/commonTypes').MeasuredDimensions;
57
59
 
58
60
  namespace Animated {
59
61
  type Nullable<T> = T | null | undefined;
@@ -543,8 +545,13 @@ declare module 'react-native-reanimated' {
543
545
  isActive: boolean;
544
546
  callbackId: number;
545
547
  };
548
+ export type FrameInfo = {
549
+ timestamp: number;
550
+ timeSincePreviousFrame: number | null;
551
+ timeSinceFirstFrame: number;
552
+ };
546
553
  export function useFrameCallback(
547
- callback: () => void,
554
+ callback: (frameInfo: FrameInfo) => void,
548
555
  autostart?: boolean
549
556
  ): FrameCallback;
550
557
 
@@ -561,6 +568,10 @@ declare module 'react-native-reanimated' {
561
568
  };
562
569
  export function useAnimatedKeyboard(): AnimatedKeyboardInfo;
563
570
 
571
+ export function useScrollViewOffset(
572
+ aref: RefObject<Animated.ScrollView>
573
+ ): SharedValue<number>;
574
+
564
575
  export interface ExitAnimationsValues {
565
576
  currentOriginX: number;
566
577
  currentOriginY: number;
@@ -803,14 +814,7 @@ declare module 'react-native-reanimated' {
803
814
  export function defineAnimation<T>(starting: any, factory: () => T): number;
804
815
  export function measure<T extends Component>(
805
816
  ref: RefObject<T>
806
- ): {
807
- width: number;
808
- height: number;
809
- x: number;
810
- y: number;
811
- pageX: number;
812
- pageY: number;
813
- };
817
+ ): MeasuredDimensions | null;
814
818
 
815
819
  export function getRelativeCoords(
816
820
  ref: RefObject<Component>,
@@ -0,0 +1,77 @@
1
+ def try_to_parse_react_native_package_json(node_modules_dir)
2
+ react_native_package_json_path = File.join(node_modules_dir, 'react-native/package.json')
3
+ if !File.exists?(react_native_package_json_path)
4
+ return nil
5
+ end
6
+ return JSON.parse(File.read(react_native_package_json_path))
7
+ end
8
+
9
+ def find_config()
10
+ result = {
11
+ :is_reanimated_example_app => nil,
12
+ :react_native_version => nil,
13
+ :react_native_minor_version => nil,
14
+ :is_tvos_target => nil,
15
+ :react_native_node_modules_dir => nil,
16
+ :reanimated_node_modules_dir => nil,
17
+ :react_native_common_dir => nil,
18
+ }
19
+
20
+ react_native_node_modules_dir = File.join(File.dirname(`cd #{Pod::Config.instance.installation_root.to_s} && node --print "require.resolve('react-native/package.json')"`), '..')
21
+ react_native_json = try_to_parse_react_native_package_json(react_native_node_modules_dir)
22
+
23
+ if react_native_json == nil
24
+ # user configuration, just in case
25
+ node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
26
+ react_native_json = try_to_parse_react_native_package_json(node_modules_dir)
27
+ end
28
+
29
+ if react_native_json == nil
30
+ raise '[RNReanimated] Unable to recognize your `react-native` version! Please set environmental variable with `react-native` locations: `export REACT_NATIVE_NODE_MODULES_DIR="<path to react-native>" && pod install'
31
+ end
32
+
33
+ result[:is_reanimated_example_app] = ENV["REANIMATED_EXAMPLE_APP_NAME"] != nil
34
+ result[:is_tvos_target] = react_native_json['name'] == 'react-native-tvos'
35
+ result[:react_native_version] = react_native_json['version']
36
+ result[:react_native_minor_version] = react_native_json['version'].split('.')[1].to_i
37
+ result[:react_native_node_modules_dir] = File.expand_path(react_native_node_modules_dir)
38
+ result[:reanimated_node_modules_dir] = File.expand_path(File.join(__dir__, '..', '..'))
39
+
40
+ pods_root = Pod::Config.instance.project_pods_root
41
+ react_native_common_dir_absolute = File.join(react_native_node_modules_dir, 'react-native', 'ReactCommon')
42
+ react_native_common_dir_relative = Pathname.new(react_native_common_dir_absolute).relative_path_from(pods_root).to_s
43
+ result[:react_native_common_dir] = react_native_common_dir_relative
44
+
45
+ return result
46
+ end
47
+
48
+ def assert_no_multiple_instances(react_native_info)
49
+ if react_native_info[:is_reanimated_example_app]
50
+ return
51
+ end
52
+
53
+ lib_instances_in_react_native_node_modules = %x[find #{react_native_info[:react_native_node_modules_dir]} -name "package.json" | grep "/react-native-reanimated/package.json"]
54
+ lib_instances_in_react_native_node_modules_array = lib_instances_in_react_native_node_modules.split("\n")
55
+ reanimated_instances = lib_instances_in_react_native_node_modules_array.length()
56
+ if react_native_info[:react_native_node_modules_dir] != react_native_info[:reanimated_node_modules_dir]
57
+ lib_instances_in_reanimated_node_modules = %x[find #{react_native_info[:reanimated_node_modules_dir]} -name "package.json" | grep "/react-native-reanimated/package.json"]
58
+ lib_instances_in_reanimated_node_modules_array = lib_instances_in_reanimated_node_modules.split("\n")
59
+ reanimated_instances += lib_instances_in_reanimated_node_modules_array.length()
60
+ end
61
+ if reanimated_instances > 1
62
+ parsed_location = ''
63
+ for location in lib_instances_in_react_native_node_modules_array + lib_instances_in_reanimated_node_modules_array
64
+ location['/package.json'] = ''
65
+ parsed_location += "- " + location + "\n"
66
+ end
67
+ raise "[react-native-reanimated] Multiple versions of Reanimated were detected. Only one instance of react-native-reanimated can be installed in a project. You need to resolve the conflict manually. Check out the documentation: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/troubleshooting#multiple-versions-of-reanimated-were-detected \n\nConflict between: \n" + parsed_location
68
+ end
69
+ end
70
+
71
+ def assert_no_reanimated2_with_new_architecture(reanimated_package_json)
72
+ reanimated_major_version = reanimated_package_json['version'].split('.')[0].to_i
73
+ fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
74
+ if fabric_enabled && reanimated_major_version == 2
75
+ raise "[react-native-reanimated] Reanimated 2.x does not support Fabric. Please upgrade to 3.x to use Reanimated with the New Architecture. For details, see https://blog.swmansion.com/announcing-reanimated-3-16167428c5f7"
76
+ end
77
+ end
@@ -534,12 +534,11 @@ export default function createAnimatedComponent(
534
534
  // TODO update config
535
535
  const tag = findNodeHandle(ref);
536
536
  if (
537
+ !shouldBeUseWeb() &&
537
538
  (this.props.layout || this.props.entering || this.props.exiting) &&
538
539
  tag != null
539
540
  ) {
540
- if (!shouldBeUseWeb()) {
541
- enableLayoutAnimations(true, false);
542
- }
541
+ enableLayoutAnimations(true, false);
543
542
  let layout = this.props.layout ? this.props.layout : DefaultLayout;
544
543
  let entering = this.props.entering
545
544
  ? this.props.entering
package/src/index.web.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // tree-shaken side effects
2
2
  import './reanimated2/js-reanimated/global';
3
3
 
4
+ // @ts-ignore backward compatibility with treeshaking
5
+ export * from './reanimated1';
4
6
  export * from './reanimated2';
5
7
  export * as default from './Animated'; // If this line fails, you probably forgot some installation steps. Check out the installation guide here: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/ 1) Make sure reanimated's babel plugin is installed in your babel.config.js (you should have 'react-native-reanimated/plugin' listed there - also see the above link for details) 2) Make sure you reset build cache after updating the config, run: yarn start --reset-cache