react-native-reanimated 3.0.0-rc.2 → 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.
- 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 +6 -1
- 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 -2
- 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 +21 -85
- package/android/CMakeLists.txt +62 -58
- package/android/build.gradle +421 -114
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +10 -8
- package/android/src/main/cpp/AndroidErrorHandler.cpp +3 -4
- package/android/src/main/cpp/{headers/AndroidErrorHandler.h → AndroidErrorHandler.h} +1 -4
- 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/ReanimatedMessageQueueThreadBase.java +72 -0
- package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +2 -1
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +1 -1
- package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +7 -7
- package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/UIImplementation/64/com/swmansion/reanimated}/layoutReanimation/ReanimatedUIImplementation.java +0 -0
- package/android/src/{main/java → reactNativeVersionPatch/UIImplementation/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +0 -0
- package/android/src/reactNativeVersionPatch/messageQueueThread/67/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
- package/android/src/reactNativeVersionPatch/messageQueueThread/latest/com/swmansion/reanimated/ReanimatedMessageQueueThread.java +12 -0
- package/android/{rnVersionPatch/62 → src/reactNativeVersionPatch/nativeHierarchyManager/62/com/swmansion/reanimated}/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
- package/android/src/{main/java → reactNativeVersionPatch/nativeHierarchyManager/latest}/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +0 -0
- package/ios/REAModule.mm +29 -0
- package/ios/keyboardObserver/REAKeyboardEventObserver.m +1 -1
- 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/createAnimatedComponent.js +2 -5
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeMethods.js +67 -31
- 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/globals.d.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 +33 -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/createAnimatedComponent.js +2 -5
- package/lib/module/createAnimatedComponent.js.map +1 -1
- package/lib/module/reanimated2/NativeMethods.js +68 -30
- 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/globals.d.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 +21 -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 +10 -6
- package/plugin.js +105 -47
- package/react-native-reanimated.d.ts +13 -9
- package/scripts/reanimated_utils.rb +77 -0
- package/src/createAnimatedComponent.tsx +2 -3
- package/src/reanimated2/NativeMethods.ts +91 -44
- 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/globals.d.ts +56 -14
- 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 +37 -0
- package/src/reanimated2/utils.ts +12 -5
- package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +0 -68
- package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +0 -68
- package/android/rnVersionPatch/65/.gitkeep +0 -0
- package/android/rnVersionPatch/66/.gitkeep +0 -0
- package/android/rnVersionPatch/67/.gitkeep +0 -0
- package/android/rnVersionPatch/68/.gitkeep +0 -0
- package/android/rnVersionPatch/backup/.gitkeep +0 -0
- package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +0 -8
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +0 -29
|
@@ -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
|
+
export 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
|
};
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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: {
|
|
@@ -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,37 @@
|
|
|
1
|
+
import { RefObject, useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import type Animated from 'react-native-reanimated';
|
|
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';
|
|
9
|
+
|
|
10
|
+
const subscribeForEvents = [
|
|
11
|
+
'onScroll',
|
|
12
|
+
'onScrollBeginDrag',
|
|
13
|
+
'onScrollEndDrag',
|
|
14
|
+
'onMomentumScrollBegin',
|
|
15
|
+
'onMomentumScrollEnd',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export function useScrollViewOffset(
|
|
19
|
+
aref: RefObject<Animated.ScrollView>
|
|
20
|
+
): SharedValue<number> {
|
|
21
|
+
const offsetRef = useRef(useSharedValue(0));
|
|
22
|
+
|
|
23
|
+
const event = useEvent<ScrollEvent>((event: ScrollEvent) => {
|
|
24
|
+
'worklet';
|
|
25
|
+
offsetRef.current.value =
|
|
26
|
+
event.contentOffset.x === 0
|
|
27
|
+
? event.contentOffset.y
|
|
28
|
+
: event.contentOffset.x;
|
|
29
|
+
}, subscribeForEvents);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const viewTag = findNodeHandle(aref.current);
|
|
33
|
+
event.current?.registerForEvents(viewTag as number);
|
|
34
|
+
}, [aref.current]);
|
|
35
|
+
|
|
36
|
+
return offsetRef.current;
|
|
37
|
+
}
|
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,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,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
|
-
}
|