-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy pathRNSScreenStackHeaderConfigShadowNode.cpp
More file actions
58 lines (49 loc) · 1.85 KB
/
RNSScreenStackHeaderConfigShadowNode.cpp
File metadata and controls
58 lines (49 loc) · 1.85 KB
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
#include "RNSScreenStackHeaderConfigShadowNode.h"
namespace facebook::react {
extern const char RNSScreenStackHeaderConfigComponentName[] =
"RNSScreenStackHeaderConfig";
void RNSScreenStackHeaderConfigShadowNode::layout(LayoutContext layoutContext) {
YogaLayoutableShadowNode::layout(layoutContext);
#if defined(ANDROID)
const auto &headerProps =
*std::static_pointer_cast<const RNSScreenStackHeaderConfigProps>(
this->getProps());
if (headerProps.translucent) {
// On Android, when header is translucent, the Screen is laid out underneath
// the native header view, therefore HeaderConfig origin already matches
// the toolbar & the correction is not needed.
return;
}
#endif // defined(ANDROID)
applyFrameCorrections();
}
void RNSScreenStackHeaderConfigShadowNode::applyFrameCorrections() {
ensureUnsealed();
const auto &stateData = getStateData();
layoutMetrics_.frame.origin.y = -stateData.frameSize.height;
}
void RNSScreenStackHeaderConfigShadowNode::setLogicalPadding(
Float start,
Float end) const {
ensureUnsealed();
auto style = yogaNode_.style();
style.setPadding(yoga::Edge::Start, yoga::StyleLength::points(start));
style.setPadding(yoga::Edge::End, yoga::StyleLength::points(end));
yogaNode_.setStyle(style);
yogaNode_.setDirty(true);
}
#if !defined(ANDROID)
void RNSScreenStackHeaderConfigShadowNode::setImageLoader(
std::weak_ptr<void> imageLoader) {
getStateDataMutable().setImageLoader(imageLoader);
}
RNSScreenStackHeaderConfigShadowNode::StateData &
RNSScreenStackHeaderConfigShadowNode::getStateDataMutable() {
// We assume that this method is called to mutate the data, so we ensure
// we're unsealed.
ensureUnsealed();
return const_cast<RNSScreenStackHeaderConfigShadowNode::StateData &>(
getStateData());
}
#endif // !defined(ANDROID)
} // namespace facebook::react