react-native-reanimated 3.0.0-rc.3 → 3.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +5 -1
  2. package/Common/cpp/SharedItems/ShareableValue.cpp +0 -2
  3. package/RNReanimated.podspec +19 -85
  4. package/android/CMakeLists.txt +22 -21
  5. package/android/build.gradle +344 -56
  6. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  7. package/android/src/main/cpp/AndroidErrorHandler.cpp +3 -4
  8. package/android/src/main/cpp/AndroidErrorHandler.h +1 -4
  9. package/android/src/main/java/com/swmansion/reanimated/{ReanimatedMessageQueueThread.java → ReanimatedMessageQueueThreadBase.java} +3 -8
  10. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +1 -1
  11. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/UIImplementation/64/com/swmansion/reanimated}/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  12. package/android/src/{main/java → reactNativeVersionPatch/UIImplementation/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +0 -0
  13. package/android/src/reactNativeVersionPatch/messageQueueThread/67/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  14. package/android/src/reactNativeVersionPatch/messageQueueThread/latest/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
  15. package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/nativeHierarchyManager/62/com/swmansion/reanimated}/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  16. package/android/src/{main/java → reactNativeVersionPatch/nativeHierarchyManager/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
  17. package/ios/REAModule.mm +21 -2
  18. package/ios/keyboardObserver/REAKeyboardEventObserver.m +1 -1
  19. package/ios/native/REAMessageThread.mm +1 -1
  20. package/lib/commonjs/createAnimatedComponent.js +2 -5
  21. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  22. package/lib/commonjs/reanimated2/NativeMethods.js +66 -26
  23. package/lib/commonjs/reanimated2/NativeMethods.js.map +1 -1
  24. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  25. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  26. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +5 -3
  27. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  28. package/lib/module/createAnimatedComponent.js +2 -5
  29. package/lib/module/createAnimatedComponent.js.map +1 -1
  30. package/lib/module/reanimated2/NativeMethods.js +67 -25
  31. package/lib/module/reanimated2/NativeMethods.js.map +1 -1
  32. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  33. package/lib/module/reanimated2/globals.d.js.map +1 -1
  34. package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -1
  35. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  36. package/package.json +7 -5
  37. package/plugin.js +1 -1
  38. package/scripts/reanimated_utils.rb +77 -0
  39. package/src/createAnimatedComponent.tsx +2 -3
  40. package/src/reanimated2/NativeMethods.ts +85 -33
  41. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +1 -1
  42. package/src/reanimated2/globals.d.ts +56 -14
  43. package/src/reanimated2/hook/useScrollViewOffset.ts +4 -3
  44. package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  45. package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +0 -68
  46. package/android/rnVersionPatch/65/.gitkeep +0 -0
  47. package/android/rnVersionPatch/66/.gitkeep +0 -0
  48. package/android/rnVersionPatch/67/.gitkeep +0 -0
  49. package/android/rnVersionPatch/68/.gitkeep +0 -0
  50. package/android/rnVersionPatch/backup/.gitkeep +0 -0
  51. package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +0 -8
@@ -3,7 +3,7 @@ import { Component } from 'react';
3
3
  import { findNodeHandle } from 'react-native';
4
4
  import { MeasuredDimensions } from './commonTypes';
5
5
  import { RefObjectFunction } from './hook/commonTypes';
6
- import { shouldBeUseWeb } from './PlatformChecker';
6
+ import { isChromeDebugger, isWeb, shouldBeUseWeb } from './PlatformChecker';
7
7
 
8
8
  export function getTag(
9
9
  view: null | number | React.Component<any, any> | React.ComponentClass<any>
@@ -13,39 +13,71 @@ export function getTag(
13
13
 
14
14
  const isNative = !shouldBeUseWeb();
15
15
 
16
- export function measure(
16
+ export let measure: (
17
17
  animatedRef: RefObjectFunction<Component>
18
- ): MeasuredDimensions | null {
19
- 'worklet';
20
- if (!_WORKLET || !isNative) {
21
- console.warn(
22
- '[Reanimated] measure() cannot be used for web or Chrome Debugger'
23
- );
24
- return null;
25
- }
18
+ ) => MeasuredDimensions | null;
26
19
 
27
- const viewTag = animatedRef();
28
- if (viewTag === -1) {
29
- console.warn(
30
- `[Reanimated] The view with tag ${viewTag} is not a valid argument for measure(). This may be because the view is not currently rendered, which may not be a bug (e.g. an off-screen FlatList item).`
31
- );
20
+ if (isWeb()) {
21
+ measure = (animatedRef: RefObjectFunction<Component>) => {
22
+ const element = animatedRef() as unknown as HTMLElement; // TODO: fix typing of animated refs on web
23
+ const viewportOffset = element.getBoundingClientRect();
24
+ return {
25
+ width: element.offsetWidth,
26
+ height: element.offsetHeight,
27
+ x: element.offsetLeft,
28
+ y: element.offsetTop,
29
+ pageX: viewportOffset.left,
30
+ pageY: viewportOffset.top,
31
+ };
32
+ };
33
+ } else if (isChromeDebugger()) {
34
+ measure = (_animatedRef: RefObjectFunction<Component>) => {
35
+ console.warn('[Reanimated] measure() cannot be used with Chrome Debugger.');
32
36
  return null;
33
- }
37
+ };
38
+ } else {
39
+ measure = (animatedRef: RefObjectFunction<Component>) => {
40
+ 'worklet';
41
+ if (!_WORKLET) {
42
+ console.warn(
43
+ '[Reanimated] measure() was called from the main JS context. Measure is ' +
44
+ 'only available in the UI runtime. This may also happen if measure() ' +
45
+ 'was called by a worklet in the useAnimatedStyle hook, because useAnimatedStyle ' +
46
+ 'calls the given worklet on the JS runtime during render. If you want to ' +
47
+ 'prevent this warning then wrap the call with `if (_WORKLET)`. Then it will ' +
48
+ 'only be called on the UI runtime after the render has been completed.'
49
+ );
50
+ return null;
51
+ }
34
52
 
35
- const measured = _measure(viewTag);
36
- if (measured.x === -1234567) {
37
- console.warn(
38
- `[Reanimated] The view with tag ${viewTag} returned an invalid measurement response`
39
- );
40
- return null;
41
- } else if (isNaN(measured.x)) {
42
- console.warn(
43
- `[Reanimated] The view with tag ${viewTag} gets view-flattened on Android. To disable view-flattening, set \`collapsable={false}\` on this component.`
44
- );
45
- return null;
46
- } else {
47
- return measured;
48
- }
53
+ const viewTag = animatedRef();
54
+ if (viewTag === -1) {
55
+ console.warn(
56
+ `[Reanimated] The view with tag ${viewTag} is not a valid argument for measure(). This may be because the view is not currently rendered, which may not be a bug (e.g. an off-screen FlatList item).`
57
+ );
58
+ return null;
59
+ }
60
+
61
+ const measured = _measure(viewTag);
62
+ if (measured === null) {
63
+ console.warn(
64
+ `[Reanimated] The view with tag ${viewTag} has some undefined, not-yet-computed or meaningless value of \`LayoutMetrics\` type. This may be because the view is not currently rendered, which may not be a bug (e.g. an off-screen FlatList item).`
65
+ );
66
+ return null;
67
+ } else if (measured.x === -1234567) {
68
+ console.warn(
69
+ `[Reanimated] The view with tag ${viewTag} returned an invalid measurement response.`
70
+ );
71
+ return null;
72
+ } else if (isNaN(measured.x)) {
73
+ console.warn(
74
+ `[Reanimated] The view with tag ${viewTag} gets view-flattened on Android. To disable view-flattening, set \`collapsable={false}\` on this component.`
75
+ );
76
+ return null;
77
+ } else {
78
+ return measured;
79
+ }
80
+ };
49
81
  }
50
82
 
51
83
  export function dispatchCommand(
@@ -68,7 +100,19 @@ export let scrollTo: (
68
100
  animated: boolean
69
101
  ) => void;
70
102
 
71
- if (global._IS_FABRIC) {
103
+ if (isWeb()) {
104
+ scrollTo = (
105
+ animatedRef: RefObjectFunction<Component>,
106
+ x: number,
107
+ y: number,
108
+ animated: boolean
109
+ ) => {
110
+ 'worklet';
111
+ const element = animatedRef() as unknown as HTMLElement;
112
+ // @ts-ignore same call as in react-native-web
113
+ element.scrollTo({ x, y, animated });
114
+ };
115
+ } else if (isNative && global._IS_FABRIC) {
72
116
  scrollTo = (
73
117
  animatedRef: RefObjectFunction<Component>,
74
118
  x: number,
@@ -78,7 +122,7 @@ if (global._IS_FABRIC) {
78
122
  'worklet';
79
123
  dispatchCommand(animatedRef, 'scrollTo', [x, y, animated]);
80
124
  };
81
- } else {
125
+ } else if (isNative) {
82
126
  scrollTo = (
83
127
  animatedRef: RefObjectFunction<Component>,
84
128
  x: number,
@@ -86,12 +130,20 @@ if (global._IS_FABRIC) {
86
130
  animated: boolean
87
131
  ) => {
88
132
  'worklet';
89
- if (!_WORKLET || !isNative) {
133
+ if (!_WORKLET) {
90
134
  return;
91
135
  }
92
136
  const viewTag = animatedRef();
93
137
  _scrollTo(viewTag, x, y, animated);
94
138
  };
139
+ } else {
140
+ scrollTo = (
141
+ _animatedRef: RefObjectFunction<Component>,
142
+ _x: number,
143
+ _y: number
144
+ ) => {
145
+ // no-op
146
+ };
95
147
  }
96
148
 
97
149
  export function setGestureState(handlerTag: number, newState: number): void {
@@ -11,7 +11,7 @@ export type FrameInfo = {
11
11
  timeSinceFirstFrame: number;
12
12
  };
13
13
 
14
- interface FrameCallbackRegistryUI {
14
+ export interface FrameCallbackRegistryUI {
15
15
  frameCallbackRegistry: Map<number, CallbackDetails>;
16
16
  activeFrameCallbacks: Set<number>;
17
17
  previousFrameTimestamp: number | null;
@@ -1,15 +1,21 @@
1
- import { AnimatedStyle, StyleProps } from './commonTypes';
2
- import { ReanimatedConsole } from './core';
3
- import { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';
4
- import { ShadowNodeWrapper } from './hook/commonTypes';
5
- import { MeasuredDimensions } from './NativeMethods';
6
- 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 { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';
8
+ import type { ShadowNodeWrapper } from './hook/commonTypes';
9
+ import type { NativeReanimated } from './NativeReanimated/NativeReanimated';
10
+
7
11
  declare global {
8
12
  const _WORKLET: boolean;
9
13
  const _IS_FABRIC: boolean;
10
- const _frameTimestamp: number;
14
+ const _frameTimestamp: number | null;
11
15
  const _eventTimestamp: number;
16
+ const __reanimatedModuleProxy: NativeReanimated;
12
17
  const _setGlobalConsole: (console?: ReanimatedConsole) => void;
18
+ const _log: (s: string) => void;
13
19
  const _getCurrentTime: () => number;
14
20
  const _stopObservingProgress: (tag: number, flag: boolean) => void;
15
21
  const _startObservingProgress: (
@@ -42,22 +48,58 @@ declare global {
42
48
  args: Array<unknown>
43
49
  ) => void;
44
50
  const _chronoNow: () => number;
51
+ const performance: { now: () => number };
52
+ const LayoutAnimationRepository: {
53
+ configs: Record<string, unknown>;
54
+ registerConfig(tag: number, config: Record<string, unknown>): void;
55
+ removeConfig(tag: number): void;
56
+ startAnimationForTag(tag: number, type: string, yogaValues: unknown): void;
57
+ };
45
58
  const ReanimatedDataMock: {
46
59
  now: () => number;
47
60
  };
48
61
  const _frameCallbackRegistry: FrameCallbackRegistryUI;
62
+
49
63
  namespace NodeJS {
50
64
  interface Global {
51
- _setGlobalConsole: (console?: ReanimatedConsole) => void;
52
- _log: (s: string) => void;
53
- _setGestureState: () => void;
54
65
  _WORKLET: boolean;
55
66
  _IS_FABRIC: boolean;
56
- __reanimatedModuleProxy: NativeReanimated;
57
67
  _frameTimestamp: number | null;
58
- _measure: () => MeasuredDimensions;
59
- _scrollTo: () => void;
60
- _dispatchCommand: () => void;
68
+ _eventTimestamp: number;
69
+ __reanimatedModuleProxy: NativeReanimated;
70
+ _setGlobalConsole: (console?: ReanimatedConsole) => void;
71
+ _log: (s: string) => void;
72
+ _getCurrentTime: () => number;
73
+ _stopObservingProgress: (tag: number, flag: boolean) => void;
74
+ _startObservingProgress: (
75
+ tag: number,
76
+ flag: { value: boolean; _value: boolean }
77
+ ) => void;
78
+ _setGestureState: (handlerTag: number, newState: number) => void;
79
+ _updatePropsPaper: (
80
+ tag: number,
81
+ name: string,
82
+ updates: StyleProps | AnimatedStyle
83
+ ) => void;
84
+ _updatePropsFabric: (
85
+ shadowNodeWrapper: ShadowNodeWrapper,
86
+ props: StyleProps | AnimatedStyle
87
+ ) => void;
88
+ _removeShadowNodeFromRegistry: (
89
+ shadowNodeWrapper: ShadowNodeWrapper
90
+ ) => void;
91
+ _measure: (viewTag: number) => MeasuredDimensions;
92
+ _scrollTo: (
93
+ viewTag: number,
94
+ x: number,
95
+ y: number,
96
+ animated: boolean
97
+ ) => void;
98
+ _dispatchCommand: (
99
+ shadowNodeWrapper: ShadowNodeWrapper,
100
+ commandName: string,
101
+ args: Array<unknown>
102
+ ) => void;
61
103
  _chronoNow: () => number;
62
104
  performance: { now: () => number };
63
105
  LayoutAnimationRepository: {
@@ -1,10 +1,11 @@
1
1
  import { RefObject, useEffect, useRef } from 'react';
2
2
 
3
- import { findNodeHandle } from 'react-native';
4
3
  import type Animated from 'react-native-reanimated';
5
- import { useEvent, useSharedValue } from '.';
6
- import { SharedValue } from '../commonTypes';
7
4
  import { ScrollEvent } from './useAnimatedScrollHandler';
5
+ import { SharedValue } from '../commonTypes';
6
+ import { findNodeHandle } from 'react-native';
7
+ import { useEvent } from './utils';
8
+ import { useSharedValue } from './useSharedValue';
8
9
 
9
10
  const subscribeForEvents = [
10
11
  'onScroll',
@@ -1,68 +0,0 @@
1
- package com.facebook.react.uimanager;
2
-
3
- import androidx.annotation.Nullable;
4
- import com.facebook.react.bridge.ReactApplicationContext;
5
- import com.facebook.react.bridge.ReadableArray;
6
- import com.facebook.react.uimanager.events.EventDispatcher;
7
- import com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager;
8
- import java.util.List;
9
-
10
- public class ReanimatedUIImplementation extends UIImplementation {
11
- public ReanimatedUIImplementation(
12
- ReactApplicationContext reactContext,
13
- UIManagerModule.ViewManagerResolver viewManagerResolver,
14
- EventDispatcher eventDispatcher,
15
- int minTimeLeftInFrameForNonBatchedOperationMs) {
16
- this(
17
- reactContext,
18
- new ViewManagerRegistry(viewManagerResolver),
19
- eventDispatcher,
20
- minTimeLeftInFrameForNonBatchedOperationMs);
21
- }
22
-
23
- public ReanimatedUIImplementation(
24
- ReactApplicationContext reactContext,
25
- List<ViewManager> viewManagerList,
26
- EventDispatcher eventDispatcher,
27
- int minTimeLeftInFrameForNonBatchedOperationMs) {
28
- this(
29
- reactContext,
30
- new ViewManagerRegistry(viewManagerList),
31
- eventDispatcher,
32
- minTimeLeftInFrameForNonBatchedOperationMs);
33
- }
34
-
35
- public ReanimatedUIImplementation(
36
- ReactApplicationContext reactContext,
37
- ViewManagerRegistry viewManagerRegistry,
38
- EventDispatcher eventDispatcher,
39
- int minTimeLeftInFrameForNonBatchedOperationMs) {
40
- super(
41
- reactContext,
42
- viewManagerRegistry,
43
- new UIViewOperationQueue(
44
- reactContext,
45
- new ReanimatedNativeHierarchyManager(viewManagerRegistry, reactContext),
46
- minTimeLeftInFrameForNonBatchedOperationMs),
47
- eventDispatcher);
48
- }
49
-
50
- /**
51
- * Invoked when there is a mutation in a node tree.
52
- *
53
- * @param tag react tag of the node we want to manage
54
- * @param indicesToRemove ordered (asc) list of indicies at which view should be removed
55
- * @param viewsToAdd ordered (asc based on mIndex property) list of tag-index pairs that represent
56
- * a view which should be added at the specified index
57
- * @param tagsToDelete list of tags corresponding to views that should be removed
58
- */
59
- public void manageChildren(
60
- int viewTag,
61
- @Nullable ReadableArray moveFrom,
62
- @Nullable ReadableArray moveTo,
63
- @Nullable ReadableArray addChildTags,
64
- @Nullable ReadableArray addAtIndices,
65
- @Nullable ReadableArray removeFrom) {
66
- super.manageChildren(viewTag, moveFrom, moveTo, addChildTags, addAtIndices, removeFrom);
67
- }
68
- }
@@ -1,68 +0,0 @@
1
- package com.facebook.react.uimanager;
2
-
3
- import androidx.annotation.Nullable;
4
- import com.facebook.react.bridge.ReactApplicationContext;
5
- import com.facebook.react.bridge.ReadableArray;
6
- import com.facebook.react.uimanager.events.EventDispatcher;
7
- import com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager;
8
- import java.util.List;
9
-
10
- public class ReanimatedUIImplementation extends UIImplementation {
11
- public ReanimatedUIImplementation(
12
- ReactApplicationContext reactContext,
13
- UIManagerModule.ViewManagerResolver viewManagerResolver,
14
- EventDispatcher eventDispatcher,
15
- int minTimeLeftInFrameForNonBatchedOperationMs) {
16
- this(
17
- reactContext,
18
- new ViewManagerRegistry(viewManagerResolver),
19
- eventDispatcher,
20
- minTimeLeftInFrameForNonBatchedOperationMs);
21
- }
22
-
23
- public ReanimatedUIImplementation(
24
- ReactApplicationContext reactContext,
25
- List<ViewManager> viewManagerList,
26
- EventDispatcher eventDispatcher,
27
- int minTimeLeftInFrameForNonBatchedOperationMs) {
28
- this(
29
- reactContext,
30
- new ViewManagerRegistry(viewManagerList),
31
- eventDispatcher,
32
- minTimeLeftInFrameForNonBatchedOperationMs);
33
- }
34
-
35
- public ReanimatedUIImplementation(
36
- ReactApplicationContext reactContext,
37
- ViewManagerRegistry viewManagerRegistry,
38
- EventDispatcher eventDispatcher,
39
- int minTimeLeftInFrameForNonBatchedOperationMs) {
40
- super(
41
- reactContext,
42
- viewManagerRegistry,
43
- new UIViewOperationQueue(
44
- reactContext,
45
- new ReanimatedNativeHierarchyManager(viewManagerRegistry, reactContext),
46
- minTimeLeftInFrameForNonBatchedOperationMs),
47
- eventDispatcher);
48
- }
49
-
50
- /**
51
- * Invoked when there is a mutation in a node tree.
52
- *
53
- * @param tag react tag of the node we want to manage
54
- * @param indicesToRemove ordered (asc) list of indicies at which view should be removed
55
- * @param viewsToAdd ordered (asc based on mIndex property) list of tag-index pairs that represent
56
- * a view which should be added at the specified index
57
- * @param tagsToDelete list of tags corresponding to views that should be removed
58
- */
59
- public void manageChildren(
60
- int viewTag,
61
- @Nullable ReadableArray moveFrom,
62
- @Nullable ReadableArray moveTo,
63
- @Nullable ReadableArray addChildTags,
64
- @Nullable ReadableArray addAtIndices,
65
- @Nullable ReadableArray removeFrom) {
66
- super.manageChildren(viewTag, moveFrom, moveTo, addChildTags, addAtIndices, removeFrom);
67
- }
68
- }
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,8 +0,0 @@
1
- package com.swmansion.reanimated;
2
-
3
- public class AndroidErrorHandler {
4
-
5
- public static void raise(String message) {
6
- throw new RuntimeException(message);
7
- }
8
- }