Valentin Shergin 2d1fabbab2 Fabric: SharedColor for Android
Summary:
@public
On Android, a color can be represented as 32 bits integer, so there is no need to instantiate complex color objects and then pass them as shared pointers.  Hense instead of using shared_ptr, we use a simple wrapper class which provides a pointer-like interface.

Reviewed By: mdvacca

Differential Revision: D8742014

fbshipit-source-id: 14109b61fd84a34989538a15bc6fe4e2a8ce83a6
2018-07-17 18:17:27 -07:00

81 lines
2.3 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.
*/
#pragma once
#include <limits>
#include <fabric/attributedstring/primitives.h>
#include <fabric/core/LayoutPrimitives.h>
#include <fabric/core/ReactPrimitives.h>
#include <fabric/debug/DebugStringConvertible.h>
#include <fabric/graphics/Color.h>
#include <fabric/graphics/Geometry.h>
#include <folly/Optional.h>
namespace facebook {
namespace react {
class TextAttributes;
using SharedTextAttributes = std::shared_ptr<const TextAttributes>;
class TextAttributes:
public DebugStringConvertible {
public:
#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()};
folly::Optional<FontWeight> fontWeight {};
folly::Optional<FontStyle> fontStyle {};
folly::Optional<FontVariant> fontVariant {};
folly::Optional<bool> allowFontScaling {};
Float letterSpacing {std::numeric_limits<Float>::quiet_NaN()};
// Paragraph Styles
Float lineHeight {std::numeric_limits<Float>::quiet_NaN()};
folly::Optional<TextAlignment> alignment {};
folly::Optional<WritingDirection> baseWritingDirection {};
// Decoration
SharedColor textDecorationColor {};
folly::Optional<TextDecorationLineType> textDecorationLineType {};
folly::Optional<TextDecorationLineStyle> textDecorationLineStyle {};
folly::Optional<TextDecorationLinePattern> textDecorationLinePattern {};
// Shadow
// TODO: Use `Point` type instead of `Size` for `textShadowOffset` attribute.
folly::Optional<Size> textShadowOffset {};
Float textShadowRadius {std::numeric_limits<Float>::quiet_NaN()};
SharedColor textShadowColor {};
// Special
folly::Optional<bool> isHighlighted {};
folly::Optional<LayoutDirection> layoutDirection {};
#pragma mark - Operations
void apply(TextAttributes textAttributes);
#pragma mark - DebugStringConvertible
SharedDebugStringConvertibleList getDebugProps() const override;
};
} // namespace react
} // namespace facebook