Skip to content

Commit

Permalink
Fabric: A bunch of functions for converting JSI primitives to Fabric …
Browse files Browse the repository at this point in the history
…and vice-versa

Summary: We need to decouple this from actual JSI/UIManagerBinding implementation to make them more maintainable.

Reviewed By: sahrens

Differential Revision: D12876742

fbshipit-source-id: 30cad69d0a9761e2aa82f31d180e4b5a40cedb61
  • Loading branch information
shergin authored and facebook-github-bot committed Nov 6, 2018
1 parent 6c5b8c6 commit b9f9f32
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions ReactCommon/fabric/uimanager/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,65 @@ struct ShadowNodeListWrapper : public jsi::HostObject {
SharedShadowNodeUnsharedList shadowNodeList;
};

inline static SharedShadowNode shadowNodeFromValue(
jsi::Runtime &runtime,
const jsi::Value &value) {
return value.getObject(runtime)
.getHostObject<ShadowNodeWrapper>(runtime)
->shadowNode;
}

inline static jsi::Value valueFromShadowNode(
jsi::Runtime &runtime,
const SharedShadowNode &shadowNode) {
return jsi::Object::createFromHostObject(
runtime, std::make_shared<ShadowNodeWrapper>(shadowNode));
}

inline static SharedShadowNodeUnsharedList shadowNodeListFromValue(
jsi::Runtime &runtime,
const jsi::Value &value) {
return value.getObject(runtime)
.getHostObject<ShadowNodeListWrapper>(runtime)
->shadowNodeList;
}

inline static jsi::Value valueFromShadowNodeList(
jsi::Runtime &runtime,
const SharedShadowNodeUnsharedList &shadowNodeList) {
return jsi::Object::createFromHostObject(
runtime, std::make_unique<ShadowNodeListWrapper>(shadowNodeList));
}

inline static RawProps rawPropsFromValue(
jsi::Runtime &runtime,
const jsi::Value &value) {
return rawPropsFromDynamic(folly::dynamic{
value.isNull() ? nullptr : jsi::dynamicFromValue(runtime, value)});
}

inline static SharedEventTarget eventTargetFromValue(
jsi::Runtime &runtime,
const jsi::Value &value) {
return std::make_shared<EventTargetWrapper>(
jsi::WeakObject(runtime, value.getObject(runtime)));
}

inline static Tag tagFromValue(jsi::Runtime &runtime, const jsi::Value &value) {
return (Tag)value.getNumber();
}

inline static SurfaceId surfaceIdFromValue(
jsi::Runtime &runtime,
const jsi::Value &value) {
return (SurfaceId)value.getNumber();
}

inline static ComponentName componentNameFromValue(
jsi::Runtime &runtime,
const jsi::Value &value) {
return value.getString(runtime).utf8(runtime);
}

} // namespace react
} // namespace facebook

0 comments on commit b9f9f32

Please sign in to comment.