Valentin Shergin d9ff1769aa 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
2018-05-08 19:24:10 -07:00

74 lines
2.8 KiB
C++

/**
* 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