React Native JSI Challenge #2

Background

Implementation

The binding object

class JSI_EXPORT REAJsiModule : public jsi::HostObject {public:
REAJsiModule(REAModule* reaModule);
static void install(REAModule *reaModule);
jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name)
override;
private:
REAModule* reamodule_;
};
- (void)setBridge:(RCTBridge *)bridge
{
[super setBridge:bridge];
...

REAJsiModule::install(self);
}
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)reaModule.bridge;
if (cxxBridge.runtime == nullptr) {
return;
}
jsi::Runtime &runtime = *(jsi::Runtime *)cxxBridge.runtime;
auto reaModuleName = “Reanimated”;
auto reaJsiModule = std::make_shared<REAJsiModule>(std::move(reaModule));
auto object = jsi::Object::createFromHostObject(runtime, reaJsiModule);
runtime.global().setProperty(runtime, reaModuleName, std::move(object));
if (methodName == “dropNode”) {
REAModule* reamodule = reamodule_;
return jsi::Function::createFromHostFunction(runtime, name, 1,
[reamodule](jsi::Runtime &runtime,
const jsi::Value &thisValue,
const jsi::Value *arguments,
size_t count) -> jsi::Value {
auto arg1 = &arguments[0];
[reamodule dropNode:
[NSNumber numberWithDouble:arg1->asNumber()]];
return jsi::Value::undefined();
});
}

Threads and queues

Wrapping up

What about Android?

References

--

--

--

Cross Platform Developer — Co-founder of Fram X

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kogito Tooling Examples —How to create a more complex custom View

Different Types of React Components

The WebSockets Adventure

The event loop

Understanding Change Detection Strategies in Angular

Identify JavaScript Data Types: Two Methods are Enough

Understanding Typescript Distributive Conditional Types with a Source Code Debugging Approach

Comparison of different unit testing frameworks in JavaScript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Christian Falch

Christian Falch

Cross Platform Developer — Co-founder of Fram X

More from Medium

Handle Events in React Native (Button and textInput)

React Native #1

Twilio Conversations API with React Native

React Native 참고 사이트 모음(feat.Firebase)