Serialize ART text components and send data to Android
Summary: This diff implements the serialization of Text components to send data from C++ to java changelog: [Internal] internal changes to support ART in fabric Reviewed By: JoshuaGross Differential Revision: D21681875 fbshipit-source-id: eba31f35c95e0a2d3226ec70421832719083d7fa
This commit is contained in:
Родитель
888866461b
Коммит
b8b683dc46
|
@ -65,6 +65,38 @@ inline folly::dynamic toDynamic(Shape const &shape) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline folly::dynamic toDynamic(ARTTextAlignment const &aligment) {
|
||||||
|
switch (aligment) {
|
||||||
|
case ARTTextAlignment::Right:
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
case ARTTextAlignment::Center:
|
||||||
|
return 2;
|
||||||
|
break;
|
||||||
|
case ARTTextAlignment::Default:
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline folly::dynamic toDynamic(ARTTextFrame const &frame) {
|
||||||
|
folly::dynamic result = folly::dynamic::object();
|
||||||
|
result["fontSize"] = frame.font.fontSize;
|
||||||
|
result["fontStyle"] = frame.font.fontStyle;
|
||||||
|
result["fontFamily"] = frame.font.fontFamily;
|
||||||
|
result["fontWeight"] = frame.font.fontWeight;
|
||||||
|
auto lines = frame.lines;
|
||||||
|
if (lines.size() > 0) {
|
||||||
|
folly::dynamic serializedLines = folly::dynamic::array();
|
||||||
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
|
serializedLines.push_back(lines[i]);
|
||||||
|
}
|
||||||
|
result["lines"] = serializedLines;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
inline folly::dynamic toDynamic(Text const &text) {
|
inline folly::dynamic toDynamic(Text const &text) {
|
||||||
folly::dynamic result = folly::dynamic::object();
|
folly::dynamic result = folly::dynamic::object();
|
||||||
result["type"] = 3;
|
result["type"] = 3;
|
||||||
|
@ -77,9 +109,8 @@ inline folly::dynamic toDynamic(Text const &text) {
|
||||||
result["strokeWidth"] = text.strokeWidth;
|
result["strokeWidth"] = text.strokeWidth;
|
||||||
result["strokeCap"] = text.strokeCap;
|
result["strokeCap"] = text.strokeCap;
|
||||||
result["strokeJoin"] = text.strokeJoin;
|
result["strokeJoin"] = text.strokeJoin;
|
||||||
result["aligment"] = text.aligment;
|
result["alignment"] = toDynamic(text.alignment);
|
||||||
// TODO T64130144: add serialization of Frame
|
result["frame"] = toDynamic(text.frame);
|
||||||
// result["aligment"] = toDynamic(text.frame);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
folly::dynamic Shape::getDynamic() const {
|
folly::dynamic Text::getDynamic() const {
|
||||||
return toDynamic(*this);
|
return toDynamic(*this);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,14 +24,35 @@ namespace react {
|
||||||
class Text : public Shape {
|
class Text : public Shape {
|
||||||
public:
|
public:
|
||||||
using Shared = std::shared_ptr<const Text>;
|
using Shared = std::shared_ptr<const Text>;
|
||||||
Text(ARTElement elementType) : Shape(){};
|
Text(
|
||||||
|
Float opacity,
|
||||||
|
std::vector<Float> transform,
|
||||||
|
std::vector<Float> d,
|
||||||
|
std::vector<Float> stroke,
|
||||||
|
std::vector<Float> strokeDash,
|
||||||
|
std::vector<Float> fill,
|
||||||
|
Float strokeWidth,
|
||||||
|
int strokeCap,
|
||||||
|
int strokeJoin,
|
||||||
|
ARTTextAlignment alignment,
|
||||||
|
ARTTextFrame frame)
|
||||||
|
: Shape(
|
||||||
|
opacity,
|
||||||
|
transform,
|
||||||
|
d,
|
||||||
|
stroke,
|
||||||
|
strokeDash,
|
||||||
|
fill,
|
||||||
|
strokeWidth,
|
||||||
|
strokeCap,
|
||||||
|
strokeJoin),
|
||||||
|
alignment(alignment),
|
||||||
|
frame(frame){};
|
||||||
Text() = default;
|
Text() = default;
|
||||||
virtual ~Text(){};
|
virtual ~Text(){};
|
||||||
|
|
||||||
int aligment{0};
|
ARTTextAlignment alignment{ARTTextAlignment::Default};
|
||||||
|
ARTTextFrame frame{};
|
||||||
// TODO T64130144: add frame data
|
|
||||||
// ARTTextFrame frame{}
|
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
folly::dynamic getDynamic() const override;
|
folly::dynamic getDynamic() const override;
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <react/graphics/Geometry.h>
|
#include <react/graphics/Geometry.h>
|
||||||
#include <vector>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
|
@ -33,11 +33,8 @@ ARTTextProps::ARTTextProps(
|
||||||
convertRawProp(rawProps, "strokeCap", sourceProps.strokeCap, {1})),
|
convertRawProp(rawProps, "strokeCap", sourceProps.strokeCap, {1})),
|
||||||
strokeJoin(
|
strokeJoin(
|
||||||
convertRawProp(rawProps, "strokeJoin", sourceProps.strokeJoin, {1})),
|
convertRawProp(rawProps, "strokeJoin", sourceProps.strokeJoin, {1})),
|
||||||
aligment(convertRawProp(
|
alignment(
|
||||||
rawProps,
|
convertRawProp(rawProps, "alignment", sourceProps.alignment, {})),
|
||||||
"aligment",
|
|
||||||
sourceProps.aligment,
|
|
||||||
{ARTTextAlignment::Default})),
|
|
||||||
frame(convertRawProp(rawProps, "frame", sourceProps.frame, {})){};
|
frame(convertRawProp(rawProps, "frame", sourceProps.frame, {})){};
|
||||||
|
|
||||||
#pragma mark - DebugStringConvertible
|
#pragma mark - DebugStringConvertible
|
||||||
|
|
|
@ -20,6 +20,22 @@ static inline void fromRawValue(
|
||||||
const RawValue &value,
|
const RawValue &value,
|
||||||
ARTTextFrameFont &result) {
|
ARTTextFrameFont &result) {
|
||||||
auto map = (better::map<std::string, RawValue>)value;
|
auto map = (better::map<std::string, RawValue>)value;
|
||||||
|
auto fontSize = map.find("fontSize");
|
||||||
|
if (fontSize != map.end()) {
|
||||||
|
fromRawValue(fontSize->second, result.fontSize);
|
||||||
|
}
|
||||||
|
auto fontStyle = map.find("fontStyle");
|
||||||
|
if (fontStyle != map.end()) {
|
||||||
|
fromRawValue(fontStyle->second, result.fontStyle);
|
||||||
|
}
|
||||||
|
auto fontFamily = map.find("fontFamily");
|
||||||
|
if (fontFamily != map.end()) {
|
||||||
|
fromRawValue(fontFamily->second, result.fontFamily);
|
||||||
|
}
|
||||||
|
auto fontWeight = map.find("fontWeight");
|
||||||
|
if (fontWeight != map.end()) {
|
||||||
|
fromRawValue(fontWeight->second, result.fontWeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void fromRawValue(
|
static inline void fromRawValue(
|
||||||
|
@ -80,7 +96,7 @@ class ARTTextProps : public Props {
|
||||||
Float strokeWidth{1.0};
|
Float strokeWidth{1.0};
|
||||||
int strokeCap{1};
|
int strokeCap{1};
|
||||||
int strokeJoin{1};
|
int strokeJoin{1};
|
||||||
ARTTextAlignment aligment{ARTTextAlignment::Default};
|
ARTTextAlignment alignment{ARTTextAlignment::Default};
|
||||||
ARTTextFrame frame{};
|
ARTTextFrame frame{};
|
||||||
|
|
||||||
#pragma mark - DebugStringConvertible
|
#pragma mark - DebugStringConvertible
|
||||||
|
|
|
@ -15,8 +15,19 @@ namespace react {
|
||||||
extern const char ARTTextComponentName[] = "ARTText";
|
extern const char ARTTextComponentName[] = "ARTText";
|
||||||
|
|
||||||
Element::Shared ARTTextShadowNode::getElement() const {
|
Element::Shared ARTTextShadowNode::getElement() const {
|
||||||
// TODO add support for Text
|
auto props = getConcreteProps();
|
||||||
return std::make_shared<Shape>();
|
return std::make_shared<Text>(
|
||||||
|
props.opacity,
|
||||||
|
props.transform,
|
||||||
|
props.d,
|
||||||
|
props.stroke,
|
||||||
|
props.strokeDash,
|
||||||
|
props.fill,
|
||||||
|
props.strokeWidth,
|
||||||
|
props.strokeCap,
|
||||||
|
props.strokeJoin,
|
||||||
|
props.alignment,
|
||||||
|
props.frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace react
|
} // namespace react
|
||||||
|
|
Загрузка…
Ссылка в новой задаче