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