react-native-reanimated 2.8.0 → 2.9.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.
Files changed (79) hide show
  1. package/Common/cpp/Tools/RuntimeDecorator.cpp +17 -11
  2. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  3. package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
  4. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  5. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
  6. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  7. package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
  8. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  9. package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
  10. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  11. package/android/.gradle/checksums/checksums.lock +0 -0
  12. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  13. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  14. package/android/CMakeLists.txt +19 -8
  15. package/android/build.gradle +22 -8
  16. package/android/react-native-reanimated-65-hermes.aar +0 -0
  17. package/android/react-native-reanimated-65-jsc.aar +0 -0
  18. package/android/react-native-reanimated-66-hermes.aar +0 -0
  19. package/android/react-native-reanimated-66-jsc.aar +0 -0
  20. package/android/react-native-reanimated-67-hermes.aar +0 -0
  21. package/android/react-native-reanimated-67-jsc.aar +0 -0
  22. package/android/react-native-reanimated-68-hermes.aar +0 -0
  23. package/android/react-native-reanimated-68-jsc.aar +0 -0
  24. package/android/react-native-reanimated-69-hermes.aar +0 -0
  25. package/android/react-native-reanimated-69-jsc.aar +0 -0
  26. package/android/rnVersionPatch/69/.gitkeep +0 -0
  27. package/android/src/main/cpp/NativeProxy.cpp +13 -2
  28. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +24 -1
  29. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +7 -5
  30. package/ios/native/REAInitializer.mm +11 -1
  31. package/ios/sensor/ReanimatedSensor.m +2 -2
  32. package/lib/Animated.js +8 -21
  33. package/lib/index.js +5 -21
  34. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +1 -1
  35. package/lib/reanimated2/animation/sequence.js +0 -3
  36. package/lib/reanimated2/component/FlatList.js +3 -3
  37. package/lib/reanimated2/component/Image.js +4 -0
  38. package/lib/reanimated2/component/ScrollView.js +4 -0
  39. package/lib/reanimated2/component/Text.js +4 -0
  40. package/lib/reanimated2/component/View.js +4 -0
  41. package/lib/reanimated2/core.js +0 -5
  42. package/lib/reanimated2/hook/utils.js +0 -5
  43. package/lib/reanimated2/js-reanimated/global.js +25 -0
  44. package/lib/reanimated2/js-reanimated/index.js +0 -24
  45. package/lib/reanimated2/mock.js +6 -0
  46. package/lib/types/lib/Animated.d.ts +8 -0
  47. package/lib/types/lib/index.d.ts +4 -0
  48. package/lib/types/lib/reanimated2/component/Image.d.ts +3 -0
  49. package/lib/types/lib/reanimated2/component/ScrollView.d.ts +3 -0
  50. package/lib/types/lib/reanimated2/component/Text.d.ts +3 -0
  51. package/lib/types/lib/reanimated2/component/View.d.ts +3 -0
  52. package/lib/types/lib/reanimated2/js-reanimated/global.d.ts +1 -0
  53. package/lib/types/lib/reanimated2/mock.d.ts +6 -0
  54. package/package.json +15 -9
  55. package/plugin.js +11 -1
  56. package/react-native-reanimated.d.ts +1 -4
  57. package/src/Animated.ts +13 -0
  58. package/src/index.ts +7 -0
  59. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +1 -1
  60. package/src/reanimated2/animation/sequence.ts +0 -5
  61. package/src/reanimated2/component/FlatList.tsx +3 -6
  62. package/src/reanimated2/component/Image.ts +6 -0
  63. package/src/reanimated2/component/ScrollView.ts +6 -0
  64. package/src/reanimated2/component/Text.ts +6 -0
  65. package/src/reanimated2/component/View.ts +6 -0
  66. package/src/reanimated2/core.ts +0 -5
  67. package/src/reanimated2/hook/utils.ts +0 -6
  68. package/src/reanimated2/js-reanimated/global.ts +33 -0
  69. package/src/reanimated2/js-reanimated/index.ts +0 -31
  70. package/src/reanimated2/mock.ts +6 -0
  71. package/android/react-native-reanimated-64-hermes.aar +0 -0
  72. package/android/react-native-reanimated-64-jsc.aar +0 -0
  73. package/lib/reanimated2/component/WrappedComponents.js +0 -9
  74. package/lib/reanimated2/component/index.js +0 -4
  75. package/lib/types/lib/reanimated2/component/WrappedComponents.d.ts +0 -8
  76. package/lib/types/lib/reanimated2/component/index.d.ts +0 -9
  77. package/src/Animated.js +0 -22
  78. package/src/reanimated2/component/WrappedComponents.ts +0 -11
  79. package/src/reanimated2/component/index.ts +0 -9
@@ -71,21 +71,27 @@ void RuntimeDecorator::decorateRuntime(
71
71
  1,
72
72
  setGlobalConsole));
73
73
 
74
+ auto chronoNow = [](jsi::Runtime &rt,
75
+ const jsi::Value &thisValue,
76
+ const jsi::Value *args,
77
+ size_t count) -> jsi::Value {
78
+ double now = std::chrono::system_clock::now().time_since_epoch() /
79
+ std::chrono::milliseconds(1);
80
+ return jsi::Value(now);
81
+ };
82
+
74
83
  rt.global().setProperty(
75
84
  rt,
76
85
  "_chronoNow",
77
86
  jsi::Function::createFromHostFunction(
78
- rt,
79
- jsi::PropNameID::forAscii(rt, "_chronoNow"),
80
- 0,
81
- [](jsi::Runtime &rt,
82
- const jsi::Value &thisValue,
83
- const jsi::Value *args,
84
- size_t count) -> jsi::Value {
85
- double now = std::chrono::system_clock::now().time_since_epoch() /
86
- std::chrono::milliseconds(1);
87
- return jsi::Value(now);
88
- }));
87
+ rt, jsi::PropNameID::forAscii(rt, "_chronoNow"), 0, chronoNow));
88
+ jsi::Object performance(rt);
89
+ performance.setProperty(
90
+ rt,
91
+ "now",
92
+ jsi::Function::createFromHostFunction(
93
+ rt, jsi::PropNameID::forAscii(rt, "now"), 0, chronoNow));
94
+ rt.global().setProperty(rt, "performance", performance);
89
95
  }
90
96
 
91
97
  void RuntimeDecorator::decorateUIRuntime(
@@ -1,2 +1,2 @@
1
- #Thu Apr 21 15:44:53 UTC 2022
1
+ #Thu Jun 30 13:53:38 UTC 2022
2
2
  gradle.version=7.2
@@ -119,12 +119,23 @@ find_library(
119
119
  PATHS ${LIBRN_DIR}
120
120
  NO_CMAKE_FIND_ROOT_PATH
121
121
  )
122
- find_library(
123
- FOLLY_JSON_LIB
124
- folly_json
125
- PATHS ${LIBRN_DIR}
126
- NO_CMAKE_FIND_ROOT_PATH
127
- )
122
+
123
+ if(${REACT_NATIVE_TARGET_VERSION} LESS 69)
124
+ find_library(
125
+ FOLLY_LIB
126
+ folly_json
127
+ PATHS ${LIBRN_DIR}
128
+ NO_CMAKE_FIND_ROOT_PATH
129
+ )
130
+ else()
131
+ find_library(
132
+ FOLLY_LIB
133
+ folly_runtime
134
+ PATHS ${LIBRN_DIR}
135
+ NO_CMAKE_FIND_ROOT_PATH
136
+ )
137
+ endif()
138
+
128
139
  find_library(
129
140
  REACT_NATIVE_JNI_LIB
130
141
  reactnativejni
@@ -169,7 +180,7 @@ if(${FOR_HERMES})
169
180
  ${HERMES_LIB}
170
181
  ${GLOG_LIB}
171
182
  ${FBJNI_LIB}
172
- ${FOLLY_JSON_LIB}
183
+ ${FOLLY_LIB}
173
184
  ${REACT_NATIVE_JNI_LIB}
174
185
  android
175
186
  )
@@ -181,7 +192,7 @@ else()
181
192
  ${JSEXECUTOR_LIB}
182
193
  ${GLOG_LIB}
183
194
  ${FBJNI_LIB}
184
- ${FOLLY_JSON_LIB}
195
+ ${FOLLY_LIB}
185
196
  ${REACT_NATIVE_JNI_LIB}
186
197
  android
187
198
  )
@@ -149,10 +149,10 @@ def detectAAR(minor, engine) {
149
149
  println "\n\n\n"
150
150
  println "****************************************************************************************"
151
151
  println "\n\n\n"
152
- println "WARNING reanimated - no version-specific reanimated AAR for react-native version $rnMinorVersion found."
152
+ println "WARNING reanimated - no version-specific reanimated AAR for react-native version $minor found."
153
153
  println "Falling back to AAR for react-native version $rnMinorVersionCopy."
154
154
  println "The react-native JSI interface is not ABI-safe yet, this may result in crashes."
155
- println "Please post a pull request to implement support for react-native version $rnMinorVersion to the reanimated repo."
155
+ println "Please post a pull request to implement support for react-native version $minor to the reanimated repo."
156
156
  println "Thanks!"
157
157
  println "\n\n\n"
158
158
  println "****************************************************************************************"
@@ -351,8 +351,8 @@ buildscript {
351
351
  }
352
352
  }
353
353
  dependencies {
354
- classpath "com.android.tools.build:gradle:4.2.2"
355
- classpath "de.undercouch:gradle-download-task:4.1.2"
354
+ classpath "com.android.tools.build:gradle:7.1.1"
355
+ classpath "de.undercouch:gradle-download-task:5.0.1"
356
356
  classpath "com.diffplug.spotless:spotless-plugin-gradle:5.15.0"
357
357
  }
358
358
  }
@@ -381,8 +381,7 @@ android {
381
381
  "-DBOOST_VERSION=${BOOST_VERSION}",
382
382
  "-DBUILD_DIR=${buildDir}",
383
383
  "-DFOR_HERMES=${FOR_HERMES}",
384
- "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
385
- "--clean-first"
384
+ "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}"
386
385
  abiFilters (*reactNativeArchitectures())
387
386
  _stackProtectorFlag ? (cppFlags("-fstack-protector-all")) : null
388
387
  }
@@ -459,7 +458,12 @@ task createNativeDepsDirectories(dependsOn: applyJavaPatches) {
459
458
  }
460
459
 
461
460
  task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
462
- src("https://github.com/react-native-community/boost-for-react-native/releases/download/v${BOOST_VERSION.replace("_", ".")}-0/boost_${BOOST_VERSION}.tar.gz")
461
+ def transformedVersion = BOOST_VERSION.replace("_", ".")
462
+ def srcUrl = "https://boostorg.jfrog.io/artifactory/main/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
463
+ if (rnMinorVersion < 69) {
464
+ srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/boost_${BOOST_VERSION}.tar.gz"
465
+ }
466
+ src(srcUrl)
463
467
  onlyIfNewer(true)
464
468
  overwrite(false)
465
469
  dest(new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz"))
@@ -672,7 +676,17 @@ dependencies {
672
676
  extractHeaders("com.facebook.fbjni:fbjni:" + FBJNI_VERSION + ":headers")
673
677
  extractSO("com.facebook.fbjni:fbjni:" + FBJNI_VERSION)
674
678
 
675
- def rnAAR = fileTree("$reactNative/android").matching({ it.include "**/**/*.aar" }).singleFile
679
+ def buildType = "debug"
680
+ tasks.all({ task ->
681
+ if (task.name == "buildCMakeRelease") {
682
+ buildType = "release"
683
+ }
684
+ })
685
+ def rnAarMatcher = "**/react-native/**/*${buildType}.aar"
686
+ if (rnMinorVersion < 69) {
687
+ rnAarMatcher = "**/**/*.aar"
688
+ }
689
+ def rnAAR = fileTree("$reactNative/android").matching({ it.include rnAarMatcher }).singleFile
676
690
  def jscAAR = fileTree("$reactNative/../jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
677
691
  extractSO(files(rnAAR, jscAAR))
678
692
  }
File without changes
@@ -145,11 +145,22 @@ void NativeProxy::installJSIBindings() {
145
145
  std::shared_ptr<jsi::Runtime> animatedRuntime =
146
146
  facebook::jsc::makeJSCRuntime();
147
147
  #endif
148
+ auto workletRuntimeValue = runtime_->global()
149
+ .getProperty(*runtime_, "ArrayBuffer")
150
+ .asObject(*runtime_)
151
+ .asFunction(*runtime_)
152
+ .callAsConstructor(*runtime_, {static_cast<double>(sizeof(void*))});
153
+ uintptr_t* workletRuntimeData = reinterpret_cast<uintptr_t*>(
154
+ workletRuntimeValue
155
+ .getObject(*runtime_)
156
+ .getArrayBuffer(*runtime_)
157
+ .data(*runtime_));
158
+ workletRuntimeData[0] = reinterpret_cast<uintptr_t>(animatedRuntime.get());
159
+
148
160
  runtime_->global().setProperty(
149
161
  *runtime_,
150
162
  "_WORKLET_RUNTIME",
151
- static_cast<double>(
152
- reinterpret_cast<std::uintptr_t>(animatedRuntime.get())));
163
+ workletRuntimeValue);
153
164
 
154
165
  std::shared_ptr<ErrorHandler> errorHandler =
155
166
  std::make_shared<AndroidErrorHandler>(scheduler_);
@@ -3,6 +3,7 @@ package com.swmansion.reanimated.sensor;
3
3
  import android.hardware.Sensor;
4
4
  import android.hardware.SensorEvent;
5
5
  import android.hardware.SensorEventListener;
6
+ import android.hardware.SensorManager;
6
7
  import com.swmansion.reanimated.NativeProxy;
7
8
 
8
9
  public class ReanimatedSensorListener implements SensorEventListener {
@@ -11,6 +12,10 @@ public class ReanimatedSensorListener implements SensorEventListener {
11
12
  private double lastRead = (double) System.currentTimeMillis();
12
13
  private final double interval;
13
14
 
15
+ private float[] rotation = new float[9];
16
+ private float[] orientation = new float[3];
17
+ private float[] quaternion = new float[4];
18
+
14
19
  ReanimatedSensorListener(NativeProxy.SensorSetter setter, double interval) {
15
20
  this.setter = setter;
16
21
  this.interval = interval;
@@ -22,8 +27,26 @@ public class ReanimatedSensorListener implements SensorEventListener {
22
27
  if (current - lastRead < interval) {
23
28
  return;
24
29
  }
30
+ int sensorType = event.sensor.getType();
25
31
  lastRead = current;
26
- setter.sensorSetter(event.values);
32
+ if (sensorType == Sensor.TYPE_ROTATION_VECTOR) {
33
+ SensorManager.getQuaternionFromVector(quaternion, event.values);
34
+ SensorManager.getRotationMatrixFromVector(rotation, event.values);
35
+ SensorManager.getOrientation(rotation, orientation);
36
+ float[] data =
37
+ new float[] {
38
+ quaternion[1], // qx
39
+ quaternion[2], // qy
40
+ quaternion[3], // qz
41
+ quaternion[0], // qw
42
+ orientation[0], // yaw
43
+ orientation[1], // pitch
44
+ orientation[2] // roll
45
+ };
46
+ setter.sensorSetter(data);
47
+ } else {
48
+ setter.sensorSetter(event.values);
49
+ }
27
50
  }
28
51
 
29
52
  @Override
@@ -1,11 +1,13 @@
1
1
  package com.swmansion.reanimated.sensor;
2
2
 
3
+ import android.hardware.Sensor;
4
+
3
5
  public enum ReanimatedSensorType {
4
- ACCELEROMETER(1),
5
- GYROSCOPE(2),
6
- GRAVITY(3),
7
- MAGNETIC_FIELD(4),
8
- ROTATION_VECTOR(5);
6
+ ACCELEROMETER(Sensor.TYPE_ACCELEROMETER),
7
+ GYROSCOPE(Sensor.TYPE_GYROSCOPE),
8
+ GRAVITY(Sensor.TYPE_GRAVITY),
9
+ MAGNETIC_FIELD(Sensor.TYPE_MAGNETIC_FIELD),
10
+ ROTATION_VECTOR(Sensor.TYPE_ROTATION_VECTOR);
9
11
 
10
12
  private final int type;
11
13
 
@@ -45,10 +45,20 @@ JSIExecutor::RuntimeInstaller REAJSIExecutorRuntimeInstaller(
45
45
  auto callInvoker = std::make_shared<react::BridgeJSCallInvoker>(bridge.reactInstance);
46
46
  auto reanimatedModule = reanimated::createReanimatedModule(bridge, callInvoker);
47
47
  #endif
48
+ auto workletRuntimeValue = runtime
49
+ .global()
50
+ .getProperty(runtime, "ArrayBuffer")
51
+ .asObject(runtime)
52
+ .asFunction(runtime)
53
+ .callAsConstructor(runtime, {static_cast<double>(sizeof(void*))});
54
+ uintptr_t* workletRuntimeData = reinterpret_cast<uintptr_t*>(
55
+ workletRuntimeValue.getObject(runtime).getArrayBuffer(runtime).data(runtime));
56
+ workletRuntimeData[0] = reinterpret_cast<uintptr_t>(reanimatedModule->runtime.get());
57
+
48
58
  runtime.global().setProperty(
49
59
  runtime,
50
60
  "_WORKLET_RUNTIME",
51
- static_cast<double>(reinterpret_cast<std::uintptr_t>(reanimatedModule->runtime.get())));
61
+ workletRuntimeValue);
52
62
 
53
63
  runtime.global().setProperty(
54
64
  runtime,
@@ -141,9 +141,9 @@
141
141
  attitude.quaternion.y,
142
142
  attitude.quaternion.z,
143
143
  attitude.quaternion.w,
144
- attitude.pitch,
145
- attitude.roll,
146
144
  attitude.yaw,
145
+ attitude.pitch,
146
+ attitude.roll
147
147
  };
148
148
  self->_setter(data);
149
149
  self->_lastTimestamp = currentTime;
package/lib/Animated.js CHANGED
@@ -1,22 +1,9 @@
1
- import createAnimatedComponent from './createAnimatedComponent';
2
- import {
3
- addWhitelistedNativeProps,
4
- addWhitelistedUIProps,
5
- } from './ConfigHelper';
6
- import * as reanimated1 from './reanimated1';
7
- import ReanimatedComponents from './reanimated2/component';
8
-
9
- const Animated = {
10
- // components
11
- ...ReanimatedComponents,
12
- createAnimatedComponent,
13
- // configuration
14
- addWhitelistedNativeProps,
15
- addWhitelistedUIProps,
16
- // reanimated 1
17
- ...reanimated1,
18
- };
19
-
20
- export * from './reanimated2';
1
+ export { default as createAnimatedComponent } from './createAnimatedComponent';
2
+ export { addWhitelistedNativeProps, addWhitelistedUIProps, } from './ConfigHelper';
3
+ export { default as Text } from './reanimated2/component/Text';
4
+ export { default as View } from './reanimated2/component/View';
5
+ export { default as ScrollView } from './reanimated2/component/ScrollView';
6
+ export { default as Image } from './reanimated2/component/Image';
7
+ export { default as FlatList } from './reanimated2/component/FlatList';
8
+ // @ts-ignore backward compatibility with treeshaking
21
9
  export * from './reanimated1';
22
- export default Animated;
package/lib/index.js CHANGED
@@ -1,22 +1,6 @@
1
- import createAnimatedComponent from './createAnimatedComponent';
2
- import {
3
- addWhitelistedNativeProps,
4
- addWhitelistedUIProps,
5
- } from './ConfigHelper';
6
- import * as reanimated1 from './reanimated1';
7
- import ReanimatedComponents from './reanimated2/component';
8
-
9
- const Animated = {
10
- // components
11
- ...ReanimatedComponents,
12
- createAnimatedComponent,
13
- // configuration
14
- addWhitelistedNativeProps,
15
- addWhitelistedUIProps,
16
- // reanimated 1
17
- ...reanimated1,
18
- };
19
-
20
- export * from './reanimated2';
1
+ // tree-shaken side effects
2
+ import './reanimated2/js-reanimated/global';
3
+ // @ts-ignore backward compatibility with treeshaking
21
4
  export * from './reanimated1';
22
- export default Animated;
5
+ export * from './reanimated2';
6
+ export * as default from './Animated';
@@ -1,7 +1,7 @@
1
1
  import { NativeModules } from 'react-native';
2
2
  export class NativeReanimated {
3
3
  constructor(native = true) {
4
- if (global.__reanimatedModuleProxy === undefined) {
4
+ if (global.__reanimatedModuleProxy === undefined && native) {
5
5
  const { ReanimatedModule } = NativeModules;
6
6
  ReanimatedModule === null || ReanimatedModule === void 0 ? void 0 : ReanimatedModule.installTurboModule();
7
7
  }
@@ -43,9 +43,6 @@ export function withSequence(..._animations) {
43
43
  return false;
44
44
  }
45
45
  function onStart(animation, value, now, previousAnimation) {
46
- if (animations.length === 1) {
47
- throw Error('withSequence() animation require more than one animation as argument');
48
- }
49
46
  animation.animationIndex = 0;
50
47
  if (previousAnimation === undefined) {
51
48
  previousAnimation = animations[animations.length - 1];
@@ -11,14 +11,14 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import React from 'react';
13
13
  import { FlatList } from 'react-native';
14
- import WrappedComponents from './WrappedComponents';
14
+ import ReanimatedView from './View';
15
15
  import createAnimatedComponent from '../../createAnimatedComponent';
16
16
  const AnimatedFlatList = createAnimatedComponent(FlatList);
17
17
  const createCellRenderer = (itemLayoutAnimation) => {
18
18
  const cellRenderer = (props) => {
19
- return (<WrappedComponents.View layout={itemLayoutAnimation} onLayout={props.onLayout}>
19
+ return (<ReanimatedView layout={itemLayoutAnimation} onLayout={props.onLayout}>
20
20
  {props.children}
21
- </WrappedComponents.View>);
21
+ </ReanimatedView>);
22
22
  };
23
23
  return cellRenderer;
24
24
  };
@@ -0,0 +1,4 @@
1
+ import { Image } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+ const AnimatedImage = createAnimatedComponent(Image);
4
+ export default AnimatedImage;
@@ -0,0 +1,4 @@
1
+ import { ScrollView } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+ const AnimatedScrollView = createAnimatedComponent(ScrollView);
4
+ export default AnimatedScrollView;
@@ -0,0 +1,4 @@
1
+ import { Text } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+ const AnimatedText = createAnimatedComponent(Text);
4
+ export default AnimatedText;
@@ -0,0 +1,4 @@
1
+ import { View } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+ const AnimatedView = createAnimatedComponent(View);
4
+ export default AnimatedView;
@@ -238,11 +238,6 @@ if (!isWeb() && isConfigured()) {
238
238
  info: runOnJS(capturableConsole.info),
239
239
  };
240
240
  _setGlobalConsole(console);
241
- if (global.performance == null) {
242
- global.performance = {
243
- now: global._chronoNow,
244
- }; // due to conflict with lib.dom.d.ts -> Performance
245
- }
246
241
  })();
247
242
  }
248
243
  let featuresConfig = {
@@ -12,11 +12,6 @@ export function useEvent(handler, eventNames = [], rebuild = false) {
12
12
  else if (rebuild) {
13
13
  initRef.current.updateWorklet(handler);
14
14
  }
15
- useEffect(() => {
16
- return () => {
17
- initRef.current = null;
18
- };
19
- }, []);
20
15
  return initRef;
21
16
  }
22
17
  export function useHandler(handlers, dependencies) {
@@ -0,0 +1,25 @@
1
+ // In order to keep bundle size down, we treat this file as a polyfill for Web.
2
+ import { shouldBeUseWeb } from '../PlatformChecker';
3
+ if (shouldBeUseWeb()) {
4
+ global._frameTimestamp = null;
5
+ global._setGlobalConsole = (_val) => {
6
+ // noop
7
+ };
8
+ global._measure = () => {
9
+ console.warn("[Reanimated] You can't use `measure` with Chrome Debugger or with web version");
10
+ return {
11
+ x: 0,
12
+ y: 0,
13
+ width: 0,
14
+ height: 0,
15
+ pageX: 0,
16
+ pageY: 0,
17
+ };
18
+ };
19
+ global._scrollTo = () => {
20
+ console.warn("[Reanimated] You can't use `scrollTo` with Chrome Debugger or with web version");
21
+ };
22
+ global._setGestureState = () => {
23
+ console.warn("[Reanimated] You can't use `setGestureState` with Chrome Debugger or with web version");
24
+ };
25
+ }
@@ -1,29 +1,5 @@
1
1
  import JSReanimated from './JSReanimated';
2
- import { shouldBeUseWeb } from '../PlatformChecker';
3
2
  const reanimatedJS = new JSReanimated();
4
- if (shouldBeUseWeb()) {
5
- global._frameTimestamp = null;
6
- global._setGlobalConsole = (_val) => {
7
- // noop
8
- };
9
- global._measure = () => {
10
- console.warn("[Reanimated] You can't use `measure` with Chrome Debugger or with web version");
11
- return {
12
- x: 0,
13
- y: 0,
14
- width: 0,
15
- height: 0,
16
- pageX: 0,
17
- pageY: 0,
18
- };
19
- };
20
- global._scrollTo = () => {
21
- console.warn("[Reanimated] You can't use `scrollTo` with Chrome Debugger or with web version");
22
- };
23
- global._setGestureState = () => {
24
- console.warn("[Reanimated] You can't use `setGestureState` with Chrome Debugger or with web version");
25
- };
26
- }
27
3
  export const _updatePropsJS = (updates, viewRef) => {
28
4
  if (viewRef._component) {
29
5
  const component = viewRef._component;
@@ -64,6 +64,12 @@ const ReanimatedV2 = {
64
64
  out: ID,
65
65
  inOut: ID,
66
66
  },
67
+ Extrapolation: {
68
+ EXTEND: 'extend',
69
+ CLAMP: 'clamp',
70
+ IDENTITY: 'identity',
71
+ },
67
72
  runOnJS: (fn) => fn,
73
+ runOnUI: (fn) => fn,
68
74
  };
69
75
  module.exports = Object.assign({}, ReanimatedV2);
@@ -0,0 +1,8 @@
1
+ export { default as createAnimatedComponent } from './createAnimatedComponent';
2
+ export { addWhitelistedNativeProps, addWhitelistedUIProps, } from './ConfigHelper';
3
+ export { default as Text } from './reanimated2/component/Text';
4
+ export { default as View } from './reanimated2/component/View';
5
+ export { default as ScrollView } from './reanimated2/component/ScrollView';
6
+ export { default as Image } from './reanimated2/component/Image';
7
+ export { default as FlatList } from './reanimated2/component/FlatList';
8
+ export * from './reanimated1';
@@ -0,0 +1,4 @@
1
+ import './reanimated2/js-reanimated/global';
2
+ export * from './reanimated1';
3
+ export * from './reanimated2';
4
+ export * as default from './Animated';
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const AnimatedImage: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
3
+ export default AnimatedImage;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const AnimatedScrollView: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
3
+ export default AnimatedScrollView;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const AnimatedText: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
3
+ export default AnimatedText;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const AnimatedView: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
3
+ export default AnimatedView;
@@ -51,5 +51,11 @@ declare const ReanimatedV2: {
51
51
  out: (t: any) => any;
52
52
  inOut: (t: any) => any;
53
53
  };
54
+ Extrapolation: {
55
+ EXTEND: string;
56
+ CLAMP: string;
57
+ IDENTITY: string;
58
+ };
54
59
  runOnJS: (fn: any) => any;
60
+ runOnUI: (fn: any) => any;
55
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-reanimated",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "description": "More powerful alternative to Animated library for React Native.",
5
5
  "scripts": {
6
6
  "start": "node node_modules/react-native/local-cli/cli.js start",
@@ -34,10 +34,10 @@
34
34
  "clean:deep": "cd android && rm -rf .cxx .gradle build && cd ../Example/android && rm -rf .gradle build app/build && cd ../.. && yarn clean",
35
35
  "reset:deep": "yarn clean:deep && yarn setup"
36
36
  },
37
- "main": "lib/Animated.js",
38
- "module": "lib/Animated",
39
- "react-native": "src/Animated",
40
- "source": "src/Animated",
37
+ "main": "lib/index.js",
38
+ "module": "lib/index",
39
+ "react-native": "src/index",
40
+ "source": "src/index",
41
41
  "types": "react-native-reanimated.d.ts",
42
42
  "files": [
43
43
  "Common/",
@@ -74,6 +74,7 @@
74
74
  },
75
75
  "homepage": "https://github.com/software-mansion/react-native-reanimated#readme",
76
76
  "dependencies": {
77
+ "@babel/plugin-proposal-export-namespace-from": "^7.17.12",
77
78
  "@babel/plugin-transform-object-assign": "^7.16.7",
78
79
  "@babel/preset-typescript": "^7.16.7",
79
80
  "@types/invariant": "^2.2.35",
@@ -121,11 +122,11 @@
121
122
  "lint-staged": "^11.2.0",
122
123
  "madge": "^5.0.1",
123
124
  "prettier": "^2.5.1",
124
- "react": "17.0.2",
125
- "react-native": "0.68.0",
125
+ "react": "18.0.0",
126
+ "react-native": "0.69.1",
126
127
  "react-native-codegen": "^0.0.7",
127
128
  "react-native-gesture-handler": "^1.6.1",
128
- "react-test-renderer": "17.0.2",
129
+ "react-test-renderer": "18.0.0",
129
130
  "release-it": "^13.7.2",
130
131
  "typescript": "^4.1.3"
131
132
  },
@@ -154,5 +155,10 @@
154
155
  "commonjs",
155
156
  "module"
156
157
  ]
157
- }
158
+ },
159
+ "sideEffects": [
160
+ "./lib/reanimated2/core",
161
+ "./lib/reanimated2/js-reanimated/global",
162
+ "./lib/index"
163
+ ]
158
164
  }
package/plugin.js CHANGED
@@ -14,7 +14,6 @@ const functionArgsToWorkletize = new Map([
14
14
  ['useAnimatedScrollHandler', [0]],
15
15
  ['useAnimatedReaction', [0, 1]],
16
16
  ['useWorkletCallback', [0]],
17
- ['createWorklet', [0]],
18
17
  // animations' callbacks
19
18
  ['withTiming', [2]],
20
19
  ['withSpring', [2]],
@@ -757,6 +756,16 @@ function isPossibleOptimization(fun) {
757
756
  return flags;
758
757
  }
759
758
 
759
+ const pluginProposalExportNamespaceFrom =
760
+ require('@babel/plugin-proposal-export-namespace-from').default;
761
+ const apiMock = {
762
+ assertVersion: () => {
763
+ // do nothing.
764
+ },
765
+ };
766
+ const ExportNamedDeclarationFn =
767
+ pluginProposalExportNamespaceFrom(apiMock).visitor.ExportNamedDeclaration;
768
+
760
769
  module.exports = function ({ types: t }) {
761
770
  return {
762
771
  pre() {
@@ -779,6 +788,7 @@ module.exports = function ({ types: t }) {
779
788
  processIfGestureHandlerEventCallbackFunctionNode(t, path, state);
780
789
  },
781
790
  },
791
+ ExportNamedDeclaration: ExportNamedDeclarationFn,
782
792
  },
783
793
  };
784
794
  };
@@ -156,7 +156,7 @@ declare module 'react-native-reanimated' {
156
156
  : Record<string, unknown>;
157
157
 
158
158
  export type AnimateProps<P extends object> = {
159
- [K in keyof P]: P[K] | AnimatedNode<P[K]>;
159
+ [K in keyof Omit<P, 'style'>]: P[K] | AnimatedNode<P[K]>;
160
160
  } & {
161
161
  style?: StyleProp<AnimateStyle<StylesOrDefault<P>>>;
162
162
  } & {
@@ -650,9 +650,6 @@ declare module 'react-native-reanimated' {
650
650
  ): PropsAdapterFunction;
651
651
 
652
652
  export function processColor(color: number | string): number;
653
- export function createWorklet<A extends any[], R>(
654
- fn: (...args: A) => R
655
- ): (...args: Parameters<typeof fn>) => R;
656
653
 
657
654
  export function interpolateColor<T extends string | number>(
658
655
  value: number,
@@ -0,0 +1,13 @@
1
+ export { default as createAnimatedComponent } from './createAnimatedComponent';
2
+ export {
3
+ addWhitelistedNativeProps,
4
+ addWhitelistedUIProps,
5
+ } from './ConfigHelper';
6
+
7
+ export { default as Text } from './reanimated2/component/Text';
8
+ export { default as View } from './reanimated2/component/View';
9
+ export { default as ScrollView } from './reanimated2/component/ScrollView';
10
+ export { default as Image } from './reanimated2/component/Image';
11
+ export { default as FlatList } from './reanimated2/component/FlatList';
12
+ // @ts-ignore backward compatibility with treeshaking
13
+ export * from './reanimated1';
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ // tree-shaken side effects
2
+ import './reanimated2/js-reanimated/global';
3
+
4
+ // @ts-ignore backward compatibility with treeshaking
5
+ export * from './reanimated1';
6
+ export * from './reanimated2';
7
+ export * as default from './Animated';
@@ -11,7 +11,7 @@ export class NativeReanimated {
11
11
  private InnerNativeModule: any;
12
12
 
13
13
  constructor(native = true) {
14
- if (global.__reanimatedModuleProxy === undefined) {
14
+ if (global.__reanimatedModuleProxy === undefined && native) {
15
15
  const { ReanimatedModule } = NativeModules;
16
16
  ReanimatedModule?.installTurboModule();
17
17
  }
@@ -63,11 +63,6 @@ export function withSequence(
63
63
  now: Timestamp,
64
64
  previousAnimation: SequenceAnimation
65
65
  ): void {
66
- if (animations.length === 1) {
67
- throw Error(
68
- 'withSequence() animation require more than one animation as argument'
69
- );
70
- }
71
66
  animation.animationIndex = 0;
72
67
  if (previousAnimation === undefined) {
73
68
  previousAnimation = animations[
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { FlatList, FlatListProps, LayoutChangeEvent } from 'react-native';
3
- import WrappedComponents from './WrappedComponents';
3
+ import ReanimatedView from './View';
4
4
  import createAnimatedComponent from '../../createAnimatedComponent';
5
5
  import { ILayoutAnimationBuilder } from '../layoutReanimation/animationBuilder/commonTypes';
6
6
 
@@ -11,12 +11,9 @@ const createCellRenderer = (itemLayoutAnimation?: ILayoutAnimationBuilder) => {
11
11
  onLayout: (event: LayoutChangeEvent) => void;
12
12
  }> = (props) => {
13
13
  return (
14
- <WrappedComponents.View
15
- layout={itemLayoutAnimation}
16
- onLayout={props.onLayout}
17
- >
14
+ <ReanimatedView layout={itemLayoutAnimation} onLayout={props.onLayout}>
18
15
  {props.children}
19
- </WrappedComponents.View>
16
+ </ReanimatedView>
20
17
  );
21
18
  };
22
19
 
@@ -0,0 +1,6 @@
1
+ import { Image } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+
4
+ const AnimatedImage = createAnimatedComponent(Image as any);
5
+
6
+ export default AnimatedImage;
@@ -0,0 +1,6 @@
1
+ import { ScrollView } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+
4
+ const AnimatedScrollView = createAnimatedComponent(ScrollView);
5
+
6
+ export default AnimatedScrollView;
@@ -0,0 +1,6 @@
1
+ import { Text } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+
4
+ const AnimatedText = createAnimatedComponent(Text as any);
5
+
6
+ export default AnimatedText;
@@ -0,0 +1,6 @@
1
+ import { View } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+
4
+ const AnimatedView = createAnimatedComponent(View);
5
+
6
+ export default AnimatedView;
@@ -333,11 +333,6 @@ if (!isWeb() && isConfigured()) {
333
333
  info: runOnJS(capturableConsole.info),
334
334
  };
335
335
  _setGlobalConsole(console);
336
- if (global.performance == null) {
337
- global.performance = {
338
- now: global._chronoNow,
339
- } as any; // due to conflict with lib.dom.d.ts -> Performance
340
- }
341
336
  })();
342
337
  }
343
338
 
@@ -44,12 +44,6 @@ export function useEvent<T extends NativeEvent<T>>(
44
44
  initRef.current.updateWorklet(handler);
45
45
  }
46
46
 
47
- useEffect(() => {
48
- return () => {
49
- initRef.current = null;
50
- };
51
- }, []);
52
-
53
47
  return initRef;
54
48
  }
55
49
 
@@ -0,0 +1,33 @@
1
+ // In order to keep bundle size down, we treat this file as a polyfill for Web.
2
+
3
+ import { shouldBeUseWeb } from '../PlatformChecker';
4
+
5
+ if (shouldBeUseWeb()) {
6
+ global._frameTimestamp = null;
7
+ global._setGlobalConsole = (_val) => {
8
+ // noop
9
+ };
10
+ global._measure = () => {
11
+ console.warn(
12
+ "[Reanimated] You can't use `measure` with Chrome Debugger or with web version"
13
+ );
14
+ return {
15
+ x: 0,
16
+ y: 0,
17
+ width: 0,
18
+ height: 0,
19
+ pageX: 0,
20
+ pageY: 0,
21
+ };
22
+ };
23
+ global._scrollTo = () => {
24
+ console.warn(
25
+ "[Reanimated] You can't use `scrollTo` with Chrome Debugger or with web version"
26
+ );
27
+ };
28
+ global._setGestureState = () => {
29
+ console.warn(
30
+ "[Reanimated] You can't use `setGestureState` with Chrome Debugger or with web version"
31
+ );
32
+ };
33
+ }
@@ -1,5 +1,4 @@
1
1
  import JSReanimated from './JSReanimated';
2
- import { shouldBeUseWeb } from '../PlatformChecker';
3
2
  import { AnimatedStyle, StyleProps } from '../commonTypes';
4
3
 
5
4
  const reanimatedJS = new JSReanimated();
@@ -13,36 +12,6 @@ interface JSReanimatedComponent {
13
12
  };
14
13
  }
15
14
 
16
- if (shouldBeUseWeb()) {
17
- global._frameTimestamp = null;
18
- global._setGlobalConsole = (_val) => {
19
- // noop
20
- };
21
- global._measure = () => {
22
- console.warn(
23
- "[Reanimated] You can't use `measure` with Chrome Debugger or with web version"
24
- );
25
- return {
26
- x: 0,
27
- y: 0,
28
- width: 0,
29
- height: 0,
30
- pageX: 0,
31
- pageY: 0,
32
- };
33
- };
34
- global._scrollTo = () => {
35
- console.warn(
36
- "[Reanimated] You can't use `scrollTo` with Chrome Debugger or with web version"
37
- );
38
- };
39
- global._setGestureState = () => {
40
- console.warn(
41
- "[Reanimated] You can't use `setGestureState` with Chrome Debugger or with web version"
42
- );
43
- };
44
- }
45
-
46
15
  export const _updatePropsJS = (
47
16
  updates: StyleProps | AnimatedStyle,
48
17
  viewRef: { _component?: JSReanimatedComponent }
@@ -65,8 +65,14 @@ const ReanimatedV2 = {
65
65
  out: ID,
66
66
  inOut: ID,
67
67
  },
68
+ Extrapolation: {
69
+ EXTEND: 'extend',
70
+ CLAMP: 'clamp',
71
+ IDENTITY: 'identity',
72
+ },
68
73
 
69
74
  runOnJS: (fn) => fn,
75
+ runOnUI: (fn) => fn,
70
76
  };
71
77
 
72
78
  module.exports = {
@@ -1,9 +0,0 @@
1
- import { Image, ScrollView, Text, View } from 'react-native';
2
- import createAnimatedComponent from '../../createAnimatedComponent';
3
- const WrappedComponents = {
4
- View: createAnimatedComponent(View),
5
- Text: createAnimatedComponent(Text),
6
- Image: createAnimatedComponent(Image),
7
- ScrollView: createAnimatedComponent(ScrollView),
8
- };
9
- export default WrappedComponents;
@@ -1,4 +0,0 @@
1
- import ReanimatedFlatlist from './FlatList';
2
- import WrappedComponents from './WrappedComponents';
3
- const ReanimatedComponents = Object.assign(Object.assign({}, WrappedComponents), { FlatList: ReanimatedFlatlist });
4
- export default ReanimatedComponents;
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- declare const WrappedComponents: {
3
- View: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
4
- Text: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
5
- Image: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
6
- ScrollView: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
7
- };
8
- export default WrappedComponents;
@@ -1,9 +0,0 @@
1
- /// <reference types="react" />
2
- declare const ReanimatedComponents: {
3
- FlatList: import("react").FC<import("./FlatList").ReanimatedFlatlistProps<any>>;
4
- View: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
5
- Text: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
6
- Image: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
7
- ScrollView: import("react").ComponentType<import("../../createAnimatedComponent").AnimatedComponentProps<import("../../createAnimatedComponent").InitialComponentProps>>;
8
- };
9
- export default ReanimatedComponents;
package/src/Animated.js DELETED
@@ -1,22 +0,0 @@
1
- import createAnimatedComponent from './createAnimatedComponent';
2
- import {
3
- addWhitelistedNativeProps,
4
- addWhitelistedUIProps,
5
- } from './ConfigHelper';
6
- import * as reanimated1 from './reanimated1';
7
- import ReanimatedComponents from './reanimated2/component';
8
-
9
- const Animated = {
10
- // components
11
- ...ReanimatedComponents,
12
- createAnimatedComponent,
13
- // configuration
14
- addWhitelistedNativeProps,
15
- addWhitelistedUIProps,
16
- // reanimated 1
17
- ...reanimated1,
18
- };
19
-
20
- export * from './reanimated2';
21
- export * from './reanimated1';
22
- export default Animated;
@@ -1,11 +0,0 @@
1
- import { Image, ScrollView, Text, View } from 'react-native';
2
- import createAnimatedComponent from '../../createAnimatedComponent';
3
-
4
- const WrappedComponents = {
5
- View: createAnimatedComponent(View),
6
- Text: createAnimatedComponent(Text as any),
7
- Image: createAnimatedComponent(Image as any),
8
- ScrollView: createAnimatedComponent(ScrollView),
9
- };
10
-
11
- export default WrappedComponents;
@@ -1,9 +0,0 @@
1
- import ReanimatedFlatlist from './FlatList';
2
- import WrappedComponents from './WrappedComponents';
3
-
4
- const ReanimatedComponents = {
5
- ...WrappedComponents,
6
- FlatList: ReanimatedFlatlist,
7
- };
8
-
9
- export default ReanimatedComponents;