react-native-reanimated 2.10.0 → 2.11.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.
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +3 -0
- package/Common/cpp/{headers/AnimatedSensor → AnimatedSensor}/AnimatedSensorModule.h +0 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +2 -0
- package/Common/cpp/{headers/LayoutAnimations → LayoutAnimations}/LayoutAnimationsProxy.h +0 -0
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +2 -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/{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/Registries/WorkletsCache.cpp +3 -0
- 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 +7 -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 +14 -73
- package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
- package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/{7.2 → 7.5.1}/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/{7.2 → 7.5.1}/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/{7.2 → 7.5.1}/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/{7.2 → 7.5.1}/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/CMakeLists.txt +56 -65
- package/android/build.gradle +377 -103
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/react-native-reanimated-66-hermes.aar +0 -0
- package/android/react-native-reanimated-66-jsc.aar +0 -0
- package/android/react-native-reanimated-67-hermes.aar +0 -0
- package/android/react-native-reanimated-67-jsc.aar +0 -0
- package/android/react-native-reanimated-68-hermes.aar +0 -0
- package/android/react-native-reanimated-68-jsc.aar +0 -0
- package/android/react-native-reanimated-69-hermes.aar +0 -0
- package/android/react-native-reanimated-69-jsc.aar +0 -0
- package/android/react-native-reanimated-70-hermes.aar +0 -0
- package/android/react-native-reanimated-70-jsc.aar +0 -0
- 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 +6 -8
- package/android/src/main/cpp/{headers/NativeProxy.h → NativeProxy.h} +0 -0
- package/android/src/main/cpp/{headers/TurboModule.h → TurboModule.h} +0 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +4 -5
- package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +2 -1
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +2 -2
- package/ios/{REAModule.m → REAModule.mm} +12 -0
- package/ios/native/NativeProxy.mm +4 -2
- package/ios/native/REAInitializer.h +2 -2
- package/ios/native/REAInitializer.mm +2 -2
- package/ios/native/UIResponder+Reanimated.mm +1 -1
- package/lib/index.web.js +2 -0
- package/lib/reanimated2/NativeMethods.js +33 -19
- package/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.js +4 -4
- package/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.js +47 -18
- package/lib/reanimated2/globals.d.ts +2 -2
- package/lib/reanimated2/hook/index.js +1 -0
- package/lib/reanimated2/hook/useScrollViewOffset.js +26 -0
- package/lib/reanimated2/utils.js +10 -3
- package/lib/types/index.web.d.ts +1 -0
- package/lib/types/reanimated2/NativeMethods.d.ts +3 -10
- package/lib/types/reanimated2/commonTypes.d.ts +8 -0
- package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryJS.d.ts +4 -3
- package/lib/types/reanimated2/frameCallback/FrameCallbackRegistryUI.d.ts +5 -9
- package/lib/types/reanimated2/hook/index.d.ts +1 -0
- package/lib/types/reanimated2/hook/useAnimatedScrollHandler.d.ts +1 -2
- package/lib/types/reanimated2/hook/useFrameCallback.d.ts +2 -1
- package/lib/types/reanimated2/hook/useScrollViewOffset.d.ts +4 -0
- package/lib/types/reanimated2/utils.d.ts +5 -1
- package/package.json +5 -4
- package/plugin.js +1 -1
- package/react-native-reanimated.d.ts +13 -9
- package/scripts/reanimated_utils.rb +65 -0
- package/src/index.web.ts +2 -0
- package/src/reanimated2/NativeMethods.ts +44 -32
- 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 +2 -2
- 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/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +0 -8
- package/lib/reanimated2/__mocks__/NativeReanimated.native.js +0 -20
- package/lib/types/reanimated2/__mocks__/NativeReanimated.native.d.ts +0 -13
|
@@ -4,4 +4,8 @@ export interface ComponentCoords {
|
|
|
4
4
|
x: number;
|
|
5
5
|
y: number;
|
|
6
6
|
}
|
|
7
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-reanimated",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.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",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"!ios/build/",
|
|
51
51
|
"!android/build/",
|
|
52
52
|
"RNReanimated.podspec",
|
|
53
|
+
"scripts/reanimated_utils.rb",
|
|
53
54
|
"README.md",
|
|
54
55
|
"react-native-reanimated.d.ts",
|
|
55
56
|
"mock.js",
|
|
@@ -93,7 +94,7 @@
|
|
|
93
94
|
"@react-native-community/bob": "^0.17.1",
|
|
94
95
|
"@react-native-community/eslint-config": "^0.0.5",
|
|
95
96
|
"@testing-library/jest-native": "^4.0.4",
|
|
96
|
-
"@testing-library/react-hooks": "^
|
|
97
|
+
"@testing-library/react-hooks": "^8.0.0",
|
|
97
98
|
"@testing-library/react-native": "^7.1.0",
|
|
98
99
|
"@types/babel-types": "^7.0.11",
|
|
99
100
|
"@types/babel__core": "^7.1.18",
|
|
@@ -121,11 +122,11 @@
|
|
|
121
122
|
"madge": "^5.0.1",
|
|
122
123
|
"prettier": "^2.5.1",
|
|
123
124
|
"react": "17.0.2",
|
|
124
|
-
"react-native": "0.70.
|
|
125
|
+
"react-native": "0.70.2",
|
|
125
126
|
"react-native-builder-bob": "^0.18.3",
|
|
126
127
|
"react-native-codegen": "^0.0.7",
|
|
127
128
|
"react-native-gesture-handler": "^1.6.1",
|
|
128
|
-
"react-test-renderer": "
|
|
129
|
+
"react-test-renderer": "17.0.2",
|
|
129
130
|
"release-it": "^13.7.2",
|
|
130
131
|
"typescript": "^4.1.3"
|
|
131
132
|
},
|
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,65 @@
|
|
|
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
|
+
result[:react_native_common_dir] = File.join(react_native_node_modules_dir, 'react-native', 'ReactCommon')
|
|
40
|
+
|
|
41
|
+
return result
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def assert_no_multiple_instances(react_native_info)
|
|
45
|
+
if react_native_info[:is_reanimated_example_app]
|
|
46
|
+
return
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
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"]
|
|
50
|
+
lib_instances_in_react_native_node_modules_array = lib_instances_in_react_native_node_modules.split("\n")
|
|
51
|
+
reanimated_instances = lib_instances_in_react_native_node_modules_array.length()
|
|
52
|
+
if react_native_info[:react_native_node_modules_dir] != react_native_info[:reanimated_node_modules_dir]
|
|
53
|
+
lib_instances_in_reanimated_node_modules = %x[find #{react_native_info[:reanimated_node_modules_dir]} -name "package.json" | grep "/react-native-reanimated/package.json"]
|
|
54
|
+
lib_instances_in_reanimated_node_modules_array = lib_instances_in_reanimated_node_modules.split("\n")
|
|
55
|
+
reanimated_instances += lib_instances_in_reanimated_node_modules_array.length()
|
|
56
|
+
end
|
|
57
|
+
if reanimated_instances > 1
|
|
58
|
+
parsed_location = ''
|
|
59
|
+
for location in lib_instances_in_react_native_node_modules_array + lib_instances_in_reanimated_node_modules_array
|
|
60
|
+
location['/package.json'] = ''
|
|
61
|
+
parsed_location += "- " + location + "\n"
|
|
62
|
+
end
|
|
63
|
+
raise "[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
|
|
64
|
+
end
|
|
65
|
+
end
|
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
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* global _WORKLET _measure _scrollTo _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,58 @@ 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 (!
|
|
20
|
+
if (!isNative) {
|
|
31
21
|
console.warn(
|
|
32
|
-
'[
|
|
22
|
+
'[Reanimated] measure() cannot be used on 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
|
+
|
|
27
|
+
if (!_WORKLET) {
|
|
28
|
+
console.warn(
|
|
29
|
+
'[Reanimated] measure() was called from the main JS context. Measure is ' +
|
|
30
|
+
'only available in the UI runtime. This may also happen if measure() ' +
|
|
31
|
+
'was called by a worklet in the useAnimatedStyle hook, because useAnimatedStyle ' +
|
|
32
|
+
'calls the given worklet on the JS runtime during render. If you want to ' +
|
|
33
|
+
'prevent this warning then wrap the call with `if (_WORKLET)`. Then it will ' +
|
|
34
|
+
'only be called on the UI runtime after the render has been completed.'
|
|
35
|
+
);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
43
39
|
const viewTag = animatedRef();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
if (viewTag === -1) {
|
|
41
|
+
console.warn(
|
|
42
|
+
`[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).`
|
|
43
|
+
);
|
|
44
|
+
return null;
|
|
47
45
|
}
|
|
48
|
-
|
|
46
|
+
|
|
47
|
+
const measured = _measure(viewTag);
|
|
48
|
+
if (measured === null) {
|
|
49
|
+
console.warn(
|
|
50
|
+
`[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).`
|
|
51
|
+
);
|
|
52
|
+
return null;
|
|
53
|
+
} else if (measured.x === -1234567) {
|
|
54
|
+
console.warn(
|
|
55
|
+
`[Reanimated] The view with tag ${viewTag} returned an invalid measurement response`
|
|
56
|
+
);
|
|
57
|
+
return null;
|
|
58
|
+
} else if (isNaN(measured.x)) {
|
|
49
59
|
console.warn(
|
|
50
|
-
|
|
60
|
+
`[Reanimated] The view with tag ${viewTag} gets view-flattened on Android. To disable view-flattening, set \`collapsable={false}\` on this component.`
|
|
51
61
|
);
|
|
62
|
+
return null;
|
|
63
|
+
} else {
|
|
64
|
+
return measured;
|
|
52
65
|
}
|
|
53
|
-
return result;
|
|
54
66
|
}
|
|
55
67
|
|
|
56
68
|
export function scrollTo(
|
|
@@ -60,7 +72,7 @@ export function scrollTo(
|
|
|
60
72
|
animated: boolean
|
|
61
73
|
): void {
|
|
62
74
|
'worklet';
|
|
63
|
-
if (!_WORKLET ||
|
|
75
|
+
if (!_WORKLET || !isNative) {
|
|
64
76
|
return;
|
|
65
77
|
}
|
|
66
78
|
const viewTag = animatedRef();
|
|
@@ -69,7 +81,7 @@ export function scrollTo(
|
|
|
69
81
|
|
|
70
82
|
export function setGestureState(handlerTag: number, newState: number): void {
|
|
71
83
|
'worklet';
|
|
72
|
-
if (!_WORKLET ||
|
|
84
|
+
if (!_WORKLET || !isNative) {
|
|
73
85
|
console.warn(
|
|
74
86
|
'[Reanimated] You can not use setGestureState in non-worklet function.'
|
|
75
87
|
);
|
|
@@ -160,3 +160,12 @@ export type AnimatedKeyboardInfo = {
|
|
|
160
160
|
height: SharedValue<number>;
|
|
161
161
|
state: SharedValue<KeyboardState>;
|
|
162
162
|
};
|
|
163
|
+
|
|
164
|
+
export interface MeasuredDimensions {
|
|
165
|
+
x: number;
|
|
166
|
+
y: number;
|
|
167
|
+
width: number;
|
|
168
|
+
height: number;
|
|
169
|
+
pageX: number;
|
|
170
|
+
pageY: number;
|
|
171
|
+
}
|
|
@@ -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
|
};
|
|
@@ -20,7 +20,7 @@ declare global {
|
|
|
20
20
|
name: string,
|
|
21
21
|
updates: StyleProps | AnimatedStyle
|
|
22
22
|
) => void;
|
|
23
|
-
const _measure: (viewTag: number) => MeasuredDimensions;
|
|
23
|
+
const _measure: (viewTag: number) => MeasuredDimensions | null;
|
|
24
24
|
const _scrollTo: (
|
|
25
25
|
viewTag: number,
|
|
26
26
|
x: number,
|
|
@@ -40,7 +40,7 @@ declare global {
|
|
|
40
40
|
_WORKLET: boolean;
|
|
41
41
|
__reanimatedModuleProxy: NativeReanimated;
|
|
42
42
|
_frameTimestamp: number | null;
|
|
43
|
-
_measure: () => MeasuredDimensions;
|
|
43
|
+
_measure: () => MeasuredDimensions | null;
|
|
44
44
|
_scrollTo: () => void;
|
|
45
45
|
_chronoNow: () => number;
|
|
46
46
|
performance: { now: () => number };
|
|
@@ -27,3 +27,4 @@ export { useAnimatedSensor, SensorType } from './useAnimatedSensor';
|
|
|
27
27
|
export { useFrameCallback } from './useFrameCallback';
|
|
28
28
|
export type { FrameCallback } from './useFrameCallback';
|
|
29
29
|
export { useAnimatedKeyboard } from './useAnimatedKeyboard';
|
|
30
|
+
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
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
import MutableValue from './MutableValue';
|
|
4
|
-
global._setGlobalConsole = (_val) => {
|
|
5
|
-
// noop
|
|
6
|
-
};
|
|
7
|
-
const NOOP = () => {
|
|
8
|
-
// noop
|
|
9
|
-
};
|
|
10
|
-
export default {
|
|
11
|
-
installCoreFunctions: NOOP,
|
|
12
|
-
makeShareable: (worklet) => worklet,
|
|
13
|
-
makeMutable: (init) => new MutableValue(init),
|
|
14
|
-
makeRemote: NOOP,
|
|
15
|
-
startMapper: NOOP,
|
|
16
|
-
stopMapper: NOOP,
|
|
17
|
-
registerEventHandler: NOOP,
|
|
18
|
-
unregisterEventHandler: NOOP,
|
|
19
|
-
getViewProp: NOOP,
|
|
20
|
-
};
|