Refactor types of ART Text class

Summary:
This diff refactors the types of ART Text classes, this is necessary on the next diffs of the stack

closeoncommit

changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D21681876

fbshipit-source-id: ea438e89df6d860b3ff8bbdae657ca123b417a1b
This commit is contained in:
David Vacca
2020-05-22 01:23:36 -07:00
committed by Facebook GitHub Bot
parent b7e8f66795
commit 888866461b
5 changed files with 49 additions and 41 deletions
@@ -30,6 +30,7 @@ inline folly::dynamic toDynamic(std::vector<Float> const &elements) {
}
return result;
}
inline folly::dynamic toDynamic(Element::ListOfShared const &elements) {
folly::dynamic children = folly::dynamic::array();
for (auto const &element : elements) {
@@ -31,7 +31,7 @@ class Text : public Shape {
int aligment{0};
// TODO T64130144: add frame data
// ARTTextFrameStruct frame{}
// ARTTextFrame frame{}
#ifdef ANDROID
folly::dynamic getDynamic() const override;
@@ -7,6 +7,8 @@
#pragma once
#include <react/graphics/Geometry.h>
#include <vector>
#include <functional>
#include <limits>
@@ -15,5 +17,19 @@ namespace react {
enum class ARTElement { Shape, Text, Group };
enum class ARTTextAlignment { Default, Right, Center };
struct ARTTextFrameFont {
Float fontSize;
std::string fontStyle;
std::string fontFamily;
std::string fontWeight;
};
struct ARTTextFrame {
std::vector<std::string> lines;
ARTTextFrameFont font;
};
} // namespace react
} // namespace facebook
@@ -33,7 +33,11 @@ ARTTextProps::ARTTextProps(
convertRawProp(rawProps, "strokeCap", sourceProps.strokeCap, {1})),
strokeJoin(
convertRawProp(rawProps, "strokeJoin", sourceProps.strokeJoin, {1})),
aligment(convertRawProp(rawProps, "aligment", sourceProps.aligment, {0})),
aligment(convertRawProp(
rawProps,
"aligment",
sourceProps.aligment,
{ARTTextAlignment::Default})),
frame(convertRawProp(rawProps, "frame", sourceProps.frame, {})){};
#pragma mark - DebugStringConvertible
@@ -7,6 +7,7 @@
#pragma once
#include <react/components/art/primitives.h>
#include <react/components/view/ViewProps.h>
#include <react/core/propsConversions.h>
#include <react/graphics/Color.h>
@@ -15,48 +16,34 @@
namespace facebook {
namespace react {
struct ARTTextFrameFontStruct {
Float fontSize;
std::string fontStyle;
std::string fontFamily;
std::string fontWeight;
};
static inline void fromRawValue(
const RawValue &value,
ARTTextFrameFontStruct &result) {
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 std::string toString(const ARTTextFrameFontStruct &value) {
return "[Object ARTTextFrameFontStruct]";
}
struct ARTTextFrameStruct {
std::vector<std::string> lines;
ARTTextFrameFontStruct font;
};
static inline void fromRawValue(
const RawValue &value,
ARTTextFrameStruct &result) {
ARTTextAlignment &result) {
auto alignment = (int)value;
switch (alignment) {
case 1:
result = ARTTextAlignment::Right;
break;
case 2:
result = ARTTextAlignment::Center;
break;
default:
result = ARTTextAlignment::Default;
break;
}
}
static inline std::string toString(const ARTTextFrameFont &value) {
return "[Object ARTTextFrameFont]";
}
static inline void fromRawValue(const RawValue &value, ARTTextFrame &result) {
auto map = (better::map<std::string, RawValue>)value;
auto lines = map.find("lines");
@@ -69,8 +56,8 @@ static inline void fromRawValue(
}
}
static inline std::string toString(const ARTTextFrameStruct &value) {
return "[Object ARTTextFrameStruct]";
static inline std::string toString(const ARTTextFrame &value) {
return "[Object ARTTextFrame]";
}
class ARTTextProps;
@@ -93,8 +80,8 @@ class ARTTextProps : public Props {
Float strokeWidth{1.0};
int strokeCap{1};
int strokeJoin{1};
int aligment{0};
ARTTextFrameStruct frame{};
ARTTextAlignment aligment{ARTTextAlignment::Default};
ARTTextFrame frame{};
#pragma mark - DebugStringConvertible