File tree Expand file tree Collapse file tree 3 files changed +57
-12
lines changed
graphics/platform/android Expand file tree Collapse file tree 3 files changed +57
-12
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ class TextAttributes:
3131#pragma mark - Fields
3232
3333 // Color
34- SharedColor foregroundColor {nullptr };
35- SharedColor backgroundColor {nullptr };
34+ SharedColor foregroundColor {};
35+ SharedColor backgroundColor {};
3636 Float opacity {std::numeric_limits<Float>::quiet_NaN ()};
3737
3838 // Font
@@ -51,7 +51,7 @@ class TextAttributes:
5151 folly::Optional<WritingDirection> baseWritingDirection {};
5252
5353 // Decoration
54- SharedColor textDecorationColor {nullptr };
54+ SharedColor textDecorationColor {};
5555 folly::Optional<TextDecorationLineType> textDecorationLineType {};
5656 folly::Optional<TextDecorationLineStyle> textDecorationLineStyle {};
5757 folly::Optional<TextDecorationLinePattern> textDecorationLinePattern {};
@@ -60,7 +60,7 @@ class TextAttributes:
6060 // TODO: Use `Point` type instead of `Size` for `textShadowOffset` attribute.
6161 folly::Optional<Size> textShadowOffset {};
6262 Float textShadowRadius {std::numeric_limits<Float>::quiet_NaN ()};
63- SharedColor textShadowColor {nullptr };
63+ SharedColor textShadowColor {};
6464
6565 // Special
6666 folly::Optional<bool > isHighlighted {};
Original file line number Diff line number Diff line change @@ -11,13 +11,22 @@ namespace facebook {
1111namespace react {
1212
1313SharedColor colorFromComponents (ColorComponents components) {
14- // Not implemented.
15- return {};
14+ return SharedColor (
15+ ((int )components.alpha & 0xff ) << 24 |
16+ ((int )components.red & 0xff ) << 16 |
17+ ((int )components.green & 0xff ) << 8 |
18+ ((int )components.blue & 0xff )
19+ );
1620}
1721
18- ColorComponents colorComponentsFromColor (SharedColor color) {
19- // Not implemented.
20- return {};
22+ ColorComponents colorComponentsFromColor (SharedColor sharedColor) {
23+ Color color = *sharedColor;
24+ return ColorComponents {
25+ (float )((color >> 16 ) & 0xff ),
26+ (float )((color >> 8 ) & 0xff ),
27+ (float )((color ) & 0xff ),
28+ (float )((color >> 24 ) & 0xff )
29+ };
2130}
2231
2332} // namespace react
Original file line number Diff line number Diff line change 77
88#pragma once
99
10- #include < memory >
10+ #include < limits >
1111
1212#include < fabric/graphics/ColorComponents.h>
1313
1414namespace facebook {
1515namespace react {
1616
17- using Color = float ;
18- using SharedColor = std::shared_ptr<Color>;
17+ using Color = int ;
18+
19+ /*
20+ * On Android, a color can be represented as 32 bits integer, so there is no need
21+ * to instantiate complex color objects and then pass them as shared pointers.
22+ * Hense instead of using shared_ptr, we use a simple wrapper class
23+ * which provides a pointer-like interface.
24+ */
25+ class SharedColor {
26+
27+ public:
28+ static const Color UndefinedColor = std::numeric_limits<Color>::max();
29+
30+ SharedColor ():
31+ color_(UndefinedColor) {}
32+
33+ SharedColor (const SharedColor &sharedColor) :
34+ color_(sharedColor.color_) {}
35+
36+ SharedColor (Color color):
37+ color_(color) {}
38+
39+ SharedColor &operator =(const SharedColor &sharedColor) {
40+ color_ = sharedColor.color_ ;
41+ return *this ;
42+ }
43+
44+ Color operator *() const {
45+ return color_;
46+ }
47+
48+ operator bool () const {
49+ return color_ != UndefinedColor;
50+ }
51+
52+ private:
53+ Color color_;
54+ };
1955
2056SharedColor colorFromComponents (ColorComponents components);
2157ColorComponents colorComponentsFromColor (SharedColor color);
You can’t perform that action at this time.
0 commit comments