xref: /expo/android/vendored/sdk47/react-native-reanimated/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp (revision 89486d34)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "LayoutAnimationsProxy.h"
2 #include "FrozenObject.h"
3 #include "MutableValue.h"
4 #include "ShareableValue.h"
5 #include "ValueWrapper.h"
6 
7 #include <utility>
8 
9 namespace reanimated {
10 
11 const long long idOffset = 1e9;
12 
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)) {}
18 
19 void LayoutAnimationsProxy::startObserving(
20     int tag,
21     std::shared_ptr<MutableValue> sv,
22     jsi::Runtime &rt) {
23   observedValues[tag] = sv;
24   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   });
29 }
30 
31 void LayoutAnimationsProxy::stopObserving(int tag, bool finished) {
32   if (observedValues.count(tag) == 0) {
33     return;
34   }
35   std::shared_ptr<MutableValue> sv = observedValues[tag];
36   sv->removeListener(tag + idOffset);
37   observedValues.erase(tag);
38   this->notifyAboutEnd(tag, !finished);
39 }
40 
41 void LayoutAnimationsProxy::notifyAboutCancellation(int tag) {
42   this->notifyAboutEnd(tag, false);
43 }
44 
45 } // namespace reanimated
46 

served by {OpenGrok

Last Index Update: Tue Oct 21 18:42:31 GMT 2025