react-native-reanimated 2.1.0 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/Common/cpp/SharedItems/MutableValue.cpp +22 -18
  2. package/Common/cpp/SharedItems/ShareableValue.cpp +1 -1
  3. package/Common/cpp/Tools/JSIStoreValueUser.cpp +28 -15
  4. package/Common/cpp/Tools/RuntimeDecorator.cpp +20 -14
  5. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +8 -3
  6. package/Common/cpp/headers/Tools/RuntimeDecorator.h +10 -0
  7. package/README.md +3 -4
  8. package/RNReanimated.podspec +6 -6
  9. package/android/build.gradle +78 -2
  10. package/android/react-native-reanimated-63-hermes.aar +0 -0
  11. package/android/react-native-reanimated-63-jsc.aar +0 -0
  12. package/android/react-native-reanimated-64-hermes.aar +0 -0
  13. package/android/react-native-reanimated-64-jsc.aar +0 -0
  14. package/android/react-native-reanimated-65-hermes.aar +0 -0
  15. package/android/react-native-reanimated-65-jsc.aar +0 -0
  16. package/android/react-native-reanimated-66-hermes.aar +0 -0
  17. package/android/react-native-reanimated-66-jsc.aar +0 -0
  18. package/ios/REANodesManager.m +3 -0
  19. package/ios/native/NativeMethods.mm +2 -2
  20. package/ios/native/NativeProxy.mm +6 -2
  21. package/ios/native/REAInitializer.h +32 -0
  22. package/ios/native/REAInitializer.mm +54 -0
  23. package/ios/native/UIResponder+Reanimated.mm +8 -48
  24. package/lib/Animated.js +0 -3
  25. package/lib/createAnimatedComponent.js +8 -4
  26. package/lib/index.js +0 -3
  27. package/lib/reanimated1/animations/decay.js +4 -2
  28. package/lib/reanimated1/animations/spring.js +4 -3
  29. package/lib/reanimated1/animations/timing.js +1 -1
  30. package/lib/reanimated1/core/Core.test.js +30 -0
  31. package/lib/reanimated2/animations.js +33 -17
  32. package/lib/reanimated2/core.js +1 -1
  33. package/lib/reanimated2/jestUtils.js +55 -21
  34. package/lib/reanimated2/js-reanimated/JSReanimated.js +7 -4
  35. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  36. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  37. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  38. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
  39. package/mock.js +1 -1
  40. package/package.json +4 -3
  41. package/plugin.js +8 -0
  42. package/react-native-reanimated.d.ts +8 -2
  43. package/src/Animated.js +0 -3
  44. package/src/createAnimatedComponent.js +8 -4
  45. package/src/reanimated1/animations/decay.js +4 -2
  46. package/src/reanimated1/animations/spring.js +4 -3
  47. package/src/reanimated1/animations/timing.js +1 -1
  48. package/src/reanimated1/core/Core.test.js +30 -0
  49. package/src/reanimated2/animations.ts +48 -22
  50. package/src/reanimated2/core.ts +1 -1
  51. package/src/reanimated2/jestUtils.ts +63 -24
  52. package/src/reanimated2/js-reanimated/JSReanimated.ts +6 -4
  53. package/android/react-native-reanimated-62.aar +0 -0
  54. package/android/react-native-reanimated-63.aar +0 -0
  55. package/android/react-native-reanimated-64.aar +0 -0
  56. package/android/react-native-reanimated.aar +0 -0
@@ -16,7 +16,7 @@ void MutableValue::setValue(jsi::Runtime &rt, const jsi::Value &newValue) {
16
16
  listener.second();
17
17
  }
18
18
  };
19
- if (RuntimeDecorator::isWorkletRuntime(rt)) {
19
+ if (RuntimeDecorator::isUIRuntime(rt)) {
20
20
  notifyListeners();
21
21
  } else {
22
22
  runtimeManager->scheduler->scheduleOnUI([notifyListeners] {
@@ -32,8 +32,27 @@ jsi::Value MutableValue::getValue(jsi::Runtime &rt) {
32
32
 
33
33
  void MutableValue::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &newValue) {
34
34
  auto propName = name.utf8(rt);
35
+ if (!runtimeManager->valueSetter) {
36
+ throw jsi::JSError(rt, "Value-Setter is not yet configured! Make sure the core-functions are installed.");
37
+ }
35
38
 
36
- if (RuntimeDecorator::isReactRuntime(rt)) {
39
+ if (RuntimeDecorator::isUIRuntime(rt)) {
40
+ // UI thread
41
+ if (propName == "value") {
42
+ auto setterProxy = jsi::Object::createFromHostObject(rt, std::make_shared<MutableValueSetterProxy>(shared_from_this()));
43
+ runtimeManager->valueSetter->getValue(rt)
44
+ .asObject(rt)
45
+ .asFunction(rt)
46
+ .callWithThis(rt, setterProxy, newValue);
47
+ } else if (propName == "_animation") {
48
+ // TODO: assert to allow animation to be set from UI only
49
+ if (animation.expired()) {
50
+ animation = getWeakRef(rt);
51
+ }
52
+ *animation.lock() = jsi::Value(rt, newValue);
53
+ }
54
+ } else {
55
+ // React-JS Thread or another threaded Runtime.
37
56
  if (propName == "value") {
38
57
  auto shareable = ShareableValue::adapt(rt, newValue, runtimeManager);
39
58
  runtimeManager->scheduler->scheduleOnUI([this, shareable] {
@@ -46,23 +65,8 @@ void MutableValue::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi:
46
65
  .callWithThis(rt, setterProxy, newValue);
47
66
  });
48
67
  }
49
- return;
50
68
  }
51
69
 
52
- // UI thread
53
- if (propName == "value") {
54
- auto setterProxy = jsi::Object::createFromHostObject(rt, std::make_shared<MutableValueSetterProxy>(shared_from_this()));
55
- runtimeManager->valueSetter->getValue(rt)
56
- .asObject(rt)
57
- .asFunction(rt)
58
- .callWithThis(rt, setterProxy, newValue);
59
- } else if (propName == "_animation") {
60
- // TODO: assert to allow animation to be set from UI only
61
- if (animation.expired()) {
62
- animation = getWeakRef(rt);
63
- }
64
- *animation.lock() = jsi::Value(rt, newValue);
65
- }
66
70
  }
67
71
 
68
72
  jsi::Value MutableValue::get(jsi::Runtime &rt, const jsi::PropNameID &name) {
@@ -72,7 +76,7 @@ jsi::Value MutableValue::get(jsi::Runtime &rt, const jsi::PropNameID &name) {
72
76
  return getValue(rt);
73
77
  }
74
78
 
75
- if (RuntimeDecorator::isWorkletRuntime(rt)) {
79
+ if (RuntimeDecorator::isUIRuntime(rt)) {
76
80
  // _value and _animation should be accessed from UI only
77
81
  if (propName == "_value") {
78
82
  return getValue(rt);
@@ -327,7 +327,7 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
327
327
  auto runtimeManager = this->runtimeManager;
328
328
  auto& frozenObject = ValueWrapper::asFrozenObject(this->valueContainer);
329
329
  if (RuntimeDecorator::isWorkletRuntime(rt)) {
330
- // when running on UI thread we prep a function
330
+ // when running on worklet thread we prep a function
331
331
 
332
332
  auto jsThis = std::make_shared<jsi::Object>(frozenObject->shallowClone(*runtimeManager->runtime));
333
333
  std::shared_ptr<jsi::Function> funPtr(runtimeManager->workletsCache->getFunction(rt, frozenObject));
@@ -1,43 +1,56 @@
1
+ #ifdef ONANDROID
2
+ #include <AndroidScheduler.h>
3
+ #endif
1
4
  #include "JSIStoreValueUser.h"
2
5
 
3
6
  namespace reanimated {
4
7
 
5
- std::atomic<int> StoreUser::ctr;
6
- std::recursive_mutex StoreUser::storeMutex;
7
- std::unordered_map<int, std::vector<std::shared_ptr<jsi::Value>>> StoreUser::store;
8
+ std::shared_ptr<StaticStoreUser> StoreUser::staticStoreUserData = std::make_shared<StaticStoreUser>();
8
9
 
9
10
  std::weak_ptr<jsi::Value> StoreUser::getWeakRef(jsi::Runtime &rt) {
10
- const std::lock_guard<std::recursive_mutex> lock(storeMutex);
11
- if (StoreUser::store.count(identifier) == 0) {
12
- StoreUser::store[identifier] = std::vector<std::shared_ptr<jsi::Value>>();
11
+ const std::lock_guard<std::recursive_mutex> lock(storeUserData->storeMutex);
12
+ if (storeUserData->store.count(identifier) == 0) {
13
+ storeUserData->store[identifier] = std::vector<std::shared_ptr<jsi::Value>>();
13
14
  }
14
15
  std::shared_ptr<jsi::Value> sv = std::make_shared<jsi::Value>(rt, jsi::Value::undefined());
15
- StoreUser::store[identifier].push_back(sv);
16
+ storeUserData->store[identifier].push_back(sv);
16
17
 
17
18
  return sv;
18
19
  }
19
20
 
20
21
  StoreUser::StoreUser(std::shared_ptr<Scheduler> s): scheduler(s) {
21
- identifier = StoreUser::ctr++;
22
+ storeUserData = StoreUser::staticStoreUserData;
23
+ identifier = storeUserData->ctr++;
22
24
  }
23
25
 
24
26
  StoreUser::~StoreUser() {
25
27
  int id = identifier;
26
28
  std::shared_ptr<Scheduler> strongScheduler = scheduler.lock();
27
29
  if (strongScheduler != nullptr) {
28
- strongScheduler->scheduleOnUI([id]() {
29
- const std::lock_guard<std::recursive_mutex> lock(storeMutex);
30
- if (StoreUser::store.count(id) > 0) {
31
- StoreUser::store.erase(id);
30
+ std::shared_ptr<StaticStoreUser> sud = storeUserData;
31
+ #ifdef ONANDROID
32
+ jni::ThreadScope::WithClassLoader([&] {
33
+ strongScheduler->scheduleOnUI([id, sud]() {
34
+ const std::lock_guard<std::recursive_mutex> lock(sud->storeMutex);
35
+ if (sud->store.count(id) > 0) {
36
+ sud->store.erase(id);
37
+ }
38
+ });
39
+ });
40
+ #else
41
+ strongScheduler->scheduleOnUI([id, sud]() {
42
+ const std::lock_guard<std::recursive_mutex> lock(sud->storeMutex);
43
+ if (sud->store.count(id) > 0) {
44
+ sud->store.erase(id);
32
45
  }
33
46
  });
47
+ #endif
34
48
  }
35
49
  }
36
50
 
37
-
38
51
  void StoreUser::clearStore() {
39
- const std::lock_guard<std::recursive_mutex> lock(storeMutex);
40
- StoreUser::store.clear();
52
+ const std::lock_guard<std::recursive_mutex> lock(StoreUser::staticStoreUserData->storeMutex);
53
+ StoreUser::staticStoreUserData->store.clear();
41
54
  }
42
55
 
43
56
  }
@@ -10,7 +10,7 @@ void RuntimeDecorator::decorateRuntime(jsi::Runtime &rt, std::string label) {
10
10
  rt.global().setProperty(rt, "_WORKLET", jsi::Value(true));
11
11
  // This property will be used for debugging
12
12
  rt.global().setProperty(rt, "_LABEL", jsi::String::createFromAscii(rt, label));
13
-
13
+
14
14
  jsi::Object dummyGlobal(rt);
15
15
  auto dummyFunction = [](
16
16
  jsi::Runtime &rt,
@@ -21,12 +21,12 @@ void RuntimeDecorator::decorateRuntime(jsi::Runtime &rt, std::string label) {
21
21
  return jsi::Value::undefined();
22
22
  };
23
23
  jsi::Function __reanimatedWorkletInit = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "__reanimatedWorkletInit"), 1, dummyFunction);
24
-
24
+
25
25
  dummyGlobal.setProperty(rt, "__reanimatedWorkletInit", __reanimatedWorkletInit);
26
26
  rt.global().setProperty(rt, "global", dummyGlobal);
27
-
27
+
28
28
  rt.global().setProperty(rt, "jsThis", jsi::Value::undefined());
29
-
29
+
30
30
  auto callback = [](
31
31
  jsi::Runtime &rt,
32
32
  const jsi::Value &thisValue,
@@ -47,7 +47,7 @@ void RuntimeDecorator::decorateRuntime(jsi::Runtime &rt, std::string label) {
47
47
  };
48
48
  jsi::Value log = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_log"), 1, callback);
49
49
  rt.global().setProperty(rt, "_log", log);
50
-
50
+
51
51
  auto setGlobalConsole = [](
52
52
  jsi::Runtime &rt,
53
53
  const jsi::Value &thisValue,
@@ -67,7 +67,8 @@ void RuntimeDecorator::decorateUIRuntime(jsi::Runtime &rt,
67
67
  MeasuringFunction measure,
68
68
  TimeProviderFunction getCurrentTime) {
69
69
  RuntimeDecorator::decorateRuntime(rt, "UI");
70
-
70
+ rt.global().setProperty(rt, "_UI", jsi::Value(true));
71
+
71
72
  auto clb = [updater](
72
73
  jsi::Runtime &rt,
73
74
  const jsi::Value &thisValue,
@@ -82,8 +83,8 @@ void RuntimeDecorator::decorateUIRuntime(jsi::Runtime &rt,
82
83
  };
83
84
  jsi::Value updateProps = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_updateProps"), 2, clb);
84
85
  rt.global().setProperty(rt, "_updateProps", updateProps);
85
-
86
-
86
+
87
+
87
88
  auto clb2 = [requestFrame](
88
89
  jsi::Runtime &rt,
89
90
  const jsi::Value &thisValue,
@@ -98,7 +99,7 @@ void RuntimeDecorator::decorateUIRuntime(jsi::Runtime &rt,
98
99
  };
99
100
  jsi::Value requestAnimationFrame = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "requestAnimationFrame"), 1, clb2);
100
101
  rt.global().setProperty(rt, "requestAnimationFrame", requestAnimationFrame);
101
-
102
+
102
103
  auto clb3 = [scrollTo](
103
104
  jsi::Runtime &rt,
104
105
  const jsi::Value &thisValue,
@@ -114,7 +115,7 @@ void RuntimeDecorator::decorateUIRuntime(jsi::Runtime &rt,
114
115
  };
115
116
  jsi::Value scrollToFunction = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_scrollTo"), 4, clb3);
116
117
  rt.global().setProperty(rt, "_scrollTo", scrollToFunction);
117
-
118
+
118
119
  auto clb4 = [measure](
119
120
  jsi::Runtime &rt,
120
121
  const jsi::Value &thisValue,
@@ -131,7 +132,7 @@ void RuntimeDecorator::decorateUIRuntime(jsi::Runtime &rt,
131
132
  };
132
133
  jsi::Value measureFunction = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_measure"), 1, clb4);
133
134
  rt.global().setProperty(rt, "_measure", measureFunction);
134
-
135
+
135
136
  auto clb6 = [getCurrentTime](
136
137
  jsi::Runtime &rt,
137
138
  const jsi::Value &thisValue,
@@ -142,16 +143,21 @@ void RuntimeDecorator::decorateUIRuntime(jsi::Runtime &rt,
142
143
  };
143
144
  jsi::Value timeFun = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_getCurrentTime"), 0, clb6);
144
145
  rt.global().setProperty(rt, "_getCurrentTime", timeFun);
145
-
146
+
146
147
  rt.global().setProperty(rt, "_frameTimestamp", jsi::Value::undefined());
147
148
  rt.global().setProperty(rt, "_eventTimestamp", jsi::Value::undefined());
148
149
  }
149
150
 
150
- bool RuntimeDecorator::isWorkletRuntime(jsi::Runtime& rt) {
151
- auto isUi = rt.global().getProperty(rt, "_WORKLET");
151
+ bool RuntimeDecorator::isUIRuntime(jsi::Runtime& rt) {
152
+ auto isUi = rt.global().getProperty(rt, "_UI");
152
153
  return isUi.isBool() && isUi.getBool();
153
154
  }
154
155
 
156
+ bool RuntimeDecorator::isWorkletRuntime(jsi::Runtime& rt) {
157
+ auto isWorklet = rt.global().getProperty(rt, "_WORKLET");
158
+ return isWorklet.isBool() && isWorklet.getBool();
159
+ }
160
+
155
161
  bool RuntimeDecorator::isReactRuntime(jsi::Runtime& rt) {
156
162
  return !isWorkletRuntime(rt);
157
163
  }
@@ -13,11 +13,16 @@ using namespace facebook;
13
13
 
14
14
  namespace reanimated {
15
15
 
16
+ struct StaticStoreUser {
17
+ std::atomic<int> ctr;
18
+ std::unordered_map<int, std::vector<std::shared_ptr<jsi::Value>>> store;
19
+ std::recursive_mutex storeMutex;
20
+ };
21
+
16
22
  class StoreUser {
17
23
  int identifier = 0;
18
- static std::atomic<int> ctr;
19
- static std::unordered_map<int, std::vector<std::shared_ptr<jsi::Value>>> store;
20
- static std::recursive_mutex storeMutex;
24
+ static std::shared_ptr<StaticStoreUser> staticStoreUserData;
25
+ std::shared_ptr<StaticStoreUser> storeUserData;
21
26
  std::weak_ptr<Scheduler> scheduler;
22
27
 
23
28
  public:
@@ -20,7 +20,17 @@ public:
20
20
  MeasuringFunction measure,
21
21
  TimeProviderFunction getCurrentTime);
22
22
 
23
+ /**
24
+ Returns true if the given Runtime is the Reanimated UI-Thread Runtime.
25
+ */
26
+ static bool isUIRuntime(jsi::Runtime &rt);
27
+ /**
28
+ Returns true if the given Runtime is a Runtime that supports Workletization. (REA, Vision, ...)
29
+ */
23
30
  static bool isWorkletRuntime(jsi::Runtime &rt);
31
+ /**
32
+ Returns true if the given Runtime is the default React-JS Runtime.
33
+ */
24
34
  static bool isReactRuntime(jsi::Runtime &rt);
25
35
  };
26
36
 
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
- <p align="center">
2
- <h1 align="center">React Native Reanimated</h1>
3
- <h3 align="center">React Native's Animated library reimplemented</h3>
4
- </p>
1
+ <img src="https://user-images.githubusercontent.com/16062886/117443145-ff868480-af37-11eb-8680-648bccf0d0ce.png" alt="React Native Reanimated by Software Mansion" width="100%">
2
+
3
+ ### React Native's Animated library reimplemented
5
4
 
6
5
  > Reanimated 2 is here! Check out our [documentation page](https://docs.swmansion.com/react-native-reanimated/) for more information
7
6
 
@@ -5,9 +5,10 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
5
5
  reactVersion = '0.0.0'
6
6
 
7
7
  begin
8
- reactVersion = JSON.parse(File.read(File.join(__dir__, "..", "react-native", "package.json")))["version"]
8
+ reactVersion = JSON.parse(File.read(File.join(__dir__, "..", "..", "node_modules", "react-native", "package.json")))["version"]
9
9
  rescue
10
- reactVersion = '0.64.0'
10
+ # Example app
11
+ reactVersion = JSON.parse(File.read(File.join(__dir__, "node_modules", "react-native", "package.json")))["version"]
11
12
  end
12
13
 
13
14
  rnVersion = reactVersion.split('.')[1]
@@ -20,7 +21,7 @@ end
20
21
 
21
22
  folly_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DRNVERSION=' + rnVersion
22
23
  folly_compiler_flags = folly_flags + ' ' + '-Wno-comma -Wno-shorten-64-to-32'
23
- folly_version = '2020.01.13.00'
24
+ folly_version = '2021.04.26.00'
24
25
  boost_compiler_flags = '-Wno-documentation'
25
26
 
26
27
  Pod::Spec.new do |s|
@@ -49,12 +50,12 @@ Pod::Spec.new do |s|
49
50
 
50
51
  s.pod_target_xcconfig = {
51
52
  "USE_HEADERMAP" => "YES",
52
- "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/#{folly_prefix}Folly\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\" "
53
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/#{folly_prefix}Folly\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\" "
53
54
  }
54
55
  s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
55
56
  s.xcconfig = {
56
57
  "CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
57
- "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/#{folly_prefix}Folly\"",
58
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/#{folly_prefix}Folly\" \"${PODS_ROOT}/Headers/Public/React-hermes\" \"${PODS_ROOT}/Headers/Public/hermes-engine\"",
58
59
  "OTHER_CFLAGS" => "$(inherited)" + " " + folly_flags }
59
60
 
60
61
  s.requires_arc = true
@@ -95,4 +96,3 @@ Pod::Spec.new do |s|
95
96
  s.dependency "#{folly_prefix}Folly"
96
97
 
97
98
  end
98
-
@@ -1,4 +1,6 @@
1
- import groovy.json.JsonSlurper;
1
+ import groovy.json.JsonSlurper
2
+ import java.util.regex.Matcher
3
+ import java.util.regex.Pattern
2
4
  configurations.maybeCreate("default")
3
5
 
4
6
  def inputFile = new File(projectDir, '../../react-native/package.json')
@@ -6,4 +8,78 @@ def json = new JsonSlurper().parseText(inputFile.text)
6
8
  def reactNativeVersion = json.version as String
7
9
  def (major, minor, patch) = reactNativeVersion.tokenize('.')
8
10
 
9
- artifacts.add("default", file("react-native-reanimated-${minor}.aar"))
11
+ def engine = "jsc"
12
+
13
+ abstract class replaceSoTask extends DefaultTask {
14
+ public static String appName = ":app"
15
+ public static String buildDir = "../../../android/app/build"
16
+
17
+ @TaskAction
18
+ def run() {
19
+ for(def abiVersion in ["x86", "x86_64", "armeabi-v7a", "arm64-v8a"]) {
20
+ ant.sequential {
21
+ copy(
22
+ tofile: "${buildDir}/intermediates/merged_native_libs/debug/out/lib/${abiVersion}/libfbjni.so",
23
+ file: "../libSo/fbjni/jni/${abiVersion}/libfbjni.so",
24
+ overwrite: true
25
+ )
26
+ }
27
+ }
28
+ }
29
+ }
30
+
31
+ def getCurrentFlavor() {
32
+ Gradle gradle = getGradle()
33
+ String taskRequestName = gradle.getStartParameter().getTaskRequests().toString()
34
+ Pattern pattern = Pattern.compile("(assemble|install|generate)(\\w+)(Release|Debug)")
35
+ Matcher matcher = pattern.matcher(taskRequestName)
36
+
37
+ if(matcher.find()) {
38
+ return matcher.group(2)
39
+ }
40
+
41
+ return ""
42
+ }
43
+
44
+ def replaceSoTaskDebug
45
+ def replaceSoTaskRelease
46
+ if(Integer.parseInt(minor) < 65) {
47
+ tasks.register("replaceSoTaskDebug", replaceSoTask)
48
+ tasks.register("replaceSoTaskRelease", replaceSoTask)
49
+ replaceSoTaskDebug = project.getTasks().getByPath(":react-native-reanimated:replaceSoTaskDebug")
50
+ replaceSoTaskRelease = project.getTasks().getByPath(":react-native-reanimated:replaceSoTaskRelease")
51
+ }
52
+
53
+ rootProject.getSubprojects().forEach({project ->
54
+ if (project.plugins.hasPlugin("com.android.application")) {
55
+ if(project.ext.react.enableHermes) {
56
+ engine = "hermes"
57
+ }
58
+
59
+ if(project.getProperties().get("android") && Integer.parseInt(minor) < 65) {
60
+ def projectProperties = project.getProperties()
61
+ if(!projectProperties.get("reanimated")
62
+ || (projectProperties.get("reanimated") && projectProperties.get("reanimated").get("enablePackagingOptions"))
63
+ ) {
64
+ def flavorString = getCurrentFlavor()
65
+ replaceSoTask.appName = project.getProperties().path
66
+ replaceSoTask.buildDir = project.getProperties().buildDir
67
+ def appName = project.getProperties().path
68
+
69
+ replaceSoTaskDebug.dependsOn(
70
+ project.getTasks().getByPath("${appName}:merge${flavorString}DebugNativeLibs"),
71
+ project.getTasks().getByPath("${appName}:strip${flavorString}DebugDebugSymbols")
72
+ )
73
+ project.getTasks().getByPath("${appName}:package${flavorString}Debug").dependsOn(replaceSoTaskDebug)
74
+
75
+ replaceSoTaskRelease.dependsOn(
76
+ project.getTasks().getByPath("${appName}:merge${flavorString}ReleaseNativeLibs"),
77
+ project.getTasks().getByPath("${appName}:strip${flavorString}ReleaseDebugSymbols")
78
+ )
79
+ project.getTasks().getByPath("${appName}:package${flavorString}Release").dependsOn(replaceSoTaskRelease)
80
+ }
81
+ }
82
+ }
83
+ })
84
+
85
+ artifacts.add("default", file("react-native-reanimated-${minor}-${engine}.aar"))
@@ -481,6 +481,9 @@
481
481
  if (strongSelf == nil) {
482
482
  return;
483
483
  }
484
+ if (eventHandler == nil) {
485
+ return;
486
+ }
484
487
  eventHandler(eventHash, event);
485
488
  if ([strongSelf isDirectEvent:event]) {
486
489
  [strongSelf performOperations];
@@ -10,7 +10,7 @@ std::vector<std::pair<std::string,double>> measure(int viewTag, RCTUIManager *ui
10
10
  UIView *rootView = view;
11
11
 
12
12
  if (view == nil) {
13
- return std::vector<std::pair<std::string, double>>(0, std::make_pair("x", -1234567.0));
13
+ return std::vector<std::pair<std::string, double>>(1, std::make_pair("x", -1234567.0));
14
14
  }
15
15
 
16
16
  while (rootView.superview && ![rootView isReactRootView]) {
@@ -18,7 +18,7 @@ std::vector<std::pair<std::string,double>> measure(int viewTag, RCTUIManager *ui
18
18
  }
19
19
 
20
20
  if (rootView == nil || (![rootView isReactRootView])) {
21
- return std::vector<std::pair<std::string, double>>(0, std::make_pair("x", -1234567.0));
21
+ return std::vector<std::pair<std::string, double>>(1, std::make_pair("x", -1234567.0));
22
22
  }
23
23
 
24
24
  CGRect frame = view.frame;
@@ -8,7 +8,9 @@
8
8
  #import <React/RCTFollyConvert.h>
9
9
  #import <React/RCTUIManager.h>
10
10
 
11
- #if __has_include(<hermes/hermes.h>)
11
+ #if __has_include(<reacthermes/HermesExecutorFactory.h>)
12
+ #import <reacthermes/HermesExecutorFactory.h>
13
+ #elif __has_include(<hermes/hermes.h>)
12
14
  #import <hermes/hermes.h>
13
15
  #else
14
16
  #import <jsi/JSCRuntime.h>
@@ -111,7 +113,9 @@ std::shared_ptr<NativeReanimatedModule> createReanimatedModule(std::shared_ptr<C
111
113
  };
112
114
 
113
115
 
114
- #if __has_include(<hermes/hermes.h>)
116
+ #if __has_include(<reacthermes/HermesExecutorFactory.h>)
117
+ std::unique_ptr<jsi::Runtime> animatedRuntime = facebook::hermes::makeHermesRuntime();
118
+ #elif __has_include(<hermes/hermes.h>)
115
119
  std::unique_ptr<jsi::Runtime> animatedRuntime = facebook::hermes::makeHermesRuntime();
116
120
  #else
117
121
  std::unique_ptr<jsi::Runtime> animatedRuntime = facebook::jsc::makeJSCRuntime();
@@ -0,0 +1,32 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <React/RCTCxxBridgeDelegate.h>
3
+ #import <RNReanimated/NativeProxy.h>
4
+ #import <RNReanimated/REAModule.h>
5
+ #import <ReactCommon/RCTTurboModuleManager.h>
6
+ #import <React/RCTBridge+Private.h>
7
+ #import <React/RCTCxxBridgeDelegate.h>
8
+ #import <RNReanimated/REAEventDispatcher.h>
9
+ #import <jsireact/JSIExecutor.h>
10
+
11
+ #if RNVERSION >= 64
12
+ #import <React/RCTJSIExecutorRuntimeInstaller.h>
13
+ #endif
14
+
15
+ #if RNVERSION < 63
16
+ #import <ReactCommon/BridgeJSCallInvoker.h>
17
+ #endif
18
+
19
+ NS_ASSUME_NONNULL_BEGIN
20
+
21
+ namespace reanimated {
22
+
23
+ using namespace facebook;
24
+ using namespace react;
25
+
26
+ JSIExecutor::RuntimeInstaller REAJSIExecutorRuntimeInstaller(
27
+ RCTBridge* bridge,
28
+ JSIExecutor::RuntimeInstaller runtimeInstallerToWrap
29
+ );
30
+
31
+ }
32
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,54 @@
1
+ #import "REAInitializer.h"
2
+
3
+ @interface RCTEventDispatcher(Reanimated)
4
+
5
+ - (void)setBridge:(RCTBridge*)bridge;
6
+
7
+ @end
8
+
9
+ namespace reanimated {
10
+
11
+ using namespace facebook;
12
+ using namespace react;
13
+
14
+ JSIExecutor::RuntimeInstaller REAJSIExecutorRuntimeInstaller(
15
+ RCTBridge* bridge,
16
+ JSIExecutor::RuntimeInstaller runtimeInstallerToWrap)
17
+ {
18
+ [bridge moduleForClass:[RCTEventDispatcher class]];
19
+ RCTEventDispatcher *eventDispatcher = [REAEventDispatcher new];
20
+ #if RNVERSION >= 66
21
+ RCTCallableJSModules *callableJSModules = [RCTCallableJSModules new];
22
+ [bridge setValue:callableJSModules forKey:@"_callableJSModules"];
23
+ [callableJSModules setBridge:bridge];
24
+ [eventDispatcher setValue:callableJSModules forKey:@"_callableJSModules"];
25
+ [eventDispatcher setValue:bridge forKey:@"_bridge"];
26
+ [eventDispatcher initialize];
27
+ #else
28
+ [eventDispatcher setBridge:bridge];
29
+ #endif
30
+ [bridge updateModuleWithInstance:eventDispatcher];
31
+ _bridge_reanimated = bridge;
32
+ const auto runtimeInstaller = [bridge, runtimeInstallerToWrap](facebook::jsi::Runtime &runtime) {
33
+ if (!bridge) {
34
+ return;
35
+ }
36
+ #if RNVERSION >= 63
37
+ auto reanimatedModule = reanimated::createReanimatedModule(bridge.jsCallInvoker);
38
+ #else
39
+ auto callInvoker = std::make_shared<react::BridgeJSCallInvoker>(bridge.reactInstance);
40
+ auto reanimatedModule = reanimated::createReanimatedModule(callInvoker);
41
+ #endif
42
+ runtime.global().setProperty(runtime,
43
+ jsi::PropNameID::forAscii(runtime, "__reanimatedModuleProxy"),
44
+ jsi::Object::createFromHostObject(runtime, reanimatedModule));
45
+
46
+ if (runtimeInstallerToWrap) {
47
+ runtimeInstallerToWrap(runtime);
48
+ }
49
+ };
50
+ return runtimeInstaller;
51
+ }
52
+
53
+
54
+ }