forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewProps.cpp
127 lines (115 loc) · 4.62 KB
/
ViewProps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* 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.
*/
#include "ViewProps.h"
#include <react/components/view/conversions.h>
#include <react/components/view/propsConversions.h>
#include <react/core/propsConversions.h>
#include <react/debug/debugStringConvertibleUtils.h>
#include <react/graphics/conversions.h>
namespace facebook {
namespace react {
ViewProps::ViewProps(const YGStyle &yogaStyle) : YogaStylableProps(yogaStyle) {}
ViewProps::ViewProps(const ViewProps &sourceProps, const RawProps &rawProps)
: Props(sourceProps, rawProps),
YogaStylableProps(sourceProps, rawProps),
AccessibilityProps(sourceProps, rawProps),
opacity(
convertRawProp(rawProps, "opacity", sourceProps.opacity, (Float)1.0)),
foregroundColor(convertRawProp(
rawProps,
"foregroundColor",
sourceProps.foregroundColor)),
backgroundColor(convertRawProp(
rawProps,
"backgroundColor",
sourceProps.backgroundColor)),
borderRadii(convertRawProp(
rawProps,
"border",
"Radius",
sourceProps.borderRadii)),
borderColors(convertRawProp(
rawProps,
"border",
"Color",
sourceProps.borderColors)),
borderStyles(convertRawProp(
rawProps,
"border",
"Style",
sourceProps.borderStyles)),
shadowColor(
convertRawProp(rawProps, "shadowColor", sourceProps.shadowColor)),
shadowOffset(
convertRawProp(rawProps, "shadowOffset", sourceProps.shadowOffset)),
shadowOpacity(
convertRawProp(rawProps, "shadowOpacity", sourceProps.shadowOpacity)),
shadowRadius(
convertRawProp(rawProps, "shadowRadius", sourceProps.shadowRadius)),
transform(convertRawProp(rawProps, "transform", sourceProps.transform)),
backfaceVisibility(convertRawProp(
rawProps,
"backfaceVisibility",
sourceProps.backfaceVisibility)),
shouldRasterize(convertRawProp(
rawProps,
"shouldRasterize",
sourceProps.shouldRasterize)),
zIndex(convertRawProp(rawProps, "zIndex", sourceProps.zIndex)),
pointerEvents(
convertRawProp(rawProps, "pointerEvents", sourceProps.pointerEvents)),
hitSlop(convertRawProp(rawProps, "hitSlop", sourceProps.hitSlop)),
onLayout(convertRawProp(rawProps, "onLayout", sourceProps.onLayout)),
collapsable(convertRawProp(
rawProps,
"collapsable",
sourceProps.collapsable,
true)){};
#pragma mark - Convenience Methods
BorderMetrics ViewProps::resolveBorderMetrics(bool isRTL) const {
auto borderWidths = CascadedBorderWidths{
optionalFloatFromYogaValue(yogaStyle.border[YGEdgeLeft]), // left
optionalFloatFromYogaValue(yogaStyle.border[YGEdgeTop]), // top
optionalFloatFromYogaValue(yogaStyle.border[YGEdgeRight]), // right
optionalFloatFromYogaValue(yogaStyle.border[YGEdgeBottom]), // bottom
optionalFloatFromYogaValue(yogaStyle.border[YGEdgeStart]), // start
optionalFloatFromYogaValue(yogaStyle.border[YGEdgeEnd]), // end
optionalFloatFromYogaValue(
yogaStyle.border[YGEdgeHorizontal]), // horizontal
optionalFloatFromYogaValue(yogaStyle.border[YGEdgeVertical]), // vertical
optionalFloatFromYogaValue(yogaStyle.border[YGEdgeAll]), // all
};
return {
borderColors.resolve(isRTL, {}), // borderColors
borderWidths.resolve(isRTL, 0), // borderWidths
borderRadii.resolve(isRTL, 0), // borderRadii
borderStyles.resolve(isRTL, BorderStyle::Solid), // borderStyles
};
}
#pragma mark - DebugStringConvertible
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList ViewProps::getDebugProps() const {
const auto &defaultViewProps = ViewProps();
return AccessibilityProps::getDebugProps() +
YogaStylableProps::getDebugProps() +
SharedDebugStringConvertibleList{
debugStringConvertibleItem("zIndex", zIndex, defaultViewProps.zIndex),
debugStringConvertibleItem(
"opacity", opacity, defaultViewProps.opacity),
debugStringConvertibleItem(
"foregroundColor",
foregroundColor,
defaultViewProps.foregroundColor),
debugStringConvertibleItem(
"backgroundColor",
backgroundColor,
defaultViewProps.backgroundColor),
};
}
#endif
} // namespace react
} // namespace facebook