mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
8bd3edec88
Reviewed By: aaronabramov Differential Revision: D33367752 fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
199 lines
5.6 KiB
C++
199 lines
5.6 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and 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 PropsParserContext &context,
|
|
const RawProps &rawProps,
|
|
const TextAttributes sourceTextAttributes,
|
|
const TextAttributes defaultTextAttributes) {
|
|
auto textAttributes = TextAttributes{};
|
|
|
|
// Color
|
|
textAttributes.foregroundColor = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"color",
|
|
sourceTextAttributes.foregroundColor,
|
|
defaultTextAttributes.foregroundColor);
|
|
textAttributes.backgroundColor = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"backgroundColor",
|
|
sourceTextAttributes.backgroundColor,
|
|
defaultTextAttributes.backgroundColor);
|
|
textAttributes.opacity = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"opacity",
|
|
sourceTextAttributes.opacity,
|
|
defaultTextAttributes.opacity);
|
|
|
|
// Font
|
|
textAttributes.fontFamily = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"fontFamily",
|
|
sourceTextAttributes.fontFamily,
|
|
defaultTextAttributes.fontFamily);
|
|
textAttributes.fontSize = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"fontSize",
|
|
sourceTextAttributes.fontSize,
|
|
defaultTextAttributes.fontSize);
|
|
textAttributes.fontSizeMultiplier = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"fontSizeMultiplier",
|
|
sourceTextAttributes.fontSizeMultiplier,
|
|
defaultTextAttributes.fontSizeMultiplier);
|
|
textAttributes.fontWeight = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"fontWeight",
|
|
sourceTextAttributes.fontWeight,
|
|
defaultTextAttributes.fontWeight);
|
|
textAttributes.fontStyle = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"fontStyle",
|
|
sourceTextAttributes.fontStyle,
|
|
defaultTextAttributes.fontStyle);
|
|
textAttributes.fontVariant = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"fontVariant",
|
|
sourceTextAttributes.fontVariant,
|
|
defaultTextAttributes.fontVariant);
|
|
textAttributes.allowFontScaling = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"allowFontScaling",
|
|
sourceTextAttributes.allowFontScaling,
|
|
defaultTextAttributes.allowFontScaling);
|
|
textAttributes.letterSpacing = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"letterSpacing",
|
|
sourceTextAttributes.letterSpacing,
|
|
defaultTextAttributes.letterSpacing);
|
|
textAttributes.textTransform = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textTransform",
|
|
sourceTextAttributes.textTransform,
|
|
defaultTextAttributes.textTransform);
|
|
|
|
// Paragraph
|
|
textAttributes.lineHeight = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"lineHeight",
|
|
sourceTextAttributes.lineHeight,
|
|
defaultTextAttributes.lineHeight);
|
|
textAttributes.alignment = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textAlign",
|
|
sourceTextAttributes.alignment,
|
|
defaultTextAttributes.alignment);
|
|
textAttributes.baseWritingDirection = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"baseWritingDirection",
|
|
sourceTextAttributes.baseWritingDirection,
|
|
defaultTextAttributes.baseWritingDirection);
|
|
|
|
// Decoration
|
|
textAttributes.textDecorationColor = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textDecorationColor",
|
|
sourceTextAttributes.textDecorationColor,
|
|
defaultTextAttributes.textDecorationColor);
|
|
textAttributes.textDecorationLineType = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textDecorationLine",
|
|
sourceTextAttributes.textDecorationLineType,
|
|
defaultTextAttributes.textDecorationLineType);
|
|
textAttributes.textDecorationStyle = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textDecorationStyle",
|
|
sourceTextAttributes.textDecorationStyle,
|
|
defaultTextAttributes.textDecorationStyle);
|
|
|
|
// Shadow
|
|
textAttributes.textShadowOffset = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textShadowOffset",
|
|
sourceTextAttributes.textShadowOffset,
|
|
defaultTextAttributes.textShadowOffset);
|
|
textAttributes.textShadowRadius = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textShadowRadius",
|
|
sourceTextAttributes.textShadowRadius,
|
|
defaultTextAttributes.textShadowRadius);
|
|
textAttributes.textShadowColor = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"textShadowColor",
|
|
sourceTextAttributes.textShadowColor,
|
|
defaultTextAttributes.textShadowColor);
|
|
|
|
// Special
|
|
textAttributes.isHighlighted = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"isHighlighted",
|
|
sourceTextAttributes.isHighlighted,
|
|
defaultTextAttributes.isHighlighted);
|
|
|
|
textAttributes.accessibilityRole = convertRawProp(
|
|
context,
|
|
rawProps,
|
|
"accessibilityRole",
|
|
sourceTextAttributes.accessibilityRole,
|
|
defaultTextAttributes.accessibilityRole);
|
|
|
|
return textAttributes;
|
|
}
|
|
|
|
BaseTextProps::BaseTextProps(
|
|
const PropsParserContext &context,
|
|
const BaseTextProps &sourceProps,
|
|
const RawProps &rawProps)
|
|
: textAttributes(convertRawProp(
|
|
context,
|
|
rawProps,
|
|
sourceProps.textAttributes,
|
|
TextAttributes{})){};
|
|
|
|
#pragma mark - DebugStringConvertible
|
|
|
|
#if RN_DEBUG_STRING_CONVERTIBLE
|
|
SharedDebugStringConvertibleList BaseTextProps::getDebugProps() const {
|
|
return textAttributes.getDebugProps();
|
|
}
|
|
#endif
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|