Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeDecorator: Correctly set global #1833

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c637701
Add Common/ to xcodeproj
mrousavy Mar 5, 2021
85baa8d
Add static helper to determine if runtime is UI runtime
mrousavy Mar 5, 2021
f837ee0
Refactor usages to use static UI runtime helper
mrousavy Mar 5, 2021
353aa0a
Fix isHostRuntime call
mrousavy Mar 5, 2021
f1d86e0
Fix RNVERSION preprocessor macros
mrousavy Mar 5, 2021
ea7f2bd
Upgrade to RN 64-rc4
mrousavy Mar 5, 2021
3b74051
Set iOS deployment target to 11.0
mrousavy Mar 5, 2021
cb5da12
Remove folly from podspec
mrousavy Mar 5, 2021
8cf1513
Remove NativeReanimatedModule reference from RemoteObject
mrousavy Mar 5, 2021
18a1f14
Revert "Remove NativeReanimatedModule reference from RemoteObject"
mrousavy Mar 5, 2021
a348164
Remove unreachable code
mrousavy Mar 5, 2021
1cdb5c9
Explicitly pass members
mrousavy Mar 5, 2021
5564f7b
Revert "Explicitly pass members"
mrousavy Mar 5, 2021
45c6613
(1/2) Create RuntimeManager.h inteface
mrousavy Mar 5, 2021
1635bce
Podspec: Bump to iOS 10
mrousavy Mar 5, 2021
2337221
(2/2) Use RuntimeManager.h interface
mrousavy Mar 5, 2021
3e54b17
Fix block scoped NativeReanimatedModule
mrousavy Mar 8, 2021
ebc07d8
Make WorkletsCache static
mrousavy Mar 8, 2021
5e7a2a1
Let Mapper use NativeReanimatedModule again
mrousavy Mar 8, 2021
1368fac
Use Scheduler::setRuntimeManager
mrousavy Mar 8, 2021
7fc83c7
Remove unused RuntimeManager*
mrousavy Mar 8, 2021
0867beb
Make worklets from WorkletsCache static
mrousavy Mar 9, 2021
def0998
Make runtime unique_ptr
mrousavy Mar 10, 2021
4f6b7a9
REAIOSScheduler: Use make_shared for faster allocation
mrousavy Mar 10, 2021
092d0f3
AndroidErrorHandler: Use make_shared for faster allocation
mrousavy Mar 10, 2021
882d73f
Create NativeReanimatedModule::instance singleton
mrousavy Mar 10, 2021
c4d3ad3
Add RuntimeDecorator::decorateRuntime
mrousavy Mar 10, 2021
0869362
isUIRuntime -> isWorkletRuntime
mrousavy Mar 11, 2021
f0f203d
Remove NativeReanimatedModule::instance
mrousavy Mar 11, 2021
2438aa6
Update WorkletsCache.cpp
mrousavy Mar 11, 2021
61584b0
Make WorkletsCache a RuntimeManager class member
mrousavy Mar 11, 2021
a4929e7
NativeReanimatedModule: Remove dangling WorkletsCache
mrousavy Mar 11, 2021
526c18f
Babel plugin: Also transform `useFrameProcessor`
mrousavy Mar 11, 2021
a9608be
Decorate Runtime with `_LABEL`
mrousavy Mar 16, 2021
6b870ac
RuntimeDecorator: Correctly set global
mrousavy Mar 16, 2021
330f2fd
Polyfill performance.now() with chrono::time_since_epoch
mrousavy Mar 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,25 @@ NativeReanimatedModule::NativeReanimatedModule(std::shared_ptr<CallInvoker> jsIn
std::unique_ptr<jsi::Runtime> rt,
std::shared_ptr<ErrorHandler> errorHandler,
std::function<jsi::Value(jsi::Runtime &, const int, const jsi::String &)> propObtainer,
PlatformDepMethodsHolder platformDepMethodsHolder) : NativeReanimatedModuleSpec(jsInvoker),
runtime(std::move(rt)),
PlatformDepMethodsHolder platformDepMethodsHolder) :
NativeReanimatedModuleSpec(jsInvoker),
RuntimeManager(std::move(rt), errorHandler, scheduler),
mapperRegistry(new MapperRegistry()),
eventHandlerRegistry(new EventHandlerRegistry()),
requestRender(platformDepMethodsHolder.requestRender),
propObtainer(propObtainer),
errorHandler(errorHandler),
workletsCache(new WorkletsCache()),
scheduler(scheduler)
propObtainer(propObtainer)
{
auto requestAnimationFrame = [=](FrameCallback callback) {
frameCallbacks.push_back(callback);
maybeRequestRender();
};

RuntimeDecorator::addNativeObjects(*runtime,
platformDepMethodsHolder.updaterFunction,
requestAnimationFrame,
platformDepMethodsHolder.scrollToFunction,
platformDepMethodsHolder.measuringFunction,
platformDepMethodsHolder.getCurrentTime);
}

bool NativeReanimatedModule::isUIRuntime(jsi::Runtime &rt)
{
return runtime.get() == &rt;
}

bool NativeReanimatedModule::isHostRuntime(jsi::Runtime &rt)
{
return !isUIRuntime(rt);
RuntimeDecorator::decorateUIRuntime(*runtime,
platformDepMethodsHolder.updaterFunction,
requestAnimationFrame,
platformDepMethodsHolder.scrollToFunction,
platformDepMethodsHolder.measuringFunction,
platformDepMethodsHolder.getCurrentTime);
}

void NativeReanimatedModule::installCoreFunctions(jsi::Runtime &rt, const jsi::Value &valueSetter)
Expand Down
5 changes: 3 additions & 2 deletions Common/cpp/SharedItems/FrozenObject.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "FrozenObject.h"
#include "SharedParent.h"
#include "ShareableValue.h"
#include "RuntimeManager.h"

namespace reanimated {

FrozenObject::FrozenObject(jsi::Runtime &rt, const jsi::Object &object, NativeReanimatedModule *module) {
FrozenObject::FrozenObject(jsi::Runtime &rt, const jsi::Object &object, RuntimeManager *runtimeManager) {
auto propertyNames = object.getPropertyNames(rt);
for (size_t i = 0, count = propertyNames.size(rt); i < count; i++) {
auto propertyName = propertyNames.getValueAtIndex(rt, i).asString(rt);
std::string nameStr = propertyName.utf8(rt);
map[nameStr] = ShareableValue::adapt(rt, object.getProperty(rt, propertyName), module);
map[nameStr] = ShareableValue::adapt(rt, object.getProperty(rt, propertyName), runtimeManager);
this->containsHostFunction |= map[nameStr]->containsHostFunction;
}
}
Expand Down
33 changes: 17 additions & 16 deletions Common/cpp/SharedItems/MutableValue.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#include "MutableValue.h"
#include "SharedParent.h"
#include "ShareableValue.h"
#include "NativeReanimatedModule.h"
#include "RuntimeManager.h"
#include "RuntimeDecorator.h"

namespace reanimated {

void MutableValue::setValue(jsi::Runtime &rt, const jsi::Value &newValue) {
std::lock_guard<std::mutex> lock(readWriteMutex);
value = ShareableValue::adapt(rt, newValue, module);
value = ShareableValue::adapt(rt, newValue, runtimeManager);

std::shared_ptr<MutableValue> thiz = shared_from_this();
auto notifyListeners = [thiz] () {
for (auto listener : thiz->listeners) {
listener.second();
}
};
if (module->isUIRuntime(rt)) {

if (RuntimeDecorator::isWorkletRuntime(rt)) {
notifyListeners();
} else {
module->scheduler->scheduleOnUI([notifyListeners] {
runtimeManager->scheduler->scheduleOnUI([notifyListeners] {
notifyListeners();
});
}
}
}

jsi::Value MutableValue::getValue(jsi::Runtime &rt) {
Expand All @@ -33,14 +34,14 @@ jsi::Value MutableValue::getValue(jsi::Runtime &rt) {
void MutableValue::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &newValue) {
auto propName = name.utf8(rt);

if (module->isHostRuntime(rt)) {
if (RuntimeDecorator::isReactRuntime(rt)) {
if (propName == "value") {
auto shareable = ShareableValue::adapt(rt, newValue, module);
module->scheduler->scheduleOnUI([this, shareable] {
jsi::Runtime &rt = *this->module->runtime.get();
auto shareable = ShareableValue::adapt(rt, newValue, runtimeManager);
runtimeManager->scheduler->scheduleOnUI([this, shareable] {
jsi::Runtime &rt = *this->runtimeManager->runtime.get();
auto setterProxy = jsi::Object::createFromHostObject(rt, std::make_shared<MutableValueSetterProxy>(shared_from_this()));
jsi::Value newValue = shareable->getValue(rt);
module->valueSetter->getValue(rt)
runtimeManager->valueSetter->getValue(rt)
.asObject(rt)
.asFunction(rt)
.callWithThis(rt, setterProxy, newValue);
Expand All @@ -52,7 +53,7 @@ void MutableValue::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi:
// UI thread
if (propName == "value") {
auto setterProxy = jsi::Object::createFromHostObject(rt, std::make_shared<MutableValueSetterProxy>(shared_from_this()));
module->valueSetter->getValue(rt)
runtimeManager->valueSetter->getValue(rt)
.asObject(rt)
.asFunction(rt)
.callWithThis(rt, setterProxy, newValue);
Expand All @@ -72,7 +73,7 @@ jsi::Value MutableValue::get(jsi::Runtime &rt, const jsi::PropNameID &name) {
return getValue(rt);
}

if (module->isUIRuntime(rt)) {
if (RuntimeDecorator::isWorkletRuntime(rt)) {
// _value and _animation should be accessed from UI only
if (propName == "_value") {
return getValue(rt);
Expand All @@ -94,8 +95,8 @@ std::vector<jsi::PropNameID> MutableValue::getPropertyNames(jsi::Runtime &rt) {
return result;
}

MutableValue::MutableValue(jsi::Runtime &rt, const jsi::Value &initial, NativeReanimatedModule *module, std::shared_ptr<Scheduler> s):
StoreUser(s), module(module), value(ShareableValue::adapt(rt, initial, module)) {
MutableValue::MutableValue(jsi::Runtime &rt, const jsi::Value &initial, RuntimeManager *runtimeManager, std::shared_ptr<Scheduler> s):
StoreUser(s), runtimeManager(runtimeManager), value(ShareableValue::adapt(rt, initial, runtimeManager)) {
}

unsigned long int MutableValue::addListener(unsigned long id, std::function<void ()> listener) {
Expand Down
6 changes: 3 additions & 3 deletions Common/cpp/SharedItems/RemoteObject.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "RemoteObject.h"
#include "SharedParent.h"
#include "NativeReanimatedModule.h"
#include "RuntimeDecorator.h"
#include <jsi/jsi.h>

using namespace facebook;
Expand All @@ -16,14 +16,14 @@ void RemoteObject::maybeInitializeOnUIRuntime(jsi::Runtime &rt) {
}

jsi::Value RemoteObject::get(jsi::Runtime &rt, const jsi::PropNameID &name) {
if (module->isUIRuntime(rt)) {
if (RuntimeDecorator::isWorkletRuntime(rt)) {
return backing.lock()->getObject(rt).getProperty(rt, name);
}
return jsi::Value::undefined();
}

void RemoteObject::set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value) {
if (module->isUIRuntime(rt)) {
if (RuntimeDecorator::isWorkletRuntime(rt)) {
backing.lock()->getObject(rt).setProperty(rt, name, value);
}
// TODO: we should throw if trying to update remote from host runtime
Expand Down
Loading