File tree 3 files changed +57
-12
lines changed
graphics/platform/android
3 files changed +57
-12
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ class TextAttributes:
31
31
#pragma mark - Fields
32
32
33
33
// Color
34
- SharedColor foregroundColor {nullptr };
35
- SharedColor backgroundColor {nullptr };
34
+ SharedColor foregroundColor {};
35
+ SharedColor backgroundColor {};
36
36
Float opacity {std::numeric_limits<Float>::quiet_NaN ()};
37
37
38
38
// Font
@@ -51,7 +51,7 @@ class TextAttributes:
51
51
folly::Optional<WritingDirection> baseWritingDirection {};
52
52
53
53
// Decoration
54
- SharedColor textDecorationColor {nullptr };
54
+ SharedColor textDecorationColor {};
55
55
folly::Optional<TextDecorationLineType> textDecorationLineType {};
56
56
folly::Optional<TextDecorationLineStyle> textDecorationLineStyle {};
57
57
folly::Optional<TextDecorationLinePattern> textDecorationLinePattern {};
@@ -60,7 +60,7 @@ class TextAttributes:
60
60
// TODO: Use `Point` type instead of `Size` for `textShadowOffset` attribute.
61
61
folly::Optional<Size > textShadowOffset {};
62
62
Float textShadowRadius {std::numeric_limits<Float>::quiet_NaN ()};
63
- SharedColor textShadowColor {nullptr };
63
+ SharedColor textShadowColor {};
64
64
65
65
// Special
66
66
folly::Optional<bool > isHighlighted {};
Original file line number Diff line number Diff line change @@ -11,13 +11,22 @@ namespace facebook {
11
11
namespace react {
12
12
13
13
SharedColor 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
+ );
16
20
}
17
21
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
+ };
21
30
}
22
31
23
32
} // namespace react
Original file line number Diff line number Diff line change 7
7
8
8
#pragma once
9
9
10
- #include < memory >
10
+ #include < limits >
11
11
12
12
#include < fabric/graphics/ColorComponents.h>
13
13
14
14
namespace facebook {
15
15
namespace react {
16
16
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
+ };
19
55
20
56
SharedColor colorFromComponents (ColorComponents components);
21
57
ColorComponents colorComponentsFromColor (SharedColor color);
You can’t perform that action at this time.
0 commit comments