Skip to content

Commit 9015559

Browse files
committed
Merge branch 'master' of github.com:software-mansion/react-native-reanimated into v2-types
2 parents e71cb95 + 864f07b commit 9015559

File tree

31 files changed

+3868
-4489
lines changed

31 files changed

+3868
-4489
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ project.xcworkspace
2828
.idea
2929
.gradle
3030
local.properties
31+
android/src/main/JNILibs/
3132

3233
# node.js
3334
#

Common/cpp/Registries/WorkletsCache.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jsi::Function function(jsi::Runtime &rt, const std::string& code) {
1919
}
2020

2121
std::shared_ptr<jsi::Function> WorkletsCache::getFunction(jsi::Runtime &rt, std::shared_ptr<FrozenObject> frozenObj) {
22-
long long workletId = frozenObj->map["__workletID"]->numberValue;
23-
if (worklets.count(workletId) == 0) {
22+
long long workletHash = frozenObj->map["__workletHash"]->numberValue;
23+
if (worklets.count(workletHash) == 0) {
2424
jsi::Function fun = function(rt, frozenObj->map["asString"]->stringValue);
2525
std::shared_ptr<jsi::Function> funPtr(new jsi::Function(std::move(fun)));
26-
worklets[workletId] = funPtr;
26+
worklets[workletHash] = funPtr;
2727
}
28-
return worklets[workletId];
28+
return worklets[workletHash];
2929
}

Common/cpp/SharedItems/Shareable.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,19 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
195195
const jsi::Value *args,
196196
size_t count
197197
) mutable -> jsi::Value {
198-
return funPtr->callWithThis(rt, *jsThis, args, count);
198+
jsi::Value oldJSThis = rt.global().getProperty(rt, "jsThis");
199+
rt.global().setProperty(rt, "jsThis", *jsThis); //set jsThis
200+
201+
jsi::Value res = jsi::Value::undefined();
202+
203+
if (thisValue.isObject()) {
204+
res = funPtr->callWithThis(rt, thisValue.asObject(rt), args, count);
205+
} else {
206+
res = funPtr->call(rt, args, count);
207+
}
208+
209+
rt.global().setProperty(rt, "jsThis", oldJSThis); //clean jsThis
210+
return res;
199211
};
200212
return jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "workletFunction"), 0, clb);
201213
} else {
@@ -230,11 +242,15 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
230242

231243
jsi::Value returnedValue;
232244

233-
returnedValue = funPtr->callWithThis(rt,
234-
jsThis,
245+
jsi::Value oldJSThis = rt.global().getProperty(rt, "jsThis");
246+
rt.global().setProperty(rt, "jsThis", jsThis); //set jsThis
247+
248+
returnedValue = funPtr->call(rt,
235249
static_cast<const jsi::Value*>(args),
236250
(size_t)params.size());
237251

252+
rt.global().setProperty(rt, "jsThis", oldJSThis); //clean jsThis
253+
238254
delete [] args;
239255
// ToDo use returned value to return promise
240256
});
@@ -292,14 +308,15 @@ void MutableValue::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi:
292308

293309
if (module->isHostRuntime(rt)) {
294310
if (propName == "value") {
295-
{
296-
std::lock_guard<std::mutex> lock(readWriteMutex);
297-
value = ShareableValue::adapt(rt, newValue, module);
298-
}
299-
module->scheduler->scheduleOnUI([this] {
300-
for (auto listener : listeners) {
301-
listener.second();
302-
}
311+
auto shareable = ShareableValue::adapt(rt, newValue, module);
312+
module->scheduler->scheduleOnUI([this, shareable] {
313+
jsi::Runtime &rt = *this->module->runtime.get();
314+
auto setterProxy = jsi::Object::createFromHostObject(rt, std::make_shared<MutableValueSetterProxy>(shared_from_this()));
315+
jsi::Value newValue = shareable->getValue(rt);
316+
module->valueSetter->getValue(rt)
317+
.asObject(rt)
318+
.asFunction(rt)
319+
.callWithThis(rt, setterProxy, newValue);
303320
});
304321
}
305322
return;

Common/cpp/Tools/RuntimeDecorator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ void RuntimeDecorator::addNativeObjects(jsi::Runtime &rt, UpdaterFunction update
2121

2222
dummyGlobal.setProperty(rt, "__reanimatedWorkletInit", __reanimatedWorkletInit);
2323
rt.global().setProperty(rt, "global", dummyGlobal);
24+
25+
rt.global().setProperty(rt, "jsThis", jsi::Value::undefined());
2426

2527
auto callback = [](
2628
jsi::Runtime &rt,

Common/cpp/headers/NativeModules/NativeReanimatedModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ namespace reanimated {
1515
using FrameCallback = std::function<void(double)>;
1616

1717
class ShareableValue;
18+
class MutableValue;
1819
class MapperRegistry;
1920
class EventHandlerRegistry;
2021

2122
class NativeReanimatedModule : public NativeReanimatedModuleSpec {
2223
friend ShareableValue;
24+
friend MutableValue;
2325

2426
public:
2527
NativeReanimatedModule(std::shared_ptr<CallInvoker> jsInvoker,

Example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ dependencies {
160160
implementation project(':react-native-gesture-handler')
161161

162162
implementation fileTree(dir: "libs", include: ["*.jar"])
163-
implementation project(':react-native')// From node_modules
163+
implementation "com.facebook.react:react-native:+" // From node_modules
164164
//implementation 'org.webkit:android-jsc:+'
165165

166166
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

Example/android/build.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ buildscript {
1919
// NOTE: Do not place your application dependencies here; they belong
2020
// in the individual module build.gradle files
2121
}
22-
23-
configurations.all {
24-
resolutionStrategy {
25-
dependencySubstitution {
26-
substitute module("com.facebook.react:react-native:+") with project(":react-native")
27-
}
28-
}
29-
}
3022
}
3123

3224
allprojects {

Example/android/settings.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ include ':react-native-reanimated'
77
project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../../android')
88
include ':react-native-gesture-handler'
99
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
10-
include ':react-native'
11-
project(':react-native').projectDir = new File(rootProject.projectDir, '../node_modules/react-native/ReactAndroid')
1210
include ':app'

Example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ PODS:
264264
- React
265265
- RNGestureHandler (1.5.2):
266266
- React
267-
- RNReanimated (2.0.0-alpha.1):
267+
- RNReanimated (2.0.0-alpha.3):
268268
- DoubleConversion
269269
- FBLazyVector
270270
- FBReactNativeSpec
@@ -428,7 +428,7 @@ SPEC CHECKSUMS:
428428
ReactCommon: ed4e11d27609d571e7eee8b65548efc191116eb3
429429
RNCMaskedView: 76c40a1d41c3e2535df09246a2b5487f04de0814
430430
RNGestureHandler: 946a7691e41df61e2c4b1884deab41a4cdc3afff
431-
RNReanimated: cb0dce8f8375ff485c6d4760553ae831500e7787
431+
RNReanimated: c7c95835ae5490a0bca3761b84771594bcb8a6f0
432432
RNSVG: ce9d996113475209013317e48b05c21ee988d42e
433433
Yoga: 3ebccbdd559724312790e7742142d062476b698e
434434

Example/ios/ReanimatedExample/AppDelegate.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
5555
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
5656
{
5757
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge delegate:self];
58+
59+
#if RCT_DEV
60+
[_turboModuleManager moduleForName:"RCTDevMenu"];
61+
#endif
62+
5863
__weak __typeof(self) weakSelf = self;
5964
return std::make_unique<facebook::react::JSCExecutorFactory>([weakSelf, bridge](facebook::jsi::Runtime &runtime) {
6065
if (!bridge) {

0 commit comments

Comments
 (0)