mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e1d17c785b
Summary: Added to C++ props, but realized this is already implemented using C++ state in Android, so added to C++ state to keep this diff simpler. Keeping the C++ props change for future use. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D29805267 fbshipit-source-id: c1fe2dc34af8bc69352ee48a5d60ba998194e3f7
178 lines
5.4 KiB
C++
178 lines
5.4 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* 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 <react/renderer/attributedstring/conversions.h>
|
|
#include <react/renderer/core/propsConversions.h>
|
|
#include <react/renderer/debug/DebugStringConvertibleItem.h>
|
|
#include <react/renderer/graphics/conversions.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
static TextAttributes convertRawProp(
|
|
const RawProps &rawProps,
|
|
const TextAttributes sourceTextAttributes,
|
|
const TextAttributes defaultTextAttributes) {
|
|
auto textAttributes = TextAttributes{};
|
|
|
|
// Color
|
|
textAttributes.foregroundColor = convertRawProp(
|
|
rawProps,
|
|
"color",
|
|
sourceTextAttributes.foregroundColor,
|
|
defaultTextAttributes.foregroundColor);
|
|
textAttributes.backgroundColor = convertRawProp(
|
|
rawProps,
|
|
"backgroundColor",
|
|
sourceTextAttributes.backgroundColor,
|
|
defaultTextAttributes.backgroundColor);
|
|
textAttributes.opacity = convertRawProp(
|
|
rawProps,
|
|
"opacity",
|
|
sourceTextAttributes.opacity,
|
|
defaultTextAttributes.opacity);
|
|
|
|
// Font
|
|
textAttributes.fontFamily = convertRawProp(
|
|
rawProps,
|
|
"fontFamily",
|
|
sourceTextAttributes.fontFamily,
|
|
defaultTextAttributes.fontFamily);
|
|
textAttributes.fontSize = convertRawProp(
|
|
rawProps,
|
|
"fontSize",
|
|
sourceTextAttributes.fontSize,
|
|
defaultTextAttributes.fontSize);
|
|
textAttributes.fontSizeMultiplier = convertRawProp(
|
|
rawProps,
|
|
"fontSizeMultiplier",
|
|
sourceTextAttributes.fontSizeMultiplier,
|
|
defaultTextAttributes.fontSizeMultiplier);
|
|
textAttributes.fontWeight = convertRawProp(
|
|
rawProps,
|
|
"fontWeight",
|
|
sourceTextAttributes.fontWeight,
|
|
defaultTextAttributes.fontWeight);
|
|
textAttributes.fontStyle = convertRawProp(
|
|
rawProps,
|
|
"fontStyle",
|
|
sourceTextAttributes.fontStyle,
|
|
defaultTextAttributes.fontStyle);
|
|
textAttributes.fontVariant = convertRawProp(
|
|
rawProps,
|
|
"fontVariant",
|
|
sourceTextAttributes.fontVariant,
|
|
defaultTextAttributes.fontVariant);
|
|
textAttributes.allowFontScaling = convertRawProp(
|
|
rawProps,
|
|
"allowFontScaling",
|
|
sourceTextAttributes.allowFontScaling,
|
|
defaultTextAttributes.allowFontScaling);
|
|
textAttributes.letterSpacing = convertRawProp(
|
|
rawProps,
|
|
"letterSpacing",
|
|
sourceTextAttributes.letterSpacing,
|
|
defaultTextAttributes.letterSpacing);
|
|
textAttributes.textTransform = convertRawProp(
|
|
rawProps,
|
|
"textTransform",
|
|
sourceTextAttributes.textTransform,
|
|
defaultTextAttributes.textTransform);
|
|
|
|
// Paragraph
|
|
textAttributes.lineHeight = convertRawProp(
|
|
rawProps,
|
|
"lineHeight",
|
|
sourceTextAttributes.lineHeight,
|
|
defaultTextAttributes.lineHeight);
|
|
textAttributes.alignment = convertRawProp(
|
|
rawProps,
|
|
"textAlign",
|
|
sourceTextAttributes.alignment,
|
|
defaultTextAttributes.alignment);
|
|
textAttributes.baseWritingDirection = convertRawProp(
|
|
rawProps,
|
|
"baseWritingDirection",
|
|
sourceTextAttributes.baseWritingDirection,
|
|
defaultTextAttributes.baseWritingDirection);
|
|
|
|
// Decoration
|
|
textAttributes.textDecorationColor = convertRawProp(
|
|
rawProps,
|
|
"textDecorationColor",
|
|
sourceTextAttributes.textDecorationColor,
|
|
defaultTextAttributes.textDecorationColor);
|
|
textAttributes.textDecorationLineType = convertRawProp(
|
|
rawProps,
|
|
"textDecorationLine",
|
|
sourceTextAttributes.textDecorationLineType,
|
|
defaultTextAttributes.textDecorationLineType);
|
|
textAttributes.textDecorationLineStyle = convertRawProp(
|
|
rawProps,
|
|
"textDecorationLineStyle",
|
|
sourceTextAttributes.textDecorationLineStyle,
|
|
defaultTextAttributes.textDecorationLineStyle);
|
|
textAttributes.textDecorationLinePattern = convertRawProp(
|
|
rawProps,
|
|
"textDecorationLinePattern",
|
|
sourceTextAttributes.textDecorationLinePattern,
|
|
defaultTextAttributes.textDecorationLinePattern);
|
|
|
|
// Shadow
|
|
textAttributes.textShadowOffset = convertRawProp(
|
|
rawProps,
|
|
"textShadowOffset",
|
|
sourceTextAttributes.textShadowOffset,
|
|
defaultTextAttributes.textShadowOffset);
|
|
textAttributes.textShadowRadius = convertRawProp(
|
|
rawProps,
|
|
"textShadowRadius",
|
|
sourceTextAttributes.textShadowRadius,
|
|
defaultTextAttributes.textShadowRadius);
|
|
textAttributes.textShadowColor = convertRawProp(
|
|
rawProps,
|
|
"textShadowColor",
|
|
sourceTextAttributes.textShadowColor,
|
|
defaultTextAttributes.textShadowColor);
|
|
|
|
// Special
|
|
textAttributes.isHighlighted = convertRawProp(
|
|
rawProps,
|
|
"isHighlighted",
|
|
sourceTextAttributes.isHighlighted,
|
|
defaultTextAttributes.isHighlighted);
|
|
|
|
textAttributes.accessibilityRole = convertRawProp(
|
|
rawProps,
|
|
"accessibilityRole",
|
|
sourceTextAttributes.accessibilityRole,
|
|
defaultTextAttributes.accessibilityRole);
|
|
|
|
return textAttributes;
|
|
}
|
|
|
|
BaseTextProps::BaseTextProps(
|
|
const BaseTextProps &sourceProps,
|
|
const RawProps &rawProps)
|
|
: textAttributes(convertRawProp(
|
|
rawProps,
|
|
sourceProps.textAttributes,
|
|
TextAttributes{})){};
|
|
|
|
#pragma mark - DebugStringConvertible
|
|
|
|
#if RN_DEBUG_STRING_CONVERTIBLE
|
|
SharedDebugStringConvertibleList BaseTextProps::getDebugProps() const {
|
|
return textAttributes.getDebugProps();
|
|
}
|
|
#endif
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|