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;
|
||||
}
|
||||
|
||||
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) {
|
||||
folly::dynamic result = folly::dynamic::object();
|
||||
result["type"] = 3;
|
||||
|
@ -77,9 +109,8 @@ inline folly::dynamic toDynamic(Text const &text) {
|
|||
result["strokeWidth"] = text.strokeWidth;
|
||||
result["strokeCap"] = text.strokeCap;
|
||||
result["strokeJoin"] = text.strokeJoin;
|
||||
result["aligment"] = text.aligment;
|
||||
// TODO T64130144: add serialization of Frame
|
||||
// result["aligment"] = toDynamic(text.frame);
|
||||
result["alignment"] = toDynamic(text.alignment);
|
||||
result["frame"] = toDynamic(text.frame);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace facebook {
|
|||
namespace react {
|
||||
|
||||
#ifdef ANDROID
|
||||
folly::dynamic Shape::getDynamic() const {
|
||||
folly::dynamic Text::getDynamic() const {
|
||||
return toDynamic(*this);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -24,14 +24,35 @@ namespace react {
|
|||
class Text : public Shape {
|
||||
public:
|
||||
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;
|
||||
virtual ~Text(){};
|
||||
|
||||
int aligment{0};
|
||||
|
||||
// TODO T64130144: add frame data
|
||||
// ARTTextFrame frame{}
|
||||
ARTTextAlignment alignment{ARTTextAlignment::Default};
|
||||
ARTTextFrame frame{};
|
||||
|
||||
#ifdef ANDROID
|
||||
folly::dynamic getDynamic() const override;
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <react/graphics/Geometry.h>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
|
|
@ -33,11 +33,8 @@ ARTTextProps::ARTTextProps(
|
|||
convertRawProp(rawProps, "strokeCap", sourceProps.strokeCap, {1})),
|
||||
strokeJoin(
|
||||
convertRawProp(rawProps, "strokeJoin", sourceProps.strokeJoin, {1})),
|
||||
aligment(convertRawProp(
|
||||
rawProps,
|
||||
"aligment",
|
||||
sourceProps.aligment,
|
||||
{ARTTextAlignment::Default})),
|
||||
alignment(
|
||||
convertRawProp(rawProps, "alignment", sourceProps.alignment, {})),
|
||||
frame(convertRawProp(rawProps, "frame", sourceProps.frame, {})){};
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
|
|
@ -20,6 +20,22 @@ static inline void fromRawValue(
|
|||
const RawValue &value,
|
||||
ARTTextFrameFont &result) {
|
||||
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(
|
||||
|
@ -80,7 +96,7 @@ class ARTTextProps : public Props {
|
|||
Float strokeWidth{1.0};
|
||||
int strokeCap{1};
|
||||
int strokeJoin{1};
|
||||
ARTTextAlignment aligment{ARTTextAlignment::Default};
|
||||
ARTTextAlignment alignment{ARTTextAlignment::Default};
|
||||
ARTTextFrame frame{};
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
|
|
@ -15,8 +15,19 @@ namespace react {
|
|||
extern const char ARTTextComponentName[] = "ARTText";
|
||||
|
||||
Element::Shared ARTTextShadowNode::getElement() const {
|
||||
// TODO add support for Text
|
||||
return std::make_shared<Shape>();
|
||||
auto props = getConcreteProps();
|
||||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче