react-native-reanimated 2.4.1 → 2.5.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 +72 -0
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +30 -1
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +64 -39
- package/Common/cpp/Tools/RuntimeDecorator.cpp +2 -0
- package/Common/cpp/headers/AnimatedSensor/AnimatedSensorModule.h +41 -0
- package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +14 -0
- package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +14 -0
- package/Common/cpp/headers/SharedItems/MutableValue.h +4 -1
- package/Common/cpp/headers/SharedItems/ShareableValue.h +3 -0
- package/Common/cpp/headers/SharedItems/ValueWrapper.h +3 -0
- package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +11 -0
- package/Common/cpp/headers/Tools/RuntimeDecorator.h +2 -0
- package/README.md +2 -2
- package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.2/dependencies-accessors/gc.properties +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/fileChanges/last-build.bin +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/7.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/7.2/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +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/.gradle/vcs-1/gc.properties +0 -0
- package/android/CMakeLists.txt +198 -0
- package/android/README.md +15 -0
- package/android/build.gradle +686 -73
- package/android/empty.cpp +1 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +25 -0
- package/android/gradlew +234 -0
- package/android/gradlew.bat +89 -0
- package/android/react-native-reanimated-64-hermes.aar +0 -0
- package/android/react-native-reanimated-64-jsc.aar +0 -0
- package/android/react-native-reanimated-65-hermes.aar +0 -0
- package/android/react-native-reanimated-65-jsc.aar +0 -0
- 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/rnVersionPatch/62/layoutReanimation/ReanimatedNativeHierarchyManager.java +412 -0
- package/android/rnVersionPatch/62/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- 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/settings.gradle +1 -0
- package/android/spotless.gradle +9 -0
- package/android/src/{AndroidManifest.xml → main/AndroidManifest.xml} +0 -0
- package/android/src/main/cpp/AndroidErrorHandler.cpp +42 -0
- package/android/src/main/cpp/AndroidLogger.cpp +27 -0
- package/android/src/main/cpp/AndroidScheduler.cpp +59 -0
- package/android/src/main/cpp/JNIHelper.cpp +59 -0
- package/android/src/main/cpp/LayoutAnimations.cpp +103 -0
- package/android/src/main/cpp/NativeProxy.cpp +327 -0
- package/android/src/main/cpp/OnLoad.cpp +17 -0
- package/android/src/main/cpp/TurboModule.cpp +44 -0
- package/android/src/main/cpp/headers/AndroidErrorHandler.h +30 -0
- package/android/src/main/cpp/headers/AndroidLogger.h +16 -0
- package/android/src/main/cpp/headers/AndroidScheduler.h +41 -0
- package/android/src/main/cpp/headers/JNIHelper.h +30 -0
- package/android/src/main/cpp/headers/LayoutAnimations.h +42 -0
- package/android/src/main/cpp/headers/NativeProxy.h +170 -0
- package/android/src/main/cpp/headers/TurboModule.h +70 -0
- package/android/src/main/java/com/facebook/react/uimanager/UIManagerReanimatedHelper.java +15 -0
- package/android/src/main/java/com/swmansion/common/GestureHandlerStateManager.java +5 -0
- package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +8 -0
- package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +43 -0
- package/android/src/main/java/com/swmansion/reanimated/MapUtils.java +26 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +117 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +285 -0
- package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +682 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +29 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java +251 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +96 -0
- package/android/src/main/java/com/swmansion/reanimated/Scheduler.java +51 -0
- package/android/src/main/java/com/swmansion/reanimated/UpdateContext.java +11 -0
- package/android/src/main/java/com/swmansion/reanimated/Utils.java +32 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +517 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +56 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +11 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +410 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +292 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +121 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +12 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/AlwaysNode.java +29 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/BezierNode.java +87 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/BlockNode.java +24 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/CallFuncNode.java +49 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ClockNode.java +38 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ClockOpNode.java +73 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java +36 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/CondNode.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/DebugNode.java +33 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/EventNode.java +83 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/FinalNode.java +5 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/FunctionNode.java +20 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/JSCallNode.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/Node.java +139 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/NoopNode.java +37 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/OperatorNode.java +377 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ParamNode.java +71 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/PropsNode.java +153 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/SetNode.java +32 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/StyleNode.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/TransformNode.java +84 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ValueNode.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +35 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/ChangeTransition.java +84 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/SaneSidePropagation.java +25 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/Scale.java +86 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionUtils.java +161 -0
- package/ios/LayoutReanimation/REAAnimationsManager.m +14 -4
- package/ios/REAModule.m +8 -9
- package/ios/REANodesManager.h +4 -1
- package/ios/REANodesManager.m +75 -3
- package/ios/native/NativeProxy.mm +76 -4
- package/ios/sensor/ReanimatedSensor.h +21 -0
- package/ios/sensor/ReanimatedSensor.m +169 -0
- package/ios/sensor/ReanimatedSensorContainer.h +13 -0
- package/ios/sensor/ReanimatedSensorContainer.m +41 -0
- package/ios/sensor/ReanimatedSensorType.h +7 -0
- package/lib/ConfigHelper.js +2 -2
- package/lib/createAnimatedComponent.js +3 -4
- package/lib/reanimated1/core/AnimatedFunction.js +1 -1
- package/lib/reanimated1/derived/interpolate.js +2 -4
- package/lib/reanimated2/Colors.js +2 -1
- package/lib/reanimated2/NativeReanimated/NativeReanimated.js +25 -12
- package/lib/reanimated2/NativeReanimated/index.js +0 -4
- package/lib/reanimated2/ViewDescriptorsSet.js +2 -2
- package/lib/reanimated2/animation/styleAnimation.js +2 -1
- package/lib/reanimated2/core.js +30 -24
- package/lib/reanimated2/globals.d.ts +6 -0
- package/lib/reanimated2/hook/index.js +1 -0
- package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
- package/lib/reanimated2/interpolation.js +1 -1
- package/lib/reanimated2/jestUtils.js +9 -4
- package/lib/reanimated2/js-reanimated/JSReanimated.js +23 -2
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +2 -1
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +32 -42
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +20 -38
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +32 -44
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -16
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -10
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +20 -36
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -20
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +8 -12
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +32 -48
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +22 -18
- package/lib/reanimated2/mock.js +3 -2
- package/mock.js +4 -4
- package/package.json +42 -36
- package/plugin.js +2 -0
- package/react-native-reanimated.d.ts +41 -12
- package/src/ConfigHelper.ts +4 -4
- package/src/createAnimatedComponent.tsx +3 -3
- package/src/reanimated1/core/AnimatedFunction.js +1 -1
- package/src/reanimated1/derived/interpolate.js +2 -4
- package/src/reanimated2/Colors.ts +2 -1
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +42 -15
- package/src/reanimated2/NativeReanimated/index.ts +0 -6
- package/src/reanimated2/ViewDescriptorsSet.ts +2 -3
- package/src/reanimated2/animation/index.ts +1 -0
- package/src/reanimated2/animation/styleAnimation.ts +10 -7
- package/src/reanimated2/animation/timing.ts +3 -1
- package/src/reanimated2/animation/util.ts +10 -11
- package/src/reanimated2/commonTypes.ts +20 -0
- package/src/reanimated2/component/FlatList.tsx +2 -1
- package/src/reanimated2/core.ts +34 -26
- package/src/reanimated2/globals.d.ts +6 -0
- package/src/reanimated2/hook/index.ts +1 -0
- package/src/reanimated2/hook/useAnimatedSensor.ts +91 -0
- package/src/reanimated2/hook/utils.ts +2 -1
- package/src/reanimated2/interpolation.ts +2 -6
- package/src/reanimated2/jestUtils.ts +9 -4
- package/src/reanimated2/js-reanimated/JSReanimated.ts +25 -2
- package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +13 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -3
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +51 -21
- package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +40 -10
- package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +48 -12
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -2
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +32 -8
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -10
- package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +64 -16
- package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +26 -19
- package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +2 -1
- package/src/reanimated2/mock.ts +3 -2
- package/android/react-native-reanimated-63-hermes.aar +0 -0
- package/android/react-native-reanimated-63-jsc.aar +0 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedProxyPackage.java +0 -15
- package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <fbjni/fbjni.h>
|
|
4
|
+
#include <jni.h>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
#include <react/jni/CxxModuleWrapper.h>
|
|
7
|
+
#include <react/jni/JMessageQueueThread.h>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include "Scheduler.h"
|
|
10
|
+
|
|
11
|
+
namespace reanimated {
|
|
12
|
+
|
|
13
|
+
using namespace facebook;
|
|
14
|
+
|
|
15
|
+
class AndroidScheduler : public jni::HybridClass<AndroidScheduler> {
|
|
16
|
+
public:
|
|
17
|
+
static auto constexpr kJavaDescriptor =
|
|
18
|
+
"Lcom/swmansion/reanimated/Scheduler;";
|
|
19
|
+
static jni::local_ref<jhybriddata> initHybrid(
|
|
20
|
+
jni::alias_ref<jhybridobject> jThis);
|
|
21
|
+
static void registerNatives();
|
|
22
|
+
|
|
23
|
+
std::shared_ptr<Scheduler> getScheduler() {
|
|
24
|
+
return scheduler_;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void scheduleOnUI();
|
|
28
|
+
|
|
29
|
+
private:
|
|
30
|
+
friend HybridBase;
|
|
31
|
+
|
|
32
|
+
void triggerUI();
|
|
33
|
+
|
|
34
|
+
jni::global_ref<AndroidScheduler::javaobject> javaPart_;
|
|
35
|
+
std::shared_ptr<Scheduler> scheduler_;
|
|
36
|
+
|
|
37
|
+
explicit AndroidScheduler(
|
|
38
|
+
jni::alias_ref<AndroidScheduler::jhybridobject> jThis);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
} // namespace reanimated
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <fbjni/fbjni.h>
|
|
4
|
+
#include <jsi/JSIDynamic.h>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
#include <react/jni/CxxModuleWrapper.h>
|
|
7
|
+
#include <react/jni/JMessageQueueThread.h>
|
|
8
|
+
#include <react/jni/WritableNativeMap.h>
|
|
9
|
+
#include <string>
|
|
10
|
+
|
|
11
|
+
namespace reanimated {
|
|
12
|
+
|
|
13
|
+
using namespace facebook::jni;
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
using namespace react;
|
|
16
|
+
|
|
17
|
+
struct JNIHelper {
|
|
18
|
+
struct PropsMap : jni::JavaClass<PropsMap, JMap<JString, JObject>> {
|
|
19
|
+
static constexpr auto kJavaDescriptor = "Ljava/util/HashMap;";
|
|
20
|
+
|
|
21
|
+
static local_ref<PropsMap> create();
|
|
22
|
+
void put(const std::string &key, jni::local_ref<JObject> object);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static jni::local_ref<PropsMap> ConvertToPropsMap(
|
|
26
|
+
jsi::Runtime &rt,
|
|
27
|
+
const jsi::Object &props);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
}; // namespace reanimated
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <fbjni/fbjni.h>
|
|
4
|
+
#include <jsi/jsi.h>
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include "JNIHelper.h"
|
|
7
|
+
|
|
8
|
+
namespace reanimated {
|
|
9
|
+
|
|
10
|
+
using namespace facebook::jni;
|
|
11
|
+
using namespace facebook;
|
|
12
|
+
|
|
13
|
+
class LayoutAnimations : public jni::HybridClass<LayoutAnimations> {
|
|
14
|
+
public:
|
|
15
|
+
static auto constexpr kJavaDescriptor =
|
|
16
|
+
"Lcom/swmansion/reanimated/layoutReanimation/LayoutAnimations;";
|
|
17
|
+
static jni::local_ref<jhybriddata> initHybrid(
|
|
18
|
+
jni::alias_ref<jhybridobject> jThis);
|
|
19
|
+
static void registerNatives();
|
|
20
|
+
|
|
21
|
+
void startAnimationForTag(
|
|
22
|
+
int tag,
|
|
23
|
+
alias_ref<JString> type,
|
|
24
|
+
alias_ref<JMap<jstring, jstring>> values);
|
|
25
|
+
void removeConfigForTag(int tag);
|
|
26
|
+
bool isLayoutAnimationEnabled();
|
|
27
|
+
|
|
28
|
+
void setWeakUIRuntime(std::weak_ptr<jsi::Runtime> wrt);
|
|
29
|
+
|
|
30
|
+
void notifyAboutProgress(const jsi::Value &progress, int tag);
|
|
31
|
+
void notifyAboutEnd(int tag, int cancelled);
|
|
32
|
+
|
|
33
|
+
private:
|
|
34
|
+
friend HybridBase;
|
|
35
|
+
jni::global_ref<LayoutAnimations::javaobject> javaPart_;
|
|
36
|
+
std::weak_ptr<jsi::Runtime> weakUIRuntime;
|
|
37
|
+
|
|
38
|
+
explicit LayoutAnimations(
|
|
39
|
+
jni::alias_ref<LayoutAnimations::jhybridobject> jThis);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
}; // namespace reanimated
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ReactCommon/CallInvokerHolder.h>
|
|
4
|
+
#include <fbjni/fbjni.h>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
#include <react/jni/CxxModuleWrapper.h>
|
|
7
|
+
#include <react/jni/JMessageQueueThread.h>
|
|
8
|
+
#include <react/jni/JavaScriptExecutorHolder.h>
|
|
9
|
+
#include <react/jni/WritableNativeMap.h>
|
|
10
|
+
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <unordered_map>
|
|
14
|
+
#include <utility>
|
|
15
|
+
#include <vector>
|
|
16
|
+
|
|
17
|
+
#include "AndroidScheduler.h"
|
|
18
|
+
#include "JNIHelper.h"
|
|
19
|
+
#include "LayoutAnimations.h"
|
|
20
|
+
#include "NativeReanimatedModule.h"
|
|
21
|
+
#include "Scheduler.h"
|
|
22
|
+
|
|
23
|
+
namespace reanimated {
|
|
24
|
+
|
|
25
|
+
using namespace facebook;
|
|
26
|
+
using namespace facebook::jni;
|
|
27
|
+
|
|
28
|
+
class AnimationFrameCallback : public HybridClass<AnimationFrameCallback> {
|
|
29
|
+
public:
|
|
30
|
+
static auto constexpr kJavaDescriptor =
|
|
31
|
+
"Lcom/swmansion/reanimated/NativeProxy$AnimationFrameCallback;";
|
|
32
|
+
|
|
33
|
+
void onAnimationFrame(double timestampMs) {
|
|
34
|
+
callback_(timestampMs);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static void registerNatives() {
|
|
38
|
+
javaClassStatic()->registerNatives({
|
|
39
|
+
makeNativeMethod(
|
|
40
|
+
"onAnimationFrame", AnimationFrameCallback::onAnimationFrame),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private:
|
|
45
|
+
friend HybridBase;
|
|
46
|
+
|
|
47
|
+
explicit AnimationFrameCallback(std::function<void(double)> callback)
|
|
48
|
+
: callback_(std::move(callback)) {}
|
|
49
|
+
|
|
50
|
+
std::function<void(double)> callback_;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
class EventHandler : public HybridClass<EventHandler> {
|
|
54
|
+
public:
|
|
55
|
+
static auto constexpr kJavaDescriptor =
|
|
56
|
+
"Lcom/swmansion/reanimated/NativeProxy$EventHandler;";
|
|
57
|
+
|
|
58
|
+
void receiveEvent(
|
|
59
|
+
jni::alias_ref<JString> eventKey,
|
|
60
|
+
jni::alias_ref<react::WritableMap> event) {
|
|
61
|
+
std::string eventAsString = "{NativeMap:null}";
|
|
62
|
+
if (event != nullptr) {
|
|
63
|
+
try {
|
|
64
|
+
eventAsString = event->toString();
|
|
65
|
+
} catch (std::exception &) {
|
|
66
|
+
// Events from other libraries may contain NaN or INF values which
|
|
67
|
+
// cannot be represented in JSON. See
|
|
68
|
+
// https://github.com/software-mansion/react-native-reanimated/issues/1776
|
|
69
|
+
// for details.
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
handler_(eventKey->toString(), eventAsString);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static void registerNatives() {
|
|
77
|
+
javaClassStatic()->registerNatives({
|
|
78
|
+
makeNativeMethod("receiveEvent", EventHandler::receiveEvent),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private:
|
|
83
|
+
friend HybridBase;
|
|
84
|
+
|
|
85
|
+
explicit EventHandler(std::function<void(std::string, std::string)> handler)
|
|
86
|
+
: handler_(std::move(handler)) {}
|
|
87
|
+
|
|
88
|
+
std::function<void(std::string, std::string)> handler_;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
class SensorSetter : public HybridClass<SensorSetter> {
|
|
92
|
+
public:
|
|
93
|
+
static auto constexpr kJavaDescriptor =
|
|
94
|
+
"Lcom/swmansion/reanimated/NativeProxy$SensorSetter;";
|
|
95
|
+
|
|
96
|
+
void sensorSetter(jni::alias_ref<JArrayFloat> value) {
|
|
97
|
+
size_t size = value->size();
|
|
98
|
+
auto elements = value->getRegion(0, size);
|
|
99
|
+
double array[7];
|
|
100
|
+
for (int i = 0; i < size; i++) {
|
|
101
|
+
array[i] = elements[i];
|
|
102
|
+
}
|
|
103
|
+
callback_(array);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static void registerNatives() {
|
|
107
|
+
javaClassStatic()->registerNatives({
|
|
108
|
+
makeNativeMethod("sensorSetter", SensorSetter::sensorSetter),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private:
|
|
113
|
+
friend HybridBase;
|
|
114
|
+
|
|
115
|
+
explicit SensorSetter(std::function<void(double[])> callback)
|
|
116
|
+
: callback_(std::move(callback)) {}
|
|
117
|
+
|
|
118
|
+
std::function<void(double[])> callback_;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
class NativeProxy : public jni::HybridClass<NativeProxy> {
|
|
122
|
+
public:
|
|
123
|
+
static auto constexpr kJavaDescriptor =
|
|
124
|
+
"Lcom/swmansion/reanimated/NativeProxy;";
|
|
125
|
+
static jni::local_ref<jhybriddata> initHybrid(
|
|
126
|
+
jni::alias_ref<jhybridobject> jThis,
|
|
127
|
+
jlong jsContext,
|
|
128
|
+
jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>
|
|
129
|
+
jsCallInvokerHolder,
|
|
130
|
+
jni::alias_ref<AndroidScheduler::javaobject> scheduler,
|
|
131
|
+
jni::alias_ref<LayoutAnimations::javaobject> layoutAnimations);
|
|
132
|
+
static void registerNatives();
|
|
133
|
+
|
|
134
|
+
private:
|
|
135
|
+
friend HybridBase;
|
|
136
|
+
jni::global_ref<NativeProxy::javaobject> javaPart_;
|
|
137
|
+
jsi::Runtime *runtime_;
|
|
138
|
+
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker_;
|
|
139
|
+
std::shared_ptr<NativeReanimatedModule> _nativeReanimatedModule;
|
|
140
|
+
std::shared_ptr<Scheduler> scheduler_;
|
|
141
|
+
jni::global_ref<LayoutAnimations::javaobject> layoutAnimations;
|
|
142
|
+
|
|
143
|
+
void installJSIBindings();
|
|
144
|
+
bool isAnyHandlerWaitingForEvent(std::string);
|
|
145
|
+
void requestRender(std::function<void(double)> onRender);
|
|
146
|
+
void registerEventHandler(
|
|
147
|
+
std::function<void(std::string, std::string)> handler);
|
|
148
|
+
void updateProps(jsi::Runtime &rt, int viewTag, const jsi::Object &props);
|
|
149
|
+
void scrollTo(int viewTag, double x, double y, bool animated);
|
|
150
|
+
void setGestureState(int handlerTag, int newState);
|
|
151
|
+
std::vector<std::pair<std::string, double>> measure(int viewTag);
|
|
152
|
+
int registerSensor(
|
|
153
|
+
int sensorType,
|
|
154
|
+
int interval,
|
|
155
|
+
std::function<void(double[])> setter);
|
|
156
|
+
void unregisterSensor(int sensorId);
|
|
157
|
+
void configureProps(
|
|
158
|
+
jsi::Runtime &rt,
|
|
159
|
+
const jsi::Value &uiProps,
|
|
160
|
+
const jsi::Value &nativeProps);
|
|
161
|
+
|
|
162
|
+
explicit NativeProxy(
|
|
163
|
+
jni::alias_ref<NativeProxy::jhybridobject> jThis,
|
|
164
|
+
jsi::Runtime *rt,
|
|
165
|
+
std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker,
|
|
166
|
+
std::shared_ptr<Scheduler> scheduler,
|
|
167
|
+
jni::global_ref<LayoutAnimations::javaobject> _layoutAnimations);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
} // namespace reanimated
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <ReactCommon/CallInvoker.h>
|
|
11
|
+
#include <jsi/jsi.h>
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <unordered_map>
|
|
15
|
+
|
|
16
|
+
namespace facebook {
|
|
17
|
+
namespace react {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* For now, support the same set of return types as existing impl.
|
|
21
|
+
* This can be improved to support richer typed objects.
|
|
22
|
+
*/
|
|
23
|
+
enum TurboModuleMethodValueKind {
|
|
24
|
+
VoidKind,
|
|
25
|
+
BooleanKind,
|
|
26
|
+
NumberKind,
|
|
27
|
+
StringKind,
|
|
28
|
+
ObjectKind,
|
|
29
|
+
ArrayKind,
|
|
30
|
+
FunctionKind,
|
|
31
|
+
PromiseKind,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Base HostObject class for every module to be exposed to JS
|
|
36
|
+
*/
|
|
37
|
+
class JSI_EXPORT TurboModule : public facebook::jsi::HostObject {
|
|
38
|
+
public:
|
|
39
|
+
TurboModule(const std::string &name, std::shared_ptr<CallInvoker> jsInvoker);
|
|
40
|
+
virtual ~TurboModule();
|
|
41
|
+
|
|
42
|
+
facebook::jsi::Value get(
|
|
43
|
+
facebook::jsi::Runtime &runtime,
|
|
44
|
+
const facebook::jsi::PropNameID &propName) override;
|
|
45
|
+
|
|
46
|
+
const std::string name_;
|
|
47
|
+
std::shared_ptr<CallInvoker> jsInvoker_;
|
|
48
|
+
|
|
49
|
+
protected:
|
|
50
|
+
struct MethodMetadata {
|
|
51
|
+
size_t argCount;
|
|
52
|
+
facebook::jsi::Value (*invoker)(
|
|
53
|
+
facebook::jsi::Runtime &rt,
|
|
54
|
+
TurboModule &turboModule,
|
|
55
|
+
const facebook::jsi::Value *args,
|
|
56
|
+
size_t count);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
std::unordered_map<std::string, MethodMetadata> methodMap_;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* An app/platform-specific provider function to get an instance of a module
|
|
64
|
+
* given a name.
|
|
65
|
+
*/
|
|
66
|
+
using TurboModuleProviderFunctionType =
|
|
67
|
+
std::function<std::shared_ptr<TurboModule>(const std::string &name)>;
|
|
68
|
+
|
|
69
|
+
} // namespace react
|
|
70
|
+
} // namespace facebook
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.facebook.react.uimanager;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This class provides a way to workaround limited visibility of
|
|
5
|
+
* UIViewOperationQueue#getUIViewOperationQueue. We rely on accessing that method to check if
|
|
6
|
+
* operation queue is empty or not. This in turn indicates if we are in a middle of processing batch
|
|
7
|
+
* of operations from JS. In such a case we can rely on the enqueued update operations to be flushed
|
|
8
|
+
* onto the shadow view hierarchy. Otherwise we want to trigger "dispatchViewUpdates" and enforce
|
|
9
|
+
* flush immediately.
|
|
10
|
+
*/
|
|
11
|
+
public class UIManagerReanimatedHelper {
|
|
12
|
+
public static boolean isOperationQueueEmpty(UIImplementation uiImplementation) {
|
|
13
|
+
return uiImplementation.getUIViewOperationQueue().isEmpty();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package com.swmansion.reanimated;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
import com.facebook.react.bridge.WritableArray;
|
|
5
|
+
import com.facebook.react.bridge.WritableMap;
|
|
6
|
+
import com.facebook.react.uimanager.events.Event;
|
|
7
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
8
|
+
|
|
9
|
+
public class CopiedEvent {
|
|
10
|
+
private int targetTag;
|
|
11
|
+
private String eventName;
|
|
12
|
+
private WritableMap payload;
|
|
13
|
+
|
|
14
|
+
CopiedEvent(Event event) {
|
|
15
|
+
event.dispatch(
|
|
16
|
+
new RCTEventEmitter() {
|
|
17
|
+
@Override
|
|
18
|
+
public void receiveEvent(int targetTag, String eventName, @Nullable WritableMap event) {
|
|
19
|
+
CopiedEvent.this.targetTag = targetTag;
|
|
20
|
+
CopiedEvent.this.eventName = eventName;
|
|
21
|
+
CopiedEvent.this.payload = event.copy();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public void receiveTouches(
|
|
26
|
+
String eventName, WritableArray touches, WritableArray changedIndices) {
|
|
27
|
+
// noop
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public int getTargetTag() {
|
|
33
|
+
return targetTag;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public String getEventName() {
|
|
37
|
+
return eventName;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public WritableMap getPayload() {
|
|
41
|
+
return payload;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package com.swmansion.reanimated;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.JSApplicationCausedNativeException;
|
|
4
|
+
import com.facebook.react.bridge.NoSuchKeyException;
|
|
5
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
6
|
+
import javax.annotation.Nonnull;
|
|
7
|
+
import javax.annotation.Nullable;
|
|
8
|
+
|
|
9
|
+
public class MapUtils {
|
|
10
|
+
public static int getInt(ReadableMap map, @Nonnull String name, String errorMsg) {
|
|
11
|
+
try {
|
|
12
|
+
return map.getInt(name);
|
|
13
|
+
} catch (NoSuchKeyException e) {
|
|
14
|
+
throw new JSApplicationCausedNativeException(errorMsg);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Nullable
|
|
19
|
+
public static String getString(ReadableMap map, @Nonnull String name, String errorMsg) {
|
|
20
|
+
try {
|
|
21
|
+
return map.getString(name);
|
|
22
|
+
} catch (NoSuchKeyException e) {
|
|
23
|
+
throw new JSApplicationCausedNativeException(errorMsg);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
package com.swmansion.reanimated;
|
|
2
|
+
|
|
3
|
+
import android.graphics.Matrix;
|
|
4
|
+
import android.graphics.RectF;
|
|
5
|
+
import android.util.Log;
|
|
6
|
+
import android.view.View;
|
|
7
|
+
import android.view.ViewParent;
|
|
8
|
+
import com.facebook.react.uimanager.PixelUtil;
|
|
9
|
+
import com.facebook.react.uimanager.RootViewUtil;
|
|
10
|
+
import com.facebook.react.views.scroll.ReactHorizontalScrollView;
|
|
11
|
+
import com.facebook.react.views.scroll.ReactScrollView;
|
|
12
|
+
import com.facebook.react.views.swiperefresh.ReactSwipeRefreshLayout;
|
|
13
|
+
|
|
14
|
+
public class NativeMethodsHelper {
|
|
15
|
+
|
|
16
|
+
public static float[] measure(View view) {
|
|
17
|
+
View rootView = (View) RootViewUtil.getRootView(view);
|
|
18
|
+
if (rootView == null || view == null) {
|
|
19
|
+
float result[] = new float[6];
|
|
20
|
+
result[0] = -1234567;
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
int buffer[] = new int[4];
|
|
25
|
+
computeBoundingBox(rootView, buffer);
|
|
26
|
+
int rootX = buffer[0];
|
|
27
|
+
int rootY = buffer[1];
|
|
28
|
+
computeBoundingBox(view, buffer);
|
|
29
|
+
buffer[0] -= rootX;
|
|
30
|
+
buffer[1] -= rootY;
|
|
31
|
+
|
|
32
|
+
float result[] = new float[6];
|
|
33
|
+
result[0] = result[1] = 0;
|
|
34
|
+
for (int i = 2; i < 6; ++i) result[i] = PixelUtil.toDIPFromPixel(buffer[i - 2]);
|
|
35
|
+
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public static void scrollTo(View view, double argX, double argY, boolean animated) {
|
|
40
|
+
int x = Math.round(PixelUtil.toPixelFromDIP(argX));
|
|
41
|
+
int y = Math.round(PixelUtil.toPixelFromDIP(argY));
|
|
42
|
+
boolean horizontal = false;
|
|
43
|
+
|
|
44
|
+
if (view instanceof ReactHorizontalScrollView) {
|
|
45
|
+
horizontal = true;
|
|
46
|
+
} else {
|
|
47
|
+
if (view instanceof ReactSwipeRefreshLayout) {
|
|
48
|
+
view = findScrollView((ReactSwipeRefreshLayout) view);
|
|
49
|
+
}
|
|
50
|
+
if (!(view instanceof ReactScrollView)) {
|
|
51
|
+
Log.w(
|
|
52
|
+
"REANIMATED",
|
|
53
|
+
"NativeMethodsHelper: Unhandled scroll view type - allowed only {ReactScrollView, ReactHorizontalScrollView}");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (animated) {
|
|
59
|
+
if (horizontal) {
|
|
60
|
+
((ReactHorizontalScrollView) view).smoothScrollTo((int) x, (int) y);
|
|
61
|
+
} else {
|
|
62
|
+
((ReactScrollView) view).smoothScrollTo((int) x, (int) y);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (horizontal) {
|
|
66
|
+
((ReactHorizontalScrollView) view).scrollTo((int) x, (int) y);
|
|
67
|
+
} else {
|
|
68
|
+
((ReactScrollView) view).scrollTo((int) x, (int) y);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private static ReactScrollView findScrollView(ReactSwipeRefreshLayout view) {
|
|
74
|
+
for (int i = 0; i < view.getChildCount(); i++) {
|
|
75
|
+
if (view.getChildAt(i) instanceof ReactScrollView) {
|
|
76
|
+
return (ReactScrollView) view.getChildAt(i);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private static void computeBoundingBox(View view, int[] outputBuffer) {
|
|
83
|
+
RectF boundingBox = new RectF();
|
|
84
|
+
boundingBox.set(0, 0, view.getWidth(), view.getHeight());
|
|
85
|
+
mapRectFromViewToWindowCoords(view, boundingBox);
|
|
86
|
+
|
|
87
|
+
outputBuffer[0] = Math.round(boundingBox.left);
|
|
88
|
+
outputBuffer[1] = Math.round(boundingBox.top);
|
|
89
|
+
outputBuffer[2] = Math.round(boundingBox.right - boundingBox.left);
|
|
90
|
+
outputBuffer[3] = Math.round(boundingBox.bottom - boundingBox.top);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private static void mapRectFromViewToWindowCoords(View view, RectF rect) {
|
|
94
|
+
Matrix matrix = view.getMatrix();
|
|
95
|
+
if (!matrix.isIdentity()) {
|
|
96
|
+
matrix.mapRect(rect);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
rect.offset(view.getLeft(), view.getTop());
|
|
100
|
+
|
|
101
|
+
ViewParent parent = view.getParent();
|
|
102
|
+
while (parent instanceof View) {
|
|
103
|
+
View parentView = (View) parent;
|
|
104
|
+
|
|
105
|
+
rect.offset(-parentView.getScrollX(), -parentView.getScrollY());
|
|
106
|
+
|
|
107
|
+
matrix = parentView.getMatrix();
|
|
108
|
+
if (!matrix.isIdentity()) {
|
|
109
|
+
matrix.mapRect(rect);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
rect.offset(parentView.getLeft(), parentView.getTop());
|
|
113
|
+
|
|
114
|
+
parent = parentView.getParent();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|