react-native-reanimated 3.0.0-rc.2 → 3.0.0-rc.3
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.
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +3 -0
- package/Common/cpp/{headers/AnimatedSensor → AnimatedSensor}/AnimatedSensorModule.h +0 -0
- package/Common/cpp/Fabric/FabricUtils.cpp +1 -1
- package/Common/cpp/{headers/Fabric → Fabric}/FabricUtils.h +0 -0
- package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +2 -0
- package/Common/cpp/{headers/Fabric → Fabric}/ReanimatedUIManagerBinding.h +0 -0
- package/Common/cpp/{headers/Fabric → Fabric}/ShadowTreeCloner.h +1 -1
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +2 -0
- package/Common/cpp/{headers/LayoutAnimations → LayoutAnimations}/LayoutAnimationsProxy.h +0 -0
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +1 -0
- package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModule.h +5 -0
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +2 -0
- package/Common/cpp/{headers/NativeModules → NativeModules}/NativeReanimatedModuleSpec.h +1 -1
- package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +93 -0
- package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +125 -0
- package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +50 -0
- package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.h +27 -0
- package/Common/cpp/ReanimatedRuntime/RuntimeInitialization.md +194 -0
- package/Common/cpp/{headers/Registries → Registries}/EventHandlerRegistry.h +0 -0
- package/Common/cpp/Registries/MapperRegistry.cpp +3 -1
- package/Common/cpp/{headers/Registries → Registries}/MapperRegistry.h +0 -0
- package/Common/cpp/{headers/Registries → Registries}/NewestShadowNodesRegistry.h +0 -0
- package/Common/cpp/Registries/WorkletsCache.cpp +8 -1
- package/Common/cpp/{headers/Registries → Registries}/WorkletsCache.h +0 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/FrozenObject.h +0 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/HostFunctionHandler.h +0 -0
- package/Common/cpp/SharedItems/MutableValue.cpp +2 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValue.h +0 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/MutableValueSetterProxy.h +0 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/RemoteObject.h +0 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/RuntimeManager.h +0 -0
- package/Common/cpp/SharedItems/ShareableValue.cpp +6 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/ShareableValue.h +0 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/SharedParent.h +0 -0
- package/Common/cpp/{headers/SharedItems → SharedItems}/ValueWrapper.h +0 -0
- package/Common/cpp/{headers/SpecTools → SpecTools}/ErrorHandler.h +0 -0
- package/Common/cpp/{headers/Tools → Tools}/FeaturesConfig.h +0 -0
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +2 -2
- package/Common/cpp/{headers/Tools → Tools}/JSIStoreValueUser.h +0 -0
- package/Common/cpp/{headers/Tools → Tools}/Mapper.h +0 -0
- package/Common/cpp/{headers/Tools → Tools}/PlatformDepMethodsHolder.h +0 -0
- package/Common/cpp/{headers/Tools → Tools}/ReanimatedHiddenHeaders.h +1 -1
- package/Common/cpp/{headers/Tools → Tools}/RuntimeDecorator.h +0 -0
- package/Common/cpp/{headers/Tools → Tools}/Scheduler.h +0 -0
- package/Common/cpp/Tools/SingleInstanceChecker.h +58 -0
- package/Common/cpp/{headers/Tools → Tools}/WorkletEventHandler.h +0 -0
- package/RNReanimated.podspec +25 -23
- package/android/CMakeLists.txt +41 -38
- package/android/build.gradle +91 -72
- package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +10 -8
- package/android/src/main/cpp/{headers/AndroidErrorHandler.h → AndroidErrorHandler.h} +0 -0
- package/android/src/main/cpp/AndroidLogger.cpp +4 -1
- package/android/src/main/cpp/{headers/AndroidLogger.h → AndroidLogger.h} +0 -0
- package/android/src/main/cpp/{headers/AndroidScheduler.h → AndroidScheduler.h} +0 -0
- package/android/src/main/cpp/{headers/JNIHelper.h → JNIHelper.h} +0 -0
- package/android/src/main/cpp/{headers/LayoutAnimations.h → LayoutAnimations.h} +0 -0
- package/android/src/main/cpp/NativeProxy.cpp +12 -28
- package/android/src/main/cpp/{headers/NativeProxy.h → NativeProxy.h} +3 -1
- package/android/src/main/cpp/{headers/TurboModule.h → TurboModule.h} +0 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +77 -0
- package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +2 -1
- package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +7 -7
- package/ios/REAModule.mm +10 -0
- package/ios/native/NativeProxy.mm +12 -19
- package/ios/native/REAInitializer.h +2 -2
- package/ios/native/REAInitializer.mm +2 -2
- package/ios/native/REAMessageThread.h +22 -0
- package/ios/native/REAMessageThread.mm +38 -0
- package/ios/native/UIResponder+Reanimated.mm +1 -1
- package/lib/commonjs/reanimated2/NativeMethods.js +20 -24
- package/lib/commonjs/reanimated2/NativeMethods.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/delay.js +0 -12
- package/lib/commonjs/reanimated2/animation/delay.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/repeat.js +0 -24
- package/lib/commonjs/reanimated2/animation/repeat.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/sequence.js +0 -12
- package/lib/commonjs/reanimated2/animation/sequence.js.map +1 -1
- package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +51 -19
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/index.js +8 -0
- package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useFrameCallback.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +31 -0
- package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -0
- package/lib/commonjs/reanimated2/utils.js +12 -3
- package/lib/commonjs/reanimated2/utils.js.map +1 -1
- package/lib/module/reanimated2/NativeMethods.js +20 -24
- package/lib/module/reanimated2/NativeMethods.js.map +1 -1
- package/lib/module/reanimated2/animation/delay.js +0 -10
- package/lib/module/reanimated2/animation/delay.js.map +1 -1
- package/lib/module/reanimated2/animation/repeat.js +0 -20
- package/lib/module/reanimated2/animation/repeat.js.map +1 -1
- package/lib/module/reanimated2/animation/sequence.js +0 -10
- package/lib/module/reanimated2/animation/sequence.js.map +1 -1
- package/lib/module/reanimated2/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryJS.js.map +1 -1
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +51 -19
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
- package/lib/module/reanimated2/hook/index.js +1 -0
- package/lib/module/reanimated2/hook/index.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedScrollHandler.js.map +1 -1
- package/lib/module/reanimated2/hook/useFrameCallback.js.map +1 -1
- package/lib/module/reanimated2/hook/useScrollViewOffset.js +20 -0
- package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -0
- package/lib/module/reanimated2/utils.js +13 -3
- package/lib/module/reanimated2/utils.js.map +1 -1
- package/package.json +6 -4
- package/plugin.js +105 -47
- package/react-native-reanimated.d.ts +13 -9
- package/src/reanimated2/NativeMethods.ts +28 -33
- package/src/reanimated2/animation/delay.ts +0 -12
- package/src/reanimated2/animation/repeat.ts +0 -25
- package/src/reanimated2/animation/sequence.ts +0 -13
- package/src/reanimated2/commonTypes.ts +9 -0
- package/src/reanimated2/frameCallback/FrameCallbackRegistryJS.ts +6 -9
- package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +78 -27
- package/src/reanimated2/hook/index.ts +1 -0
- package/src/reanimated2/hook/useAnimatedScrollHandler.ts +3 -1
- package/src/reanimated2/hook/useFrameCallback.ts +2 -1
- package/src/reanimated2/hook/useScrollViewOffset.ts +36 -0
- package/src/reanimated2/utils.ts +12 -5
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +0 -29
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* global _WORKLET _measure _scrollTo _dispatchCommand _setGestureState */
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
-
// @ts-nocheck
|
|
4
2
|
import { Component } from 'react';
|
|
5
3
|
import { findNodeHandle } from 'react-native';
|
|
6
|
-
import {
|
|
4
|
+
import { MeasuredDimensions } from './commonTypes';
|
|
5
|
+
import { RefObjectFunction } from './hook/commonTypes';
|
|
7
6
|
import { shouldBeUseWeb } from './PlatformChecker';
|
|
8
7
|
|
|
9
8
|
export function getTag(
|
|
@@ -12,45 +11,41 @@ export function getTag(
|
|
|
12
11
|
return findNodeHandle(view);
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
x: number;
|
|
17
|
-
y: number;
|
|
18
|
-
width: number;
|
|
19
|
-
height: number;
|
|
20
|
-
pageX: number;
|
|
21
|
-
pageY: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const isNativeIndefined = shouldBeUseWeb();
|
|
14
|
+
const isNative = !shouldBeUseWeb();
|
|
25
15
|
|
|
26
16
|
export function measure(
|
|
27
17
|
animatedRef: RefObjectFunction<Component>
|
|
28
|
-
): MeasuredDimensions {
|
|
18
|
+
): MeasuredDimensions | null {
|
|
29
19
|
'worklet';
|
|
30
|
-
if (!_WORKLET ||
|
|
20
|
+
if (!_WORKLET || !isNative) {
|
|
31
21
|
console.warn(
|
|
32
|
-
'[
|
|
22
|
+
'[Reanimated] measure() cannot be used for web or Chrome Debugger'
|
|
33
23
|
);
|
|
34
|
-
return
|
|
35
|
-
x: NaN,
|
|
36
|
-
y: NaN,
|
|
37
|
-
width: NaN,
|
|
38
|
-
height: NaN,
|
|
39
|
-
pageX: NaN,
|
|
40
|
-
pageY: NaN,
|
|
41
|
-
};
|
|
24
|
+
return null;
|
|
42
25
|
}
|
|
26
|
+
|
|
43
27
|
const viewTag = animatedRef();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
);
|
|
32
|
+
return null;
|
|
47
33
|
}
|
|
48
|
-
|
|
34
|
+
|
|
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)) {
|
|
49
42
|
console.warn(
|
|
50
|
-
|
|
43
|
+
`[Reanimated] The view with tag ${viewTag} gets view-flattened on Android. To disable view-flattening, set \`collapsable={false}\` on this component.`
|
|
51
44
|
);
|
|
45
|
+
return null;
|
|
46
|
+
} else {
|
|
47
|
+
return measured;
|
|
52
48
|
}
|
|
53
|
-
return result;
|
|
54
49
|
}
|
|
55
50
|
|
|
56
51
|
export function dispatchCommand(
|
|
@@ -59,7 +54,7 @@ export function dispatchCommand(
|
|
|
59
54
|
args: Array<unknown>
|
|
60
55
|
): void {
|
|
61
56
|
'worklet';
|
|
62
|
-
if (!_WORKLET ||
|
|
57
|
+
if (!_WORKLET || !isNative) {
|
|
63
58
|
return;
|
|
64
59
|
}
|
|
65
60
|
const shadowNodeWrapper = animatedRef();
|
|
@@ -91,7 +86,7 @@ if (global._IS_FABRIC) {
|
|
|
91
86
|
animated: boolean
|
|
92
87
|
) => {
|
|
93
88
|
'worklet';
|
|
94
|
-
if (!_WORKLET ||
|
|
89
|
+
if (!_WORKLET || !isNative) {
|
|
95
90
|
return;
|
|
96
91
|
}
|
|
97
92
|
const viewTag = animatedRef();
|
|
@@ -101,7 +96,7 @@ if (global._IS_FABRIC) {
|
|
|
101
96
|
|
|
102
97
|
export function setGestureState(handlerTag: number, newState: number): void {
|
|
103
98
|
'worklet';
|
|
104
|
-
if (!_WORKLET ||
|
|
99
|
+
if (!_WORKLET || !isNative) {
|
|
105
100
|
console.warn(
|
|
106
101
|
'[Reanimated] You can not use setGestureState in non-worklet function.'
|
|
107
102
|
);
|
|
@@ -75,15 +75,3 @@ export function withDelay(
|
|
|
75
75
|
};
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @deprecated Kept for backward compatibility. Will be removed soon.
|
|
81
|
-
*/
|
|
82
|
-
export function delay(
|
|
83
|
-
delayMs: number,
|
|
84
|
-
_nextAnimation: NextAnimation<DelayAnimation>
|
|
85
|
-
): Animation<DelayAnimation> {
|
|
86
|
-
'worklet';
|
|
87
|
-
console.warn('Method `delay` is deprecated. Please use `withDelay` instead');
|
|
88
|
-
return withDelay(delayMs, _nextAnimation);
|
|
89
|
-
}
|
|
@@ -91,28 +91,3 @@ export function withRepeat(
|
|
|
91
91
|
} as RepeatAnimation;
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @deprecated Kept for backward compatibility. Will be removed soon.
|
|
97
|
-
*/
|
|
98
|
-
export function repeat(
|
|
99
|
-
_nextAnimation: NextAnimation<RepeatAnimation>,
|
|
100
|
-
numberOfReps = 2,
|
|
101
|
-
reverse = false,
|
|
102
|
-
callback?: AnimationCallback
|
|
103
|
-
): Animation<RepeatAnimation> {
|
|
104
|
-
'worklet';
|
|
105
|
-
console.warn(
|
|
106
|
-
'Method `repeat` is deprecated. Please use `withRepeat` instead'
|
|
107
|
-
);
|
|
108
|
-
return withRepeat(_nextAnimation, numberOfReps, reverse, callback);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function loop(
|
|
112
|
-
nextAnimation: NextAnimation<RepeatAnimation>,
|
|
113
|
-
numberOfLoops = 1
|
|
114
|
-
): Animation<RepeatAnimation> {
|
|
115
|
-
'worklet';
|
|
116
|
-
console.warn('Method `loop` is deprecated. Please use `withRepeat` instead');
|
|
117
|
-
return repeat(nextAnimation, Math.round(numberOfLoops * 2), true);
|
|
118
|
-
}
|
|
@@ -83,16 +83,3 @@ export function withSequence(
|
|
|
83
83
|
}
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @deprecated Kept for backward compatibility. Will be removed soon.
|
|
89
|
-
*/
|
|
90
|
-
export function sequence(
|
|
91
|
-
..._animations: NextAnimation<SequenceAnimation>[]
|
|
92
|
-
): Animation<SequenceAnimation> {
|
|
93
|
-
'worklet';
|
|
94
|
-
console.warn(
|
|
95
|
-
'Method `sequence` is deprecated. Please use `withSequence` instead'
|
|
96
|
-
);
|
|
97
|
-
return withSequence(..._animations);
|
|
98
|
-
}
|
|
@@ -161,3 +161,12 @@ export type AnimatedKeyboardInfo = {
|
|
|
161
161
|
height: SharedValue<number>;
|
|
162
162
|
state: SharedValue<KeyboardState>;
|
|
163
163
|
};
|
|
164
|
+
|
|
165
|
+
export interface MeasuredDimensions {
|
|
166
|
+
x: number;
|
|
167
|
+
y: number;
|
|
168
|
+
width: number;
|
|
169
|
+
height: number;
|
|
170
|
+
pageX: number;
|
|
171
|
+
pageY: number;
|
|
172
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { runOnUI } from '../core';
|
|
2
|
-
import { prepareUIRegistry } from './FrameCallbackRegistryUI';
|
|
2
|
+
import { FrameInfo, prepareUIRegistry } from './FrameCallbackRegistryUI';
|
|
3
3
|
|
|
4
4
|
export default class FrameCallbackRegistryJS {
|
|
5
5
|
private nextCallbackId = 0;
|
|
@@ -8,7 +8,7 @@ export default class FrameCallbackRegistryJS {
|
|
|
8
8
|
prepareUIRegistry();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
registerFrameCallback(callback: () => void): number {
|
|
11
|
+
registerFrameCallback(callback: (frameInfo: FrameInfo) => void): number {
|
|
12
12
|
if (!callback) {
|
|
13
13
|
return -1;
|
|
14
14
|
}
|
|
@@ -24,20 +24,17 @@ export default class FrameCallbackRegistryJS {
|
|
|
24
24
|
return callbackId;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
unregisterFrameCallback(
|
|
27
|
+
unregisterFrameCallback(callbackId: number): void {
|
|
28
28
|
runOnUI(() => {
|
|
29
29
|
'worklet';
|
|
30
|
-
global._frameCallbackRegistry.unregisterFrameCallback(
|
|
30
|
+
global._frameCallbackRegistry.unregisterFrameCallback(callbackId);
|
|
31
31
|
})();
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
manageStateFrameCallback(
|
|
34
|
+
manageStateFrameCallback(callbackId: number, state: boolean): void {
|
|
35
35
|
runOnUI(() => {
|
|
36
36
|
'worklet';
|
|
37
|
-
global._frameCallbackRegistry.manageStateFrameCallback(
|
|
38
|
-
frameCallbackId,
|
|
39
|
-
state
|
|
40
|
-
);
|
|
37
|
+
global._frameCallbackRegistry.manageStateFrameCallback(callbackId, state);
|
|
41
38
|
})();
|
|
42
39
|
}
|
|
43
40
|
}
|
|
@@ -1,61 +1,112 @@
|
|
|
1
1
|
import { runOnUI } from '../core';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
type CallbackDetails = {
|
|
4
|
+
callback: (frameInfo: FrameInfo) => void;
|
|
5
|
+
startTime: number | null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type FrameInfo = {
|
|
9
|
+
timestamp: number;
|
|
10
|
+
timeSincePreviousFrame: number | null;
|
|
11
|
+
timeSinceFirstFrame: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface FrameCallbackRegistryUI {
|
|
15
|
+
frameCallbackRegistry: Map<number, CallbackDetails>;
|
|
16
|
+
activeFrameCallbacks: Set<number>;
|
|
17
|
+
previousFrameTimestamp: number | null;
|
|
7
18
|
runCallbacks: () => void;
|
|
8
|
-
registerFrameCallback: (
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
registerFrameCallback: (
|
|
20
|
+
callback: (frameInfo: FrameInfo) => void,
|
|
21
|
+
callbackId: number
|
|
22
|
+
) => void;
|
|
23
|
+
unregisterFrameCallback: (callbackId: number) => void;
|
|
24
|
+
manageStateFrameCallback: (callbackId: number, state: boolean) => void;
|
|
11
25
|
}
|
|
12
26
|
|
|
13
27
|
export const prepareUIRegistry = runOnUI(() => {
|
|
14
28
|
'worklet';
|
|
15
29
|
|
|
16
30
|
const frameCallbackRegistry: FrameCallbackRegistryUI = {
|
|
17
|
-
frameCallbackRegistry: new Map<number,
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
frameCallbackRegistry: new Map<number, CallbackDetails>(),
|
|
32
|
+
activeFrameCallbacks: new Set<number>(),
|
|
33
|
+
previousFrameTimestamp: null,
|
|
20
34
|
|
|
21
35
|
runCallbacks() {
|
|
22
|
-
const loop = () => {
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
const loop = (timestamp: number) => {
|
|
37
|
+
if (this.previousFrameTimestamp === null) {
|
|
38
|
+
this.previousFrameTimestamp = timestamp;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const delta = timestamp - this.previousFrameTimestamp;
|
|
42
|
+
|
|
43
|
+
this.activeFrameCallbacks.forEach((callbackId: number) => {
|
|
44
|
+
const callbackDetails = this.frameCallbackRegistry.get(callbackId)!;
|
|
45
|
+
|
|
46
|
+
const { startTime } = callbackDetails;
|
|
47
|
+
|
|
48
|
+
if (startTime === null) {
|
|
49
|
+
// First frame
|
|
50
|
+
callbackDetails.startTime = timestamp;
|
|
51
|
+
|
|
52
|
+
callbackDetails.callback({
|
|
53
|
+
timestamp,
|
|
54
|
+
timeSincePreviousFrame: null,
|
|
55
|
+
timeSinceFirstFrame: 0,
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
// Next frame
|
|
59
|
+
callbackDetails.callback({
|
|
60
|
+
timestamp,
|
|
61
|
+
timeSincePreviousFrame: delta,
|
|
62
|
+
timeSinceFirstFrame: timestamp - startTime,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
26
65
|
});
|
|
27
66
|
|
|
28
|
-
if (this.
|
|
67
|
+
if (this.activeFrameCallbacks.size > 0) {
|
|
68
|
+
this.previousFrameTimestamp = timestamp;
|
|
29
69
|
requestAnimationFrame(loop);
|
|
30
70
|
} else {
|
|
31
|
-
this.
|
|
71
|
+
this.previousFrameTimestamp = null;
|
|
32
72
|
}
|
|
33
73
|
};
|
|
34
74
|
|
|
35
|
-
|
|
75
|
+
// runCallback() should only be called after registering a callback,
|
|
76
|
+
// so if there is only one active callback, then it means that there were
|
|
77
|
+
// zero previously and the loop isn't running yet.
|
|
78
|
+
if (this.activeFrameCallbacks.size === 1) {
|
|
36
79
|
requestAnimationFrame(loop);
|
|
37
|
-
this.isFrameCallbackRunning = true;
|
|
38
80
|
}
|
|
39
81
|
},
|
|
40
82
|
|
|
41
|
-
registerFrameCallback(
|
|
42
|
-
|
|
83
|
+
registerFrameCallback(
|
|
84
|
+
callback: (frameInfo: FrameInfo) => void,
|
|
85
|
+
callbackId: number
|
|
86
|
+
) {
|
|
87
|
+
this.frameCallbackRegistry.set(callbackId, {
|
|
88
|
+
callback: callback,
|
|
89
|
+
startTime: null,
|
|
90
|
+
});
|
|
43
91
|
},
|
|
44
92
|
|
|
45
|
-
unregisterFrameCallback(
|
|
46
|
-
this.manageStateFrameCallback(
|
|
47
|
-
this.frameCallbackRegistry.delete(
|
|
93
|
+
unregisterFrameCallback(callbackId: number) {
|
|
94
|
+
this.manageStateFrameCallback(callbackId, false);
|
|
95
|
+
this.frameCallbackRegistry.delete(callbackId);
|
|
48
96
|
},
|
|
49
97
|
|
|
50
|
-
manageStateFrameCallback(
|
|
51
|
-
if (
|
|
98
|
+
manageStateFrameCallback(callbackId: number, state: boolean) {
|
|
99
|
+
if (callbackId === -1) {
|
|
52
100
|
return;
|
|
53
101
|
}
|
|
54
102
|
if (state) {
|
|
55
|
-
this.
|
|
103
|
+
this.activeFrameCallbacks.add(callbackId);
|
|
56
104
|
this.runCallbacks();
|
|
57
105
|
} else {
|
|
58
|
-
this.
|
|
106
|
+
const callback = this.frameCallbackRegistry.get(callbackId)!;
|
|
107
|
+
callback.startTime = null;
|
|
108
|
+
|
|
109
|
+
this.activeFrameCallbacks.delete(callbackId);
|
|
59
110
|
}
|
|
60
111
|
},
|
|
61
112
|
};
|
|
@@ -24,3 +24,4 @@ export { useAnimatedSensor, SensorType } from './useAnimatedSensor';
|
|
|
24
24
|
export { useFrameCallback } from './useFrameCallback';
|
|
25
25
|
export type { FrameCallback } from './useFrameCallback';
|
|
26
26
|
export { useAnimatedKeyboard } from './useAnimatedKeyboard';
|
|
27
|
+
export { useScrollViewOffset } from './useScrollViewOffset';
|
|
@@ -10,7 +10,9 @@ export interface ScrollHandler<TContext extends Context>
|
|
|
10
10
|
(event: NativeScrollEvent, context?: TContext): void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
interface ScrollEvent
|
|
13
|
+
export interface ScrollEvent
|
|
14
|
+
extends NativeScrollEvent,
|
|
15
|
+
NativeEvent<ScrollEvent> {
|
|
14
16
|
eventName: string;
|
|
15
17
|
}
|
|
16
18
|
export interface ScrollHandlers<TContext extends Context> {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import FrameCallbackRegistryJS from '../frameCallback/FrameCallbackRegistryJS';
|
|
3
|
+
import { FrameInfo } from '../frameCallback/FrameCallbackRegistryUI';
|
|
3
4
|
|
|
4
5
|
export type FrameCallback = {
|
|
5
6
|
setActive: (isActive: boolean) => void;
|
|
@@ -9,7 +10,7 @@ export type FrameCallback = {
|
|
|
9
10
|
const frameCallbackRegistry = new FrameCallbackRegistryJS();
|
|
10
11
|
|
|
11
12
|
export function useFrameCallback(
|
|
12
|
-
callback: () => void,
|
|
13
|
+
callback: (frameInfo: FrameInfo) => void,
|
|
13
14
|
autostart = true
|
|
14
15
|
): FrameCallback {
|
|
15
16
|
const ref = useRef<FrameCallback>({
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { RefObject, useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { findNodeHandle } from 'react-native';
|
|
4
|
+
import type Animated from 'react-native-reanimated';
|
|
5
|
+
import { useEvent, useSharedValue } from '.';
|
|
6
|
+
import { SharedValue } from '../commonTypes';
|
|
7
|
+
import { ScrollEvent } from './useAnimatedScrollHandler';
|
|
8
|
+
|
|
9
|
+
const subscribeForEvents = [
|
|
10
|
+
'onScroll',
|
|
11
|
+
'onScrollBeginDrag',
|
|
12
|
+
'onScrollEndDrag',
|
|
13
|
+
'onMomentumScrollBegin',
|
|
14
|
+
'onMomentumScrollEnd',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export function useScrollViewOffset(
|
|
18
|
+
aref: RefObject<Animated.ScrollView>
|
|
19
|
+
): SharedValue<number> {
|
|
20
|
+
const offsetRef = useRef(useSharedValue(0));
|
|
21
|
+
|
|
22
|
+
const event = useEvent<ScrollEvent>((event: ScrollEvent) => {
|
|
23
|
+
'worklet';
|
|
24
|
+
offsetRef.current.value =
|
|
25
|
+
event.contentOffset.x === 0
|
|
26
|
+
? event.contentOffset.y
|
|
27
|
+
: event.contentOffset.x;
|
|
28
|
+
}, subscribeForEvents);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const viewTag = findNodeHandle(aref.current);
|
|
32
|
+
event.current?.registerForEvents(viewTag as number);
|
|
33
|
+
}, [aref.current]);
|
|
34
|
+
|
|
35
|
+
return offsetRef.current;
|
|
36
|
+
}
|
package/src/reanimated2/utils.ts
CHANGED
|
@@ -7,15 +7,22 @@ export interface ComponentCoords {
|
|
|
7
7
|
y: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Given an absolute position and a component ref, returns the relative
|
|
12
|
+
* position in the component's local coordinate space.
|
|
13
|
+
*/
|
|
10
14
|
export function getRelativeCoords(
|
|
11
15
|
parentRef: RefObjectFunction<Component>,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
): ComponentCoords {
|
|
16
|
+
absoluteX: number,
|
|
17
|
+
absoluteY: number
|
|
18
|
+
): ComponentCoords | null {
|
|
15
19
|
'worklet';
|
|
16
20
|
const parentCoords = measure(parentRef);
|
|
21
|
+
if (parentCoords === null) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
17
24
|
return {
|
|
18
|
-
x:
|
|
19
|
-
y:
|
|
25
|
+
x: absoluteX - parentCoords.x,
|
|
26
|
+
y: absoluteY - parentCoords.y,
|
|
20
27
|
};
|
|
21
28
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
package com.swmansion.reanimated;
|
|
2
|
-
|
|
3
|
-
import android.util.Log;
|
|
4
|
-
import com.facebook.react.bridge.JSIModulePackage;
|
|
5
|
-
import com.facebook.react.bridge.JSIModuleSpec;
|
|
6
|
-
import com.facebook.react.bridge.JavaScriptContextHolder;
|
|
7
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
-
import java.util.Arrays;
|
|
9
|
-
import java.util.List;
|
|
10
|
-
|
|
11
|
-
public class ReanimatedJSIModulePackage implements JSIModulePackage {
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Since 2.5.0, Reanimated autoinstalls on Android - you can remove
|
|
14
|
-
* getJSIModulePackage() override in MainApplication.java.
|
|
15
|
-
*/
|
|
16
|
-
@Deprecated
|
|
17
|
-
public ReanimatedJSIModulePackage() {
|
|
18
|
-
super();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Override
|
|
22
|
-
public List<JSIModuleSpec> getJSIModules(
|
|
23
|
-
ReactApplicationContext reactApplicationContext, JavaScriptContextHolder jsContext) {
|
|
24
|
-
Log.w(
|
|
25
|
-
"[REANIMATED]",
|
|
26
|
-
"Since 2.5.0, Reanimated autoinstalls on Android - you can remove getJSIModulePackage() override in MainApplication.java.");
|
|
27
|
-
return Arrays.<JSIModuleSpec>asList();
|
|
28
|
-
}
|
|
29
|
-
}
|