react-native-reanimated 3.0.0-rc.4 → 3.0.0-rc.6

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 (61) hide show
  1. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +97 -15
  2. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +32 -8
  3. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +16 -1
  4. package/Common/cpp/NativeModules/NativeReanimatedModule.h +8 -1
  5. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +17 -0
  6. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +8 -0
  7. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +2 -1
  8. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.h +1 -0
  9. package/Common/cpp/Tools/RuntimeDecorator.cpp +2 -1
  10. package/android/CMakeLists.txt +1 -0
  11. package/android/build.gradle +9 -1
  12. package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +16 -25
  13. package/android/src/main/cpp/LayoutAnimations.cpp +42 -50
  14. package/android/src/main/cpp/LayoutAnimations.h +17 -3
  15. package/android/src/main/cpp/NativeProxy.cpp +55 -6
  16. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +1 -1
  17. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +208 -223
  18. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +7 -5
  19. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +5 -3
  20. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +1 -1
  21. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +20 -7
  22. package/android/src/reactNativeVersionPatch/nativeHierarchyManager/62/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +8 -44
  23. package/android/src/reactNativeVersionPatch/nativeHierarchyManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +15 -61
  24. package/ios/LayoutReanimation/REAAnimationsManager.h +18 -8
  25. package/ios/LayoutReanimation/REAAnimationsManager.m +197 -162
  26. package/ios/LayoutReanimation/REAUIManager.mm +63 -70
  27. package/ios/native/NativeProxy.mm +55 -48
  28. package/lib/commonjs/createAnimatedComponent.js +26 -26
  29. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  30. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +4 -0
  31. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  32. package/lib/commonjs/reanimated2/core.js +9 -9
  33. package/lib/commonjs/reanimated2/core.js.map +1 -1
  34. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  35. package/lib/commonjs/reanimated2/jestUtils.js +17 -9
  36. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  37. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +23 -62
  38. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +1 -1
  39. package/lib/module/createAnimatedComponent.js +27 -26
  40. package/lib/module/createAnimatedComponent.js.map +1 -1
  41. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +4 -0
  42. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  43. package/lib/module/reanimated2/core.js +7 -9
  44. package/lib/module/reanimated2/core.js.map +1 -1
  45. package/lib/module/reanimated2/globals.d.js.map +1 -1
  46. package/lib/module/reanimated2/jestUtils.js +17 -9
  47. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  48. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +22 -61
  49. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/createAnimatedComponent.tsx +48 -39
  52. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +15 -0
  53. package/src/reanimated2/core.ts +19 -10
  54. package/src/reanimated2/globals.d.ts +10 -6
  55. package/src/reanimated2/jestUtils.ts +14 -6
  56. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +24 -50
  57. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Default.js +0 -55
  58. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Default.js.map +0 -1
  59. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Default.js +0 -40
  60. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Default.js.map +0 -1
  61. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +0 -49
@@ -11,35 +11,117 @@ namespace reanimated {
11
11
  const long long idOffset = 1e9;
12
12
 
13
13
  LayoutAnimationsProxy::LayoutAnimationsProxy(
14
- std::function<void(int, jsi::Object newProps)> _notifyAboutProgress,
15
- std::function<void(int, bool)> _notifyAboutEnd)
16
- : notifyAboutProgress(std::move(_notifyAboutProgress)),
17
- notifyAboutEnd(std::move(_notifyAboutEnd)) {}
14
+ std::function<void(int, jsi::Object newProps)> progressHandler,
15
+ std::function<void(int, bool, bool)> endHandler,
16
+ std::weak_ptr<ErrorHandler> weakErrorHandler)
17
+ : progressHandler_(std::move(progressHandler)),
18
+ endHandler_(std::move(endHandler)),
19
+ weakErrorHandler_(weakErrorHandler) {}
18
20
 
19
21
  void LayoutAnimationsProxy::startObserving(
20
22
  int tag,
21
23
  std::shared_ptr<MutableValue> sv,
22
24
  jsi::Runtime &rt) {
23
- observedValues[tag] = sv;
25
+ observedValues_[tag] = sv;
26
+ this->progressHandler_(tag, sv->value->toJSValue(rt).asObject(rt));
24
27
  sv->addListener(tag + idOffset, [sv, tag, this, &rt]() {
25
- std::shared_ptr<FrozenObject> newValue =
26
- ValueWrapper::asFrozenObject(sv->value->valueContainer);
27
- this->notifyAboutProgress(tag, newValue->shallowClone(rt));
28
+ this->progressHandler_(tag, sv->value->toJSValue(rt).asObject(rt));
28
29
  });
29
30
  }
30
31
 
31
- void LayoutAnimationsProxy::stopObserving(int tag, bool finished) {
32
- if (observedValues.count(tag) == 0) {
32
+ void LayoutAnimationsProxy::stopObserving(
33
+ int tag,
34
+ bool finished,
35
+ bool removeView) {
36
+ if (observedValues_.count(tag) == 0) {
33
37
  return;
34
38
  }
35
- std::shared_ptr<MutableValue> sv = observedValues[tag];
39
+ std::shared_ptr<MutableValue> sv = observedValues_[tag];
36
40
  sv->removeListener(tag + idOffset);
37
- observedValues.erase(tag);
38
- this->notifyAboutEnd(tag, !finished);
41
+ observedValues_.erase(tag);
42
+ this->endHandler_(tag, !finished, removeView);
43
+ }
44
+
45
+ void LayoutAnimationsProxy::configureAnimation(
46
+ int tag,
47
+ const std::string &type,
48
+ std::shared_ptr<ShareableValue> config,
49
+ std::shared_ptr<ShareableValue> viewSharedValue) {
50
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
51
+ if (type == "entering") {
52
+ enteringAnimations_[tag] = config;
53
+ } else if (type == "exiting") {
54
+ exitingAnimations_[tag] = config;
55
+ } else if (type == "layout") {
56
+ layoutAnimations_[tag] = config;
57
+ }
58
+ viewSharedValues_[tag] = viewSharedValue;
59
+ }
60
+
61
+ bool LayoutAnimationsProxy::hasLayoutAnimation(
62
+ int tag,
63
+ const std::string &type) {
64
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
65
+ if (type == "entering") {
66
+ return enteringAnimations_.find(tag) != enteringAnimations_.end();
67
+ } else if (type == "exiting") {
68
+ return exitingAnimations_.find(tag) != exitingAnimations_.end();
69
+ } else if (type == "layout") {
70
+ return layoutAnimations_.find(tag) != layoutAnimations_.end();
71
+ }
72
+ return false;
73
+ }
74
+
75
+ void LayoutAnimationsProxy::clearLayoutAnimationConfig(int tag) {
76
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
77
+ enteringAnimations_.erase(tag);
78
+ exitingAnimations_.erase(tag);
79
+ layoutAnimations_.erase(tag);
80
+ viewSharedValues_.erase(tag);
39
81
  }
40
82
 
41
- void LayoutAnimationsProxy::notifyAboutCancellation(int tag) {
42
- this->notifyAboutEnd(tag, false);
83
+ void LayoutAnimationsProxy::startLayoutAnimation(
84
+ jsi::Runtime &rt,
85
+ int tag,
86
+ const std::string &type,
87
+ const jsi::Object &values) {
88
+ std::shared_ptr<ShareableValue> config;
89
+ std::shared_ptr<ShareableValue> viewSharedValue;
90
+ {
91
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
92
+ if (type == "entering") {
93
+ config = enteringAnimations_[tag];
94
+ } else if (type == "exiting") {
95
+ config = exitingAnimations_[tag];
96
+ } else if (type == "layout") {
97
+ config = layoutAnimations_[tag];
98
+ }
99
+ viewSharedValue = viewSharedValues_[tag];
100
+ }
101
+
102
+ jsi::Value layoutAnimationRepositoryAsValue =
103
+ rt.global()
104
+ .getPropertyAsObject(rt, "global")
105
+ .getProperty(rt, "LayoutAnimationRepository");
106
+ if (layoutAnimationRepositoryAsValue.isUndefined()) {
107
+ auto errorHandler = weakErrorHandler_.lock();
108
+ if (errorHandler != nullptr) {
109
+ errorHandler->setError(
110
+ "startLayoutAnimation called before initializing LayoutAnimationRepository");
111
+ errorHandler->raise();
112
+ }
113
+ return;
114
+ }
115
+ jsi::Function startAnimationForTag =
116
+ layoutAnimationRepositoryAsValue.getObject(rt).getPropertyAsFunction(
117
+ rt, "startAnimationForTag");
118
+ startAnimationForTag.call(
119
+ rt,
120
+ jsi::Value(tag),
121
+ jsi::String::createFromAscii(rt, type),
122
+ values,
123
+ config->toJSValue(rt),
124
+ viewSharedValue->toJSValue(rt));
43
125
  }
44
126
 
45
127
  } // namespace reanimated
@@ -1,32 +1,56 @@
1
1
  #pragma once
2
2
 
3
+ #include <ErrorHandler.h>
3
4
  #include <jsi/jsi.h>
4
5
  #include <stdio.h>
5
6
  #include <functional>
6
- #include <map>
7
7
  #include <memory>
8
+ #include <mutex>
9
+ #include <string>
10
+ #include <unordered_map>
8
11
 
9
12
  namespace reanimated {
10
13
 
11
14
  using namespace facebook;
12
15
 
13
16
  class MutableValue;
17
+ class ShareableValue;
14
18
 
15
19
  class LayoutAnimationsProxy {
16
20
  public:
17
21
  LayoutAnimationsProxy(
18
- std::function<void(int, jsi::Object newProps)> _notifyAboutProgress,
19
- std::function<void(int, bool)> _notifyAboutEnd);
22
+ std::function<void(int, jsi::Object newProps)> progressHandler,
23
+ std::function<void(int, bool, bool)> endHandler,
24
+ std::weak_ptr<ErrorHandler> weakErrorHandler);
20
25
 
21
26
  void
22
27
  startObserving(int tag, std::shared_ptr<MutableValue> sv, jsi::Runtime &rt);
23
- void stopObserving(int tag, bool finished);
24
- void notifyAboutCancellation(int tag);
28
+ void stopObserving(int tag, bool finished, bool removeView);
29
+ void configureAnimation(
30
+ int tag,
31
+ const std::string &type,
32
+ std::shared_ptr<ShareableValue> config,
33
+ std::shared_ptr<ShareableValue> viewSharedValue);
34
+ bool hasLayoutAnimation(int tag, const std::string &type);
35
+ void startLayoutAnimation(
36
+ jsi::Runtime &rt,
37
+ int tag,
38
+ const std::string &type,
39
+ const jsi::Object &values);
40
+ void clearLayoutAnimationConfig(int tag);
25
41
 
26
42
  private:
27
- std::function<void(int, jsi::Object newProps)> notifyAboutProgress;
28
- std::function<void(int, bool)> notifyAboutEnd;
29
- std::map<int, std::shared_ptr<MutableValue>> observedValues;
43
+ std::function<void(int, jsi::Object newProps)> progressHandler_;
44
+ std::function<void(int, bool, bool)> endHandler_;
45
+ std::weak_ptr<ErrorHandler> weakErrorHandler_;
46
+ std::unordered_map<int, std::shared_ptr<MutableValue>> observedValues_;
47
+ std::unordered_map<int, std::shared_ptr<ShareableValue>> viewSharedValues_;
48
+ std::unordered_map<int, std::shared_ptr<ShareableValue>> enteringAnimations_;
49
+ std::unordered_map<int, std::shared_ptr<ShareableValue>> exitingAnimations_;
50
+ std::unordered_map<int, std::shared_ptr<ShareableValue>> layoutAnimations_;
51
+ mutable std::mutex
52
+ animationsMutex_; // Protects `enteringAnimations_`, `exitingAnimations_`,
53
+ // `layoutAnimations_` and `viewSharedValues_`.
30
54
  };
31
55
 
32
56
  } // namespace reanimated
@@ -87,6 +87,7 @@ NativeReanimatedModule::NativeReanimatedModule(
87
87
  PlatformDepMethodsHolder platformDepMethodsHolder)
88
88
  : NativeReanimatedModuleSpec(jsInvoker),
89
89
  RuntimeManager(rt, errorHandler, scheduler, RuntimeType::UI),
90
+ layoutAnimationsProxy_(layoutAnimationsProxy),
90
91
  mapperRegistry(std::make_shared<MapperRegistry>()),
91
92
  eventHandlerRegistry(std::make_shared<EventHandlerRegistry>()),
92
93
  requestRender(platformDepMethodsHolder.requestRender),
@@ -109,7 +110,7 @@ NativeReanimatedModule::NativeReanimatedModule(
109
110
  maybeRequestRender();
110
111
  };
111
112
 
112
- this->layoutAnimationsProxy = layoutAnimationsProxy;
113
+ this->layoutAnimationsProxy_ = layoutAnimationsProxy;
113
114
 
114
115
  #ifdef RCT_NEW_ARCH_ENABLED
115
116
  auto updateProps = [this](
@@ -337,6 +338,20 @@ jsi::Value NativeReanimatedModule::configureProps(
337
338
  return jsi::Value::undefined();
338
339
  }
339
340
 
341
+ jsi::Value NativeReanimatedModule::configureLayoutAnimation(
342
+ jsi::Runtime &rt,
343
+ const jsi::Value &viewTag,
344
+ const jsi::Value &type,
345
+ const jsi::Value &config,
346
+ const jsi::Value &viewSharedValue) {
347
+ layoutAnimationsProxy_->configureAnimation(
348
+ viewTag.asNumber(),
349
+ type.asString(rt).utf8(rt),
350
+ ShareableValue::adapt(rt, config, this),
351
+ ShareableValue::adapt(rt, viewSharedValue, this));
352
+ return jsi::Value::undefined();
353
+ }
354
+
340
355
  void NativeReanimatedModule::onEvent(
341
356
  std::string eventName,
342
357
  #ifdef RCT_NEW_ARCH_ENABLED
@@ -144,11 +144,19 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
144
144
  jsi::Runtime &rt,
145
145
  const jsi::Value &listenerId) override;
146
146
 
147
+ jsi::Value configureLayoutAnimation(
148
+ jsi::Runtime &rt,
149
+ const jsi::Value &viewTag,
150
+ const jsi::Value &type,
151
+ const jsi::Value &config,
152
+ const jsi::Value &viewSharedValue) override;
153
+
147
154
  private:
148
155
  #ifdef RCT_NEW_ARCH_ENABLED
149
156
  bool isThereAnyLayoutProp(jsi::Runtime &rt, const jsi::Value &props);
150
157
  #endif // RCT_NEW_ARCH_ENABLED
151
158
 
159
+ std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy_;
152
160
  std::shared_ptr<MapperRegistry> mapperRegistry;
153
161
  std::shared_ptr<EventHandlerRegistry> eventHandlerRegistry;
154
162
  std::function<void(FrameCallback &, jsi::Runtime &)> requestRender;
@@ -158,7 +166,6 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
158
166
  std::function<jsi::Value(jsi::Runtime &, const int, const jsi::String &)>
159
167
  propObtainer;
160
168
  std::function<void(double)> onRenderCallback;
161
- std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy;
162
169
  AnimatedSensorModule animatedSensorModule;
163
170
  ConfigurePropsFunction configurePropsPlatformFunction;
164
171
 
@@ -159,6 +159,20 @@ static jsi::Value SPEC_PREFIX(unsubscribeFromKeyboardEvents)(
159
159
  return jsi::Value::undefined();
160
160
  }
161
161
 
162
+ static jsi::Value SPEC_PREFIX(configureLayoutAnimation)(
163
+ jsi::Runtime &rt,
164
+ TurboModule &turboModule,
165
+ const jsi::Value *args,
166
+ size_t count) {
167
+ return static_cast<NativeReanimatedModuleSpec *>(&turboModule)
168
+ ->configureLayoutAnimation(
169
+ rt,
170
+ std::move(args[0]),
171
+ std::move(args[1]),
172
+ std::move(args[2]),
173
+ std::move(args[3]));
174
+ }
175
+
162
176
  NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
163
177
  std::shared_ptr<CallInvoker> jsInvoker)
164
178
  : TurboModule("NativeReanimated", jsInvoker) {
@@ -188,5 +202,8 @@ NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
188
202
  MethodMetadata{1, SPEC_PREFIX(subscribeForKeyboardEvents)};
189
203
  methodMap_["unsubscribeFromKeyboardEvents"] =
190
204
  MethodMetadata{1, SPEC_PREFIX(unsubscribeFromKeyboardEvents)};
205
+
206
+ methodMap_["configureLayoutAnimation"] =
207
+ MethodMetadata{4, SPEC_PREFIX(configureLayoutAnimation)};
191
208
  }
192
209
  } // namespace reanimated
@@ -85,6 +85,14 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
85
85
  jsi::Runtime &rt,
86
86
  const jsi::Value &uiProps,
87
87
  const jsi::Value &nativeProps) = 0;
88
+
89
+ // layout animations
90
+ virtual jsi::Value configureLayoutAnimation(
91
+ jsi::Runtime &rt,
92
+ const jsi::Value &viewTag,
93
+ const jsi::Value &type,
94
+ const jsi::Value &config,
95
+ const jsi::Value &viewSharedValue) = 0;
88
96
  };
89
97
 
90
98
  } // namespace reanimated
@@ -20,6 +20,7 @@ using namespace facebook;
20
20
  using namespace react;
21
21
 
22
22
  std::shared_ptr<jsi::Runtime> ReanimatedRuntime::make(
23
+ jsi::Runtime *rnRuntime,
23
24
  std::shared_ptr<MessageQueueThread> jsQueue) {
24
25
  #if JS_RUNTIME_HERMES
25
26
  std::unique_ptr<facebook::hermes::HermesRuntime> runtime =
@@ -37,7 +38,7 @@ std::shared_ptr<jsi::Runtime> ReanimatedRuntime::make(
37
38
  auto config = std::make_unique<rnv8::V8RuntimeConfig>();
38
39
  config->enableInspector = false;
39
40
  config->appName = "reanimated";
40
- return rnv8::createSharedV8Runtime(runtime_, std::move(config));
41
+ return rnv8::createSharedV8Runtime(rnRuntime, std::move(config));
41
42
  #else
42
43
  // This is required by iOS, because there is an assertion in the destructor
43
44
  // that the thread was indeed `quit` before
@@ -21,6 +21,7 @@ using namespace react;
21
21
  class ReanimatedRuntime {
22
22
  public:
23
23
  static std::shared_ptr<jsi::Runtime> make(
24
+ jsi::Runtime *rnRuntime,
24
25
  std::shared_ptr<MessageQueueThread> jsQueue);
25
26
  };
26
27
 
@@ -277,7 +277,8 @@ void RuntimeDecorator::decorateUIRuntime(
277
277
  if (layoutProxy.expired()) {
278
278
  return jsi::Value::undefined();
279
279
  }
280
- proxy->stopObserving(args[0].asNumber(), args[1].getBool());
280
+ proxy->stopObserving(
281
+ args[0].asNumber(), args[1].getBool(), args[2].getBool());
281
282
  return jsi::Value::undefined();
282
283
  };
283
284
  jsi::Value _stopObservingProgress = jsi::Function::createFromHostFunction(
@@ -332,3 +332,4 @@ endif()
332
332
  set (ignoreMe "${CLIENT_SIDE_BUILD}")
333
333
  set (ignoreMe "${JS_RUNTIME_DIR}")
334
334
  set (ignoreMe "${PLAYGROUND_APP_NAME}")
335
+ set (ignoreMe "${REANIMATED_PACKAGE_BUILD}")
@@ -1,5 +1,6 @@
1
1
  import com.android.Version
2
2
  import org.apache.tools.ant.filters.ReplaceTokens
3
+ import org.apache.tools.ant.taskdefs.condition.Os
3
4
  import groovy.json.JsonSlurper
4
5
  import java.nio.file.Paths
5
6
 
@@ -183,6 +184,13 @@ def getReanimatedVersion() {
183
184
  return major.toInteger()
184
185
  }
185
186
 
187
+ def toPlatformFileString(String path) {
188
+ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
189
+ path = path.replace(File.separatorChar, '/' as char)
190
+ }
191
+ return path
192
+ }
193
+
186
194
  boolean CLIENT_SIDE_BUILD = resolveClientSideBuild()
187
195
  if (CLIENT_SIDE_BUILD) {
188
196
  configurations.maybeCreate("default")
@@ -447,7 +455,7 @@ android {
447
455
  "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
448
456
  "-DANDROID_TOOLCHAIN=clang",
449
457
  "-DBOOST_VERSION=${BOOST_VERSION}",
450
- "-DREACT_NATIVE_DIR=${reactNativeRootDir.path}",
458
+ "-DREACT_NATIVE_DIR=${toPlatformFileString(reactNativeRootDir.path)}",
451
459
  "-DJS_RUNTIME=${JS_RUNTIME}",
452
460
  "-DJS_RUNTIME_DIR=${jsRuntimeDir}",
453
461
  "-DCLIENT_SIDE_BUILD=${CLIENT_SIDE_BUILD}",
@@ -307,31 +307,22 @@ public class NativeProxy {
307
307
 
308
308
  WeakReference<LayoutAnimations> weakLayoutAnimations = new WeakReference<>(LayoutAnimations);
309
309
  animationsManager.setNativeMethods(
310
- new NativeMethodsHolder() {
311
- @Override
312
- public void startAnimationForTag(int tag, String type, HashMap<String, Float> values) {
313
- LayoutAnimations LayoutAnimations = weakLayoutAnimations.get();
314
- if (LayoutAnimations != null) {
315
- HashMap<String, String> preparedValues = new HashMap<>();
316
- for (String key : values.keySet()) {
317
- preparedValues.put(key, values.get(key).toString());
310
+ new NativeMethodsHolder() {
311
+ @Override
312
+ public void startAnimation(int tag, String type, HashMap<String, Float> values) {}
313
+
314
+ @Override
315
+ public boolean isLayoutAnimationEnabled() {
316
+ return false;
317
+ }
318
+
319
+ @Override
320
+ public boolean hasAnimation(int tag, String type) {
321
+ return false;
318
322
  }
319
- LayoutAnimations.startAnimationForTag(tag, type, preparedValues);
320
- }
321
- }
322
-
323
- @Override
324
- public void removeConfigForTag(int tag) {
325
- LayoutAnimations LayoutAnimations = weakLayoutAnimations.get();
326
- if (LayoutAnimations != null) {
327
- LayoutAnimations.removeConfigForTag(tag);
328
- }
329
- }
330
-
331
- @Override
332
- public boolean isLayoutAnimationEnabled() {
333
- return LayoutAnimations.isLayoutAnimationEnabled();
334
- }
335
- });
323
+
324
+ @Override
325
+ public void clearAnimationConfig(int tag) {}
326
+ });
336
327
  }
337
328
  }
@@ -17,70 +17,59 @@ void LayoutAnimations::setWeakUIRuntime(std::weak_ptr<jsi::Runtime> wrt) {
17
17
  this->weakUIRuntime = wrt;
18
18
  }
19
19
 
20
+ void LayoutAnimations::setAnimationStartingBlock(
21
+ AnimationStartingBlock animationStartingBlock) {
22
+ this->animationStartingBlock_ = animationStartingBlock;
23
+ }
24
+
20
25
  void LayoutAnimations::startAnimationForTag(
21
26
  int tag,
22
27
  alias_ref<JString> type,
23
28
  alias_ref<JMap<jstring, jstring>> values) {
24
- if (auto rt = this->weakUIRuntime.lock()) {
25
- jsi::Value layoutAnimationRepositoryAsValue =
26
- rt->global()
27
- .getPropertyAsObject(*rt, "global")
28
- .getProperty(*rt, "LayoutAnimationRepository");
29
- if (!layoutAnimationRepositoryAsValue.isUndefined()) {
30
- jsi::Function startAnimationForTag =
31
- layoutAnimationRepositoryAsValue.getObject(*rt).getPropertyAsFunction(
32
- *rt, "startAnimationForTag");
33
- jsi::Object target(*rt);
34
-
35
- for (const auto &entry : *values) {
36
- target.setProperty(
37
- *rt,
38
- entry.first->toStdString().c_str(),
39
- std::stof(entry.second->toStdString()));
40
- }
41
- startAnimationForTag.call(
42
- *rt,
43
- jsi::Value(tag),
44
- jsi::String::createFromUtf8(*rt, type->toStdString()),
45
- target);
46
- }
47
- }
29
+ this->animationStartingBlock_(tag, type, values);
48
30
  }
49
31
 
50
- void LayoutAnimations::removeConfigForTag(int tag) {
51
- if (auto rt = this->weakUIRuntime.lock()) {
52
- jsi::Value layoutAnimationRepositoryAsValue =
53
- rt->global()
54
- .getPropertyAsObject(*rt, "global")
55
- .getProperty(*rt, "LayoutAnimationRepository");
56
- if (!layoutAnimationRepositoryAsValue.isUndefined()) {
57
- jsi::Function removeConfig =
58
- layoutAnimationRepositoryAsValue.getObject(*rt).getPropertyAsFunction(
59
- *rt, "removeConfig");
60
- removeConfig.call(*rt, jsi::Value(tag));
61
- }
62
- }
63
- }
64
-
65
- void LayoutAnimations::notifyAboutProgress(
66
- const jsi::Value &progress,
67
- int tag) {
32
+ void LayoutAnimations::progressLayoutAnimation(
33
+ int tag,
34
+ const jsi::Value &progress) {
68
35
  if (auto rt = this->weakUIRuntime.lock()) {
69
36
  static const auto method =
70
37
  javaPart_->getClass()
71
- ->getMethod<void(JMap<JString, JObject>::javaobject, int)>(
72
- "notifyAboutProgress");
38
+ ->getMethod<void(int, JMap<JString, JObject>::javaobject)>(
39
+ "progressLayoutAnimation");
73
40
  method(
74
41
  javaPart_.get(),
75
- JNIHelper::ConvertToPropsMap(*rt, progress.asObject(*rt)).get(),
76
- tag);
42
+ tag,
43
+ JNIHelper::ConvertToPropsMap(*rt, progress.asObject(*rt)).get());
77
44
  }
78
45
  }
79
46
 
80
- void LayoutAnimations::notifyAboutEnd(int tag, int cancelled) {
47
+ void LayoutAnimations::endLayoutAnimation(
48
+ int tag,
49
+ bool cancelled,
50
+ bool removeView) {
81
51
  static const auto method =
82
- javaPart_->getClass()->getMethod<void(int, int)>("notifyAboutEnd");
83
- method(javaPart_.get(), tag, cancelled);
52
+ javaPart_->getClass()->getMethod<void(int, bool, bool)>(
53
+ "endLayoutAnimation");
54
+ method(javaPart_.get(), tag, cancelled, removeView);
55
+ }
56
+
57
+ void LayoutAnimations::setHasAnimationBlock(
58
+ HasAnimationBlock hasAnimationBlock) {
59
+ this->hasAnimationBlock_ = hasAnimationBlock;
60
+ }
61
+
62
+ bool LayoutAnimations::hasAnimationForTag(int tag, std::string type) {
63
+ return hasAnimationBlock_(tag, type);
64
+ }
65
+
66
+ void LayoutAnimations::setClearAnimationConfigBlock(
67
+ ClearAnimationConfigBlock clearAnimationConfigBlock) {
68
+ this->clearAnimationConfigBlock_ = clearAnimationConfigBlock;
69
+ }
70
+
71
+ void LayoutAnimations::clearAnimationConfigForTag(int tag) {
72
+ clearAnimationConfigBlock_(tag);
84
73
  }
85
74
 
86
75
  bool LayoutAnimations::isLayoutAnimationEnabled() {
@@ -93,7 +82,10 @@ void LayoutAnimations::registerNatives() {
93
82
  makeNativeMethod(
94
83
  "startAnimationForTag", LayoutAnimations::startAnimationForTag),
95
84
  makeNativeMethod(
96
- "removeConfigForTag", LayoutAnimations::removeConfigForTag),
85
+ "hasAnimationForTag", LayoutAnimations::hasAnimationForTag),
86
+ makeNativeMethod(
87
+ "clearAnimationConfigForTag",
88
+ LayoutAnimations::clearAnimationConfigForTag),
97
89
  makeNativeMethod(
98
90
  "isLayoutAnimationEnabled",
99
91
  LayoutAnimations::isLayoutAnimationEnabled),
@@ -3,6 +3,7 @@
3
3
  #include <fbjni/fbjni.h>
4
4
  #include <jsi/jsi.h>
5
5
  #include <memory>
6
+ #include <string>
6
7
  #include "JNIHelper.h"
7
8
 
8
9
  namespace reanimated {
@@ -11,6 +12,11 @@ using namespace facebook::jni;
11
12
  using namespace facebook;
12
13
 
13
14
  class LayoutAnimations : public jni::HybridClass<LayoutAnimations> {
15
+ using AnimationStartingBlock = std::function<
16
+ void(int, alias_ref<JString>, alias_ref<JMap<jstring, jstring>>)>;
17
+ using HasAnimationBlock = std::function<bool(int, std::string)>;
18
+ using ClearAnimationConfigBlock = std::function<void(int)>;
19
+
14
20
  public:
15
21
  static auto constexpr kJavaDescriptor =
16
22
  "Lcom/swmansion/reanimated/layoutReanimation/LayoutAnimations;";
@@ -22,18 +28,26 @@ class LayoutAnimations : public jni::HybridClass<LayoutAnimations> {
22
28
  int tag,
23
29
  alias_ref<JString> type,
24
30
  alias_ref<JMap<jstring, jstring>> values);
25
- void removeConfigForTag(int tag);
31
+ bool hasAnimationForTag(int tag, std::string type);
26
32
  bool isLayoutAnimationEnabled();
27
33
 
28
34
  void setWeakUIRuntime(std::weak_ptr<jsi::Runtime> wrt);
35
+ void setAnimationStartingBlock(AnimationStartingBlock animationStartingBlock);
36
+ void setHasAnimationBlock(HasAnimationBlock hasAnimationBlock);
37
+ void setClearAnimationConfigBlock(
38
+ ClearAnimationConfigBlock clearAnimationConfigBlock);
29
39
 
30
- void notifyAboutProgress(const jsi::Value &progress, int tag);
31
- void notifyAboutEnd(int tag, int cancelled);
40
+ void progressLayoutAnimation(int tag, const jsi::Value &progress);
41
+ void endLayoutAnimation(int tag, bool cancelled, bool removeView);
42
+ void clearAnimationConfigForTag(int tag);
32
43
 
33
44
  private:
34
45
  friend HybridBase;
35
46
  jni::global_ref<LayoutAnimations::javaobject> javaPart_;
36
47
  std::weak_ptr<jsi::Runtime> weakUIRuntime;
48
+ AnimationStartingBlock animationStartingBlock_;
49
+ HasAnimationBlock hasAnimationBlock_;
50
+ ClearAnimationConfigBlock clearAnimationConfigBlock_;
37
51
 
38
52
  explicit LayoutAnimations(
39
53
  jni::alias_ref<LayoutAnimations::jhybridobject> jThis);