mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
61755aced1
Summary: The [first implementation of `TextAttributes` in Fabric](https://github.com/facebook/react-native/commit/62576bcb7832e08c6fd9f9482285882c37a2ece5) included two separate props instead of `textDecorationStyle`: `textDecorationLineStyle` (single, double, ...) and `textDecorationLinePattern` (dot, dash, dotdash, ...). These two props were implemented in C++ and iOS but never supported in JS. Pre-Fabric (and CSS) on the other hand use a single prop `textDecorationStyle: 'solid' | 'double' | 'dotted' | 'dashed'`. This diff implements this same API in Fabric, and removes the unused `textDecorationLineStyle` and `textDecorationLinePattern` props. Changelog: [iOS][Fixed] - Implement `textDecorationStyle` on iOS and remove unused `textDecorationLineStyle` and `textDecorationLinePattern` from Fabric. Reviewed By: dmitryrykun Differential Revision: D31617598 fbshipit-source-id: f5173e7ecdd31aafa0e5f0e50137eefa0505e007
136 lines
4.2 KiB
C++
136 lines
4.2 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
#include <limits>
|
|
|
|
#include <better/optional.h>
|
|
#include <folly/Hash.h>
|
|
#include <react/renderer/attributedstring/primitives.h>
|
|
#include <react/renderer/core/LayoutPrimitives.h>
|
|
#include <react/renderer/core/ReactPrimitives.h>
|
|
#include <react/renderer/debug/DebugStringConvertible.h>
|
|
#include <react/renderer/graphics/Color.h>
|
|
#include <react/renderer/graphics/Geometry.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class TextAttributes;
|
|
|
|
using SharedTextAttributes = std::shared_ptr<const TextAttributes>;
|
|
|
|
class TextAttributes : public DebugStringConvertible {
|
|
public:
|
|
/*
|
|
* Returns TextAttribute object which has actual default attribute values
|
|
* (e.g. `foregroundColor = black`), in oppose to TextAttribute's default
|
|
* constructor which creates an object with nulled attributes.
|
|
*/
|
|
static TextAttributes defaultTextAttributes();
|
|
|
|
#pragma mark - Fields
|
|
|
|
// Color
|
|
SharedColor foregroundColor{};
|
|
SharedColor backgroundColor{};
|
|
Float opacity{std::numeric_limits<Float>::quiet_NaN()};
|
|
|
|
// Font
|
|
std::string fontFamily{""};
|
|
Float fontSize{std::numeric_limits<Float>::quiet_NaN()};
|
|
Float fontSizeMultiplier{std::numeric_limits<Float>::quiet_NaN()};
|
|
better::optional<FontWeight> fontWeight{};
|
|
better::optional<FontStyle> fontStyle{};
|
|
better::optional<FontVariant> fontVariant{};
|
|
better::optional<bool> allowFontScaling{};
|
|
Float letterSpacing{std::numeric_limits<Float>::quiet_NaN()};
|
|
better::optional<TextTransform> textTransform{};
|
|
|
|
// Paragraph Styles
|
|
Float lineHeight{std::numeric_limits<Float>::quiet_NaN()};
|
|
better::optional<TextAlignment> alignment{};
|
|
better::optional<WritingDirection> baseWritingDirection{};
|
|
|
|
// Decoration
|
|
SharedColor textDecorationColor{};
|
|
better::optional<TextDecorationLineType> textDecorationLineType{};
|
|
better::optional<TextDecorationStyle> textDecorationStyle{};
|
|
|
|
// Shadow
|
|
// TODO: Use `Point` type instead of `Size` for `textShadowOffset` attribute.
|
|
better::optional<Size> textShadowOffset{};
|
|
Float textShadowRadius{std::numeric_limits<Float>::quiet_NaN()};
|
|
SharedColor textShadowColor{};
|
|
|
|
// Special
|
|
better::optional<bool> isHighlighted{};
|
|
|
|
// TODO T59221129: document where this value comes from and how it is set.
|
|
// It's not clear if this is being used properly, or if it's being set at all.
|
|
// Currently, it is intentionally *not* being set as part of BaseTextProps
|
|
// construction.
|
|
better::optional<LayoutDirection> layoutDirection{};
|
|
better::optional<AccessibilityRole> accessibilityRole{};
|
|
|
|
#pragma mark - Operations
|
|
|
|
void apply(TextAttributes textAttributes);
|
|
|
|
#pragma mark - Operators
|
|
|
|
bool operator==(const TextAttributes &rhs) const;
|
|
bool operator!=(const TextAttributes &rhs) const;
|
|
|
|
#pragma mark - DebugStringConvertible
|
|
|
|
#if RN_DEBUG_STRING_CONVERTIBLE
|
|
SharedDebugStringConvertibleList getDebugProps() const override;
|
|
#endif
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|
|
|
|
namespace std {
|
|
|
|
template <>
|
|
struct hash<facebook::react::TextAttributes> {
|
|
size_t operator()(
|
|
const facebook::react::TextAttributes &textAttributes) const {
|
|
return folly::hash::hash_combine(
|
|
0,
|
|
textAttributes.foregroundColor,
|
|
textAttributes.backgroundColor,
|
|
textAttributes.opacity,
|
|
textAttributes.fontFamily,
|
|
textAttributes.fontSize,
|
|
textAttributes.fontSizeMultiplier,
|
|
textAttributes.fontWeight,
|
|
textAttributes.fontStyle,
|
|
textAttributes.fontVariant,
|
|
textAttributes.allowFontScaling,
|
|
textAttributes.letterSpacing,
|
|
textAttributes.textTransform,
|
|
textAttributes.lineHeight,
|
|
textAttributes.alignment,
|
|
textAttributes.baseWritingDirection,
|
|
textAttributes.textDecorationColor,
|
|
textAttributes.textDecorationLineType,
|
|
textAttributes.textDecorationStyle,
|
|
textAttributes.textShadowOffset,
|
|
textAttributes.textShadowRadius,
|
|
textAttributes.textShadowColor,
|
|
textAttributes.isHighlighted,
|
|
textAttributes.layoutDirection,
|
|
textAttributes.accessibilityRole);
|
|
}
|
|
};
|
|
} // namespace std
|