Fabric/Text: <Paragraph> is now supporting text attributes
Summary: I was shamed by Sebastian's sebmarkbage concerns (totally unrelated to this topic) about introducing another level of indirection into the system and decided to change my original plan not to support text attributes for the <Paragraph> component. So, now <Paragraph> shares <View>, <Text> and <Paragraph> itself capabilities. That reduces the minimum amount of required components for trivial text fragment from three (Paragraph, Text, RawText) to two (Paragraph and RawText). Special thanks for C++ for supporting multiple inheritance. Reviewed By: mdvacca Differential Revision: D7785889 fbshipit-source-id: dd9f2e2650bfbfd76d7d4b538adaf409f9429df3
This commit is contained in:
parent
9ea7957958
commit
d9ff1769aa
|
@ -1,5 +1,5 @@
|
|||
load("//configurations/buck/apple:flag_defs.bzl", "get_debug_preprocessor_flags")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "react_native_xplat_target", "rn_xplat_cxx_library", "get_apple_inspector_flags", "APPLE")
|
||||
load("//configurations/buck/apple:flag_defs.bzl", "get_application_ios_flags", "get_debug_preprocessor_flags", "OBJC_ARC_PREPROCESSOR_FLAGS")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "rn_xplat_cxx_library", "get_apple_inspector_flags", "react_native_xplat_target", "ANDROID", "APPLE")
|
||||
|
||||
APPLE_COMPILER_FLAGS = []
|
||||
|
||||
|
@ -37,6 +37,7 @@ rn_xplat_cxx_library(
|
|||
],
|
||||
force_static = True,
|
||||
macosx_tests_override = [],
|
||||
platforms = (ANDROID, APPLE),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
load("//configurations/buck/apple:flag_defs.bzl", "get_debug_preprocessor_flags")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "react_native_xplat_target", "rn_xplat_cxx_library", "get_apple_inspector_flags", "APPLE")
|
||||
load("//configurations/buck/apple:flag_defs.bzl", "get_application_ios_flags", "get_debug_preprocessor_flags", "OBJC_ARC_PREPROCESSOR_FLAGS")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "rn_xplat_cxx_library", "get_apple_inspector_flags", "react_native_xplat_target", "ANDROID", "APPLE")
|
||||
|
||||
APPLE_COMPILER_FLAGS = []
|
||||
|
||||
|
@ -40,6 +40,7 @@ rn_xplat_cxx_library(
|
|||
],
|
||||
force_static = True,
|
||||
macosx_tests_override = [],
|
||||
platforms = (ANDROID, APPLE),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
load("@xplat//configurations/buck/apple:flag_defs.bzl", "get_debug_preprocessor_flags")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "react_native_xplat_target", "rn_xplat_cxx_library", "get_apple_inspector_flags", "APPLE")
|
||||
load("//configurations/buck/apple:flag_defs.bzl", "get_application_ios_flags", "get_debug_preprocessor_flags", "OBJC_ARC_PREPROCESSOR_FLAGS")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "rn_xplat_cxx_library", "get_apple_inspector_flags", "react_native_xplat_target", "ANDROID", "APPLE")
|
||||
|
||||
APPLE_COMPILER_FLAGS = []
|
||||
|
||||
if not IS_OSS_BUILD:
|
||||
load("@xplat//configurations/buck/apple:flag_defs.bzl", "get_static_library_ios_flags", "flags")
|
||||
APPLE_COMPILER_FLAGS = flags.get_flag_value(get_static_library_ios_flags(), "compiler_flags")
|
||||
APPLE_COMPILER_FLAGS = flags.get_flag_value(get_static_library_ios_flags(), 'compiler_flags')
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "debug",
|
||||
|
@ -37,6 +37,7 @@ rn_xplat_cxx_library(
|
|||
],
|
||||
force_static = True,
|
||||
macosx_tests_override = [],
|
||||
platforms = (ANDROID, APPLE),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
|
@ -44,7 +45,10 @@ rn_xplat_cxx_library(
|
|||
tests = [],
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
"xplat//fbsystrace:fbsystrace",
|
||||
"xplat//folly:headers_only",
|
||||
"xplat//folly:memory",
|
||||
"xplat//folly:molly",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
load("//configurations/buck/apple:flag_defs.bzl", "get_debug_preprocessor_flags")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "react_native_xplat_target", "rn_xplat_cxx_library", "get_apple_inspector_flags", "APPLE")
|
||||
load("//configurations/buck/apple:flag_defs.bzl", "get_application_ios_flags", "get_debug_preprocessor_flags", "OBJC_ARC_PREPROCESSOR_FLAGS")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "rn_xplat_cxx_library", "get_apple_inspector_flags", "react_native_xplat_target", "ANDROID", "APPLE")
|
||||
|
||||
APPLE_COMPILER_FLAGS = []
|
||||
|
||||
|
@ -25,10 +25,10 @@ rn_xplat_cxx_library(
|
|||
prefix = "fabric/graphics",
|
||||
),
|
||||
compiler_flags = [
|
||||
"-std=c++14",
|
||||
"-Wall",
|
||||
"-fexceptions",
|
||||
"-frtti",
|
||||
"-std=c++14",
|
||||
"-Wall",
|
||||
],
|
||||
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
|
||||
fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(),
|
||||
|
@ -36,7 +36,13 @@ rn_xplat_cxx_library(
|
|||
":tests",
|
||||
],
|
||||
force_static = True,
|
||||
frameworks = [
|
||||
"$SDKROOT/System/Library/Frameworks/CoreGraphics.framework",
|
||||
"$SDKROOT/System/Library/Frameworks/Foundation.framework",
|
||||
"$SDKROOT/System/Library/Frameworks/UIKit.framework",
|
||||
],
|
||||
macosx_tests_override = [],
|
||||
platforms = (ANDROID, APPLE),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
|
|
|
@ -21,6 +21,7 @@ rn_xplat_cxx_library(
|
|||
exported_headers = subdir_glob(
|
||||
[
|
||||
("", "*.h"),
|
||||
("basetext", "*.h"),
|
||||
("paragraph", "*.h"),
|
||||
("text", "*.h"),
|
||||
("rawtext", "*.h"),
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "BaseTextProps.h"
|
||||
|
||||
#include <fabric/attributedstring/textValuesConversions.h>
|
||||
#include <fabric/core/propsConversions.h>
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
#include <fabric/graphics/graphicValuesConversions.h>
|
||||
#include <fabric/text/propsConversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
void BaseTextProps::apply(const RawProps &rawProps) {
|
||||
// Color
|
||||
applyRawProp(rawProps, "color", textAttributes_.foregroundColor);
|
||||
applyRawProp(rawProps, "backgroundColor", textAttributes_.backgroundColor);
|
||||
applyRawProp(rawProps, "opacity", textAttributes_.opacity);
|
||||
|
||||
// Font
|
||||
applyRawProp(rawProps, "fontFamily", textAttributes_.fontFamily);
|
||||
applyRawProp(rawProps, "fontSize", textAttributes_.fontSize);
|
||||
applyRawProp(rawProps, "fontSizeMultiplier", textAttributes_.fontSizeMultiplier);
|
||||
applyRawProp(rawProps, "fontWeight", textAttributes_.fontWeight);
|
||||
applyRawProp(rawProps, "fontStyle", textAttributes_.fontStyle);
|
||||
applyRawProp(rawProps, "fontVariant", textAttributes_.fontVariant);
|
||||
applyRawProp(rawProps, "allowFontScaling", textAttributes_.allowFontScaling);
|
||||
applyRawProp(rawProps, "letterSpacing", textAttributes_.letterSpacing);
|
||||
|
||||
// Paragraph
|
||||
applyRawProp(rawProps, "lineHeight", textAttributes_.lineHeight);
|
||||
applyRawProp(rawProps, "alignment", textAttributes_.alignment);
|
||||
applyRawProp(rawProps, "baseWritingDirection", textAttributes_.baseWritingDirection);
|
||||
|
||||
// Decoration
|
||||
applyRawProp(rawProps, "textDecorationColor", textAttributes_.textDecorationColor);
|
||||
applyRawProp(rawProps, "textDecorationLineType", textAttributes_.textDecorationLineType);
|
||||
applyRawProp(rawProps, "textDecorationLineStyle", textAttributes_.textDecorationLineStyle);
|
||||
applyRawProp(rawProps, "textDecorationLinePattern", textAttributes_.textDecorationLinePattern);
|
||||
|
||||
// Shadow
|
||||
applyRawProp(rawProps, "textShadowOffset", textAttributes_.textShadowOffset);
|
||||
applyRawProp(rawProps, "textShadowRadius", textAttributes_.textShadowRadius);
|
||||
applyRawProp(rawProps, "textShadowColor", textAttributes_.textShadowColor);
|
||||
|
||||
// Special
|
||||
applyRawProp(rawProps, "isHighlighted", textAttributes_.isHighlighted);
|
||||
}
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
TextAttributes BaseTextProps::getTextAttributes() const {
|
||||
return textAttributes_;
|
||||
}
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
SharedDebugStringConvertibleList BaseTextProps::getDebugProps() const {
|
||||
SharedDebugStringConvertibleList list = {};
|
||||
|
||||
auto textAttributesPropsList = textAttributes_.getDebugProps();
|
||||
std::move(textAttributesPropsList.begin(), textAttributesPropsList.end(), std::back_inserter(list));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fabric/attributedstring/TextAttributes.h>
|
||||
#include <fabric/core/Props.h>
|
||||
#include <fabric/graphics/Color.h>
|
||||
#include <fabric/graphics/Geometry.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/*
|
||||
* `Props`-like class which is used as a base class for all Props classes
|
||||
* that can have text attributes (such as Text and Paragraph).
|
||||
*/
|
||||
class BaseTextProps {
|
||||
public:
|
||||
|
||||
/*
|
||||
* Same semantic as `Props::apply(...)`.
|
||||
*/
|
||||
void apply(const RawProps &rawProps);
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
/*
|
||||
* Returns all props values as `TextAttributes` object.
|
||||
*/
|
||||
TextAttributes getTextAttributes() const;
|
||||
|
||||
#pragma mark - DebugStringConvertible (partially)
|
||||
|
||||
SharedDebugStringConvertibleList getDebugProps() const;
|
||||
|
||||
private:
|
||||
|
||||
TextAttributes textAttributes_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "BaseTextShadowNode.h"
|
||||
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
|
||||
#include "RawTextShadowNode.h"
|
||||
#include "RawTextProps.h"
|
||||
#include "TextShadowNode.h"
|
||||
#include "TextProps.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
AttributedString BaseTextShadowNode::getAttributedString(
|
||||
const TextAttributes &textAttributes,
|
||||
const SharedShadowNodeSharedList &childNodes
|
||||
) const {
|
||||
// TODO: Implement caching.
|
||||
|
||||
AttributedString attributedString;
|
||||
|
||||
for (auto &&childNode : *childNodes) {
|
||||
// RawShadowNode
|
||||
SharedRawTextShadowNode rawTextShadowNode = std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
|
||||
if (rawTextShadowNode) {
|
||||
AttributedString::Fragment fragment;
|
||||
fragment.string = rawTextShadowNode->getProps()->getText();
|
||||
fragment.textAttributes = textAttributes;
|
||||
attributedString.appendFragment(fragment);
|
||||
continue;
|
||||
}
|
||||
|
||||
// TextShadowNode
|
||||
SharedTextShadowNode textShadowNode = std::dynamic_pointer_cast<const TextShadowNode>(childNode);
|
||||
if (textShadowNode) {
|
||||
TextAttributes localTextAttributes = textAttributes;
|
||||
localTextAttributes.apply(textShadowNode->getProps()->getTextAttributes());
|
||||
attributedString.appendAttributedString(textShadowNode->getAttributedString(localTextAttributes, textShadowNode->getChildren()));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Any other kind of ShadowNode
|
||||
AttributedString::Fragment fragment;
|
||||
fragment.shadowNode = childNode;
|
||||
fragment.textAttributes = textAttributes;
|
||||
attributedString.appendFragment(fragment);
|
||||
}
|
||||
|
||||
return attributedString;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fabric/attributedstring/AttributedString.h>
|
||||
#include <fabric/attributedstring/TextAttributes.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/*
|
||||
* Base class (one of) for shadow nodes that represents attributed text,
|
||||
* such as Text and Paragraph (but not RawText).
|
||||
*/
|
||||
class BaseTextShadowNode {
|
||||
public:
|
||||
|
||||
/*
|
||||
* Returns a `AttributedString` which represents text content of the node.
|
||||
*/
|
||||
AttributedString getAttributedString(
|
||||
const TextAttributes &baseTextAttributes,
|
||||
const SharedShadowNodeSharedList &childNodes
|
||||
) const;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
|
@ -17,6 +17,7 @@ namespace react {
|
|||
|
||||
void ParagraphProps::apply(const RawProps &rawProps) {
|
||||
ViewProps::apply(rawProps);
|
||||
BaseTextProps::apply(rawProps);
|
||||
|
||||
// Paragraph Attributes
|
||||
applyRawProp(rawProps, "numberOfLines", paragraphAttributes_.maximumNumberOfLines);
|
||||
|
@ -44,13 +45,17 @@ bool ParagraphProps::getIsSelectable() const {
|
|||
SharedDebugStringConvertibleList ParagraphProps::getDebugProps() const {
|
||||
SharedDebugStringConvertibleList list = {};
|
||||
|
||||
// View Props
|
||||
auto &&viewPropsList = ViewProps::getDebugProps();
|
||||
std::move(viewPropsList.begin(), viewPropsList.end(), std::back_inserter(list));
|
||||
|
||||
// Paragraph Props
|
||||
auto &¶graphAttributePropsList = paragraphAttributes_.getDebugProps();
|
||||
std::move(paragraphAttributePropsList.begin(), paragraphAttributePropsList.end(), std::back_inserter(list));
|
||||
|
||||
// View Props
|
||||
auto &&viewPropsList = ViewProps::getDebugProps();
|
||||
std::move(viewPropsList.begin(), viewPropsList.end(), std::back_inserter(list));
|
||||
// Base Text Props
|
||||
auto &&baseTextPropsList = BaseTextProps::getDebugProps();
|
||||
std::move(baseTextPropsList.begin(), baseTextPropsList.end(), std::back_inserter(list));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <fabric/attributedstring/ParagraphAttributes.h>
|
||||
#include <fabric/core/Props.h>
|
||||
#include <fabric/text/BaseTextProps.h>
|
||||
#include <fabric/view/ViewProps.h>
|
||||
|
||||
namespace facebook {
|
||||
|
@ -27,7 +28,8 @@ using SharedParagraphProps = std::shared_ptr<const ParagraphProps>;
|
|||
* object.
|
||||
*/
|
||||
class ParagraphProps:
|
||||
public ViewProps {
|
||||
public ViewProps,
|
||||
public BaseTextProps {
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -17,17 +17,9 @@ namespace react {
|
|||
ComponentName ParagraphShadowNode::getComponentName() const {
|
||||
return ComponentName("Paragraph");
|
||||
}
|
||||
|
||||
SharedTextShadowNode ParagraphShadowNode::getTextChildNode() const {
|
||||
// <Paragraph> component must always have a single <Text> child component.
|
||||
assert(getChildren()->size() == 1);
|
||||
auto childNode = getChildren()->front();
|
||||
assert(std::dynamic_pointer_cast<const TextShadowNode>(childNode));
|
||||
return std::static_pointer_cast<const TextShadowNode>(childNode);
|
||||
}
|
||||
|
||||
AttributedString ParagraphShadowNode::getAttributedString() const {
|
||||
return getTextChildNode()->getAttributedString(TextAttributes());
|
||||
return BaseTextShadowNode::getAttributedString(getProps()->getTextAttributes(), getChildren());
|
||||
}
|
||||
|
||||
void ParagraphShadowNode::setTextLayoutManager(SharedTextLayoutManager textLayoutManager) {
|
||||
|
|
|
@ -26,14 +26,10 @@ using SharedParagraphShadowNode = std::shared_ptr<const ParagraphShadowNode>;
|
|||
* `ShadowNode` for <Paragraph> component, represents <View>-like component
|
||||
* containing and displaying text. Text content is represented as nested <Text>
|
||||
* and <RawText> components.
|
||||
* Note some Hierarchical constraints:
|
||||
* * <Paragraph> component must have only one <Text> component.
|
||||
* * <Text> component might have nested <Text>, <RawText>, and <View>-like
|
||||
* components.
|
||||
* * <RawText> component must not have any children.
|
||||
*/
|
||||
class ParagraphShadowNode:
|
||||
public ConcreteViewShadowNode<ParagraphProps> {
|
||||
public ConcreteViewShadowNode<ParagraphProps>,
|
||||
public BaseTextShadowNode {
|
||||
|
||||
public:
|
||||
|
||||
|
@ -41,11 +37,6 @@ public:
|
|||
|
||||
ComponentName getComponentName() const override;
|
||||
|
||||
/*
|
||||
* Returns a single nested <Text> shadow node.
|
||||
*/
|
||||
SharedTextShadowNode getTextChildNode() const;
|
||||
|
||||
/*
|
||||
* Returns a `AttributedString` which represents text content of the node.
|
||||
*/
|
||||
|
|
|
@ -18,57 +18,13 @@ namespace react {
|
|||
|
||||
void TextProps::apply(const RawProps &rawProps) {
|
||||
Props::apply(rawProps);
|
||||
|
||||
// Color
|
||||
applyRawProp(rawProps, "color", textAttributes_.foregroundColor);
|
||||
applyRawProp(rawProps, "backgroundColor", textAttributes_.backgroundColor);
|
||||
applyRawProp(rawProps, "opacity", textAttributes_.opacity);
|
||||
|
||||
// Font
|
||||
applyRawProp(rawProps, "fontFamily", textAttributes_.fontFamily);
|
||||
applyRawProp(rawProps, "fontSize", textAttributes_.fontSize);
|
||||
applyRawProp(rawProps, "fontSizeMultiplier", textAttributes_.fontSizeMultiplier);
|
||||
applyRawProp(rawProps, "fontWeight", textAttributes_.fontWeight);
|
||||
applyRawProp(rawProps, "fontStyle", textAttributes_.fontStyle);
|
||||
applyRawProp(rawProps, "fontVariant", textAttributes_.fontVariant);
|
||||
applyRawProp(rawProps, "allowFontScaling", textAttributes_.allowFontScaling);
|
||||
applyRawProp(rawProps, "letterSpacing", textAttributes_.letterSpacing);
|
||||
|
||||
// Paragraph
|
||||
applyRawProp(rawProps, "lineHeight", textAttributes_.lineHeight);
|
||||
applyRawProp(rawProps, "alignment", textAttributes_.alignment);
|
||||
applyRawProp(rawProps, "baseWritingDirection", textAttributes_.baseWritingDirection);
|
||||
|
||||
// Decoration
|
||||
applyRawProp(rawProps, "textDecorationColor", textAttributes_.textDecorationColor);
|
||||
applyRawProp(rawProps, "textDecorationLineType", textAttributes_.textDecorationLineType);
|
||||
applyRawProp(rawProps, "textDecorationLineStyle", textAttributes_.textDecorationLineStyle);
|
||||
applyRawProp(rawProps, "textDecorationLinePattern", textAttributes_.textDecorationLinePattern);
|
||||
|
||||
// Shadow
|
||||
applyRawProp(rawProps, "textShadowOffset", textAttributes_.textShadowOffset);
|
||||
applyRawProp(rawProps, "textShadowRadius", textAttributes_.textShadowRadius);
|
||||
applyRawProp(rawProps, "textShadowColor", textAttributes_.textShadowColor);
|
||||
|
||||
// Special
|
||||
applyRawProp(rawProps, "isHighlighted", textAttributes_.isHighlighted);
|
||||
}
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
TextAttributes TextProps::getTextAttributes() const {
|
||||
return textAttributes_;
|
||||
BaseTextProps::apply(rawProps);
|
||||
}
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
SharedDebugStringConvertibleList TextProps::getDebugProps() const {
|
||||
SharedDebugStringConvertibleList list = {};
|
||||
|
||||
auto textAttributesPropsList = textAttributes_.getDebugProps();
|
||||
std::move(textAttributesPropsList.begin(), textAttributesPropsList.end(), std::back_inserter(list));
|
||||
|
||||
return list;
|
||||
return BaseTextProps::getDebugProps();
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <fabric/core/Props.h>
|
||||
#include <fabric/graphics/Color.h>
|
||||
#include <fabric/graphics/Geometry.h>
|
||||
#include <fabric/text/BaseTextProps.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
@ -20,22 +21,12 @@ class TextProps;
|
|||
using SharedTextProps = std::shared_ptr<const TextProps>;
|
||||
|
||||
class TextProps:
|
||||
public Props {
|
||||
public Props,
|
||||
public BaseTextProps {
|
||||
|
||||
public:
|
||||
void apply(const RawProps &rawProps) override;
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
TextAttributes getTextAttributes() const;
|
||||
|
||||
private:
|
||||
|
||||
/*
|
||||
* Not all `TextAttributes` fields make sense and is used as TextProps values.
|
||||
*/
|
||||
TextAttributes textAttributes_;
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
SharedDebugStringConvertibleList getDebugProps() const override;
|
||||
|
@ -43,4 +34,3 @@ private:
|
|||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
|
||||
#include "RawTextShadowNode.h"
|
||||
#include "RawTextProps.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
@ -19,41 +16,5 @@ ComponentName TextShadowNode::getComponentName() const {
|
|||
return ComponentName("Text");
|
||||
}
|
||||
|
||||
AttributedString TextShadowNode::getAttributedString(const TextAttributes &baseTextAttributes) const {
|
||||
// TODO: Implement caching.
|
||||
|
||||
TextAttributes textAttributes = baseTextAttributes;
|
||||
textAttributes.apply(getProps()->getTextAttributes());
|
||||
|
||||
AttributedString attributedString;
|
||||
|
||||
for (auto &&childNode : *getChildren()) {
|
||||
// RawShadowNode
|
||||
SharedRawTextShadowNode rawTextShadowNode = std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
|
||||
if (rawTextShadowNode) {
|
||||
AttributedString::Fragment fragment;
|
||||
fragment.string = rawTextShadowNode->getProps()->getText();
|
||||
fragment.textAttributes = textAttributes;
|
||||
attributedString.appendFragment(fragment);
|
||||
continue;
|
||||
}
|
||||
|
||||
// TextShadowNode
|
||||
SharedTextShadowNode textShadowNode = std::dynamic_pointer_cast<const TextShadowNode>(childNode);
|
||||
if (textShadowNode) {
|
||||
attributedString.appendAttributedString(textShadowNode->getAttributedString(textAttributes));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Any other kind of ShadowNode
|
||||
AttributedString::Fragment fragment;
|
||||
fragment.shadowNode = childNode;
|
||||
fragment.textAttributes = textAttributes;
|
||||
attributedString.appendFragment(fragment);
|
||||
}
|
||||
|
||||
return attributedString;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <fabric/attributedstring/TextAttributes.h>
|
||||
#include <fabric/core/ConcreteShadowNode.h>
|
||||
#include <fabric/core/ShadowNode.h>
|
||||
#include <fabric/text/BaseTextShadowNode.h>
|
||||
#include <fabric/text/TextProps.h>
|
||||
#include <fabric/text/TextShadowNode.h>
|
||||
|
||||
|
@ -22,18 +23,14 @@ class TextShadowNode;
|
|||
using SharedTextShadowNode = std::shared_ptr<const TextShadowNode>;
|
||||
|
||||
class TextShadowNode:
|
||||
public ConcreteShadowNode<TextProps> {
|
||||
public ConcreteShadowNode<TextProps>,
|
||||
public BaseTextShadowNode {
|
||||
|
||||
public:
|
||||
|
||||
using ConcreteShadowNode::ConcreteShadowNode;
|
||||
|
||||
ComponentName getComponentName() const override;
|
||||
|
||||
/*
|
||||
* Returns a `AttributedString` which represents text content of the node.
|
||||
*/
|
||||
AttributedString getAttributedString(const TextAttributes &baseTextAttributes) const;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
load("//configurations/buck/apple:flag_defs.bzl", "get_debug_preprocessor_flags", "get_fbobjc_enable_exception_lang_compiler_flags")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "react_native_xplat_target", "rn_xplat_cxx_library", "get_apple_inspector_flags", "APPLE")
|
||||
load("//configurations/buck/apple:flag_defs.bzl", "get_application_ios_flags", "get_debug_preprocessor_flags", "OBJC_ARC_PREPROCESSOR_FLAGS")
|
||||
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "rn_xplat_cxx_library", "get_apple_inspector_flags", "react_native_xplat_target", "ANDROID", "APPLE")
|
||||
|
||||
APPLE_COMPILER_FLAGS = []
|
||||
|
||||
|
@ -39,14 +39,14 @@ rn_xplat_cxx_library(
|
|||
":tests",
|
||||
],
|
||||
force_static = True,
|
||||
macosx_tests_override = [],
|
||||
frameworks = [
|
||||
"$SDKROOT/System/Library/Frameworks/CoreGraphics.framework",
|
||||
"$SDKROOT/System/Library/Frameworks/Foundation.framework",
|
||||
"$SDKROOT/System/Library/Frameworks/QuartzCore.framework",
|
||||
"$SDKROOT/System/Library/Frameworks/UIKit.framework",
|
||||
],
|
||||
lang_compiler_flags = get_fbobjc_enable_exception_lang_compiler_flags(),
|
||||
preprocessor_flags = get_debug_preprocessor_flags() + [
|
||||
macosx_tests_override = [],
|
||||
platforms = (ANDROID, APPLE),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
],
|
||||
|
@ -58,6 +58,7 @@ rn_xplat_cxx_library(
|
|||
"xplat//folly:memory",
|
||||
"xplat//folly:molly",
|
||||
"xplat//third-party/glog:glog",
|
||||
"xplat//yoga:yoga",
|
||||
react_native_xplat_target("fabric/attributedstring:attributedstring"),
|
||||
react_native_xplat_target("fabric/core:core"),
|
||||
react_native_xplat_target("fabric/debug:debug"),
|
||||
|
|
|
@ -53,15 +53,15 @@ rn_xplat_cxx_library(
|
|||
"xplat//folly:molly",
|
||||
"xplat//third-party/glog:glog",
|
||||
"xplat//yoga:yoga",
|
||||
react_native_xplat_target("fabric/debug:debug"),
|
||||
react_native_xplat_target("fabric/core:core"),
|
||||
react_native_xplat_target("fabric/debug:debug"),
|
||||
react_native_xplat_target("fabric/graphics:graphics"),
|
||||
],
|
||||
)
|
||||
|
||||
if not IS_OSS_BUILD:
|
||||
load("@xplat//build_defs:fb_xplat_cxx_test.bzl", "fb_xplat_cxx_test")
|
||||
|
||||
|
||||
fb_xplat_cxx_test(
|
||||
name = "tests",
|
||||
srcs = glob(["tests/**/*.cpp"]),
|
||||
|
|
Loading…
Reference in New Issue