Fabric: A bunch of functions for converting JSI primitives to Fabric 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
This commit is contained in:
Valentin Shergin 2018-11-06 10:58:51 -08:00 committed by Facebook Github Bot
parent 6c5b8c603b
commit b9f9f3284e
1 changed files with 60 additions and 0 deletions

View File

@ -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