1 #include "MutableValueSetterProxy.h"
2 #include <ABI48_0_0jsi/ABI48_0_0jsi.h>
3 #include "MutableValue.h"
4 #include "SharedParent.h"
5
6 using namespace ABI48_0_0facebook;
7
8 namespace ABI48_0_0reanimated {
9
set(jsi::Runtime & rt,const jsi::PropNameID & name,const jsi::Value & newValue)10 void MutableValueSetterProxy::set(
11 jsi::Runtime &rt,
12 const jsi::PropNameID &name,
13 const jsi::Value &newValue) {
14 auto propName = name.utf8(rt);
15 if (propName == "_value") {
16 mutableValue->setValue(rt, newValue);
17 } else if (propName == "_animation") {
18 // TODO: assert to allow animation to be set from UI only
19 if (mutableValue->animation.expired()) {
20 mutableValue->animation = mutableValue->getWeakRef(rt);
21 }
22 *mutableValue->animation.lock() = jsi::Value(rt, newValue);
23 } else if (propName == "value") {
24 // you call `this.value` inside of value setter, we should throw
25 }
26 }
27
get(jsi::Runtime & rt,const jsi::PropNameID & name)28 jsi::Value MutableValueSetterProxy::get(
29 jsi::Runtime &rt,
30 const jsi::PropNameID &name) {
31 auto propName = name.utf8(rt);
32
33 if (propName == "value") {
34 return mutableValue->getValue(rt);
35 } else if (propName == "_value") {
36 return mutableValue->getValue(rt);
37 } else if (propName == "_animation") {
38 if (mutableValue->animation.expired()) {
39 mutableValue->animation = mutableValue->getWeakRef(rt);
40 }
41 return jsi::Value(rt, *mutableValue->animation.lock());
42 }
43
44 return jsi::Value::undefined();
45 }
46
47 } // namespace reanimated
48