|
7 | 7 |
|
8 | 8 | #include "ScrollContentViewShadowNode.h" |
9 | 9 |
|
| 10 | +#include <algorithm> |
10 | 11 | #include <array> |
11 | 12 |
|
12 | 13 | namespace facebook::react { |
@@ -78,16 +79,21 @@ StyleLength resolvedPadding( |
78 | 79 | } |
79 | 80 |
|
80 | 81 | /* |
| 82 | + * The safe area is a floor on the padding, as it is on UIKit's layout |
| 83 | + * margins: the edge takes the larger of its style padding and the inset. |
| 84 | + * Where UIKit already applies the inset as a content inset, the edge keeps |
| 85 | + * what its padding exceeds that by, which lands the content on the same floor. |
81 | 86 | * A percentage padding keeps the edge as the style set it, with no inset |
82 | | - * added, since Yoga holds one length per edge and a percentage has no point |
83 | | - * value to add to. |
| 87 | + * applied, since Yoga holds one length per edge and a percentage has no point |
| 88 | + * value to compare. |
84 | 89 | */ |
85 | | -StyleLength padded(StyleLength value, Float inset) { |
86 | | - if (inset == 0 || value.isPercent()) { |
| 90 | +StyleLength padded(StyleLength value, Float inset, Float contentInset) { |
| 91 | + if ((inset == 0 && contentInset == 0) || value.isPercent()) { |
87 | 92 | return value; |
88 | 93 | } |
89 | | - auto base = value.isPoints() ? value.value().unwrap() : 0.0f; |
90 | | - return StyleLength::points(base + inset); |
| 94 | + auto base = value.isPoints() ? Float{value.value().unwrap()} : Float{0}; |
| 95 | + return StyleLength::points( |
| 96 | + std::max(std::max(base, inset) - contentInset, Float{0})); |
91 | 97 | } |
92 | 98 |
|
93 | 99 | } // namespace |
@@ -131,22 +137,31 @@ void ScrollContentViewShadowNode::applySafeAreaPadding() { |
131 | 137 | const ScrollContentViewState& state, |
132 | 138 | LayoutDirection layoutDirection) { |
133 | 139 | const auto& insets = state.safeAreaPadding; |
| 140 | + const auto& contentInsets = state.contentInsetAdjustment; |
134 | 141 | auto swap = state.swapLeftAndRightInRTL; |
135 | | - if (insets.top != 0 || insets.bottom != 0) { |
| 142 | + if (insets.top != 0 || insets.bottom != 0 || contentInsets.top != 0 || |
| 143 | + contentInsets.bottom != 0) { |
136 | 144 | auto top = padded( |
137 | | - resolvedPadding(style, Edge::Top, layoutDirection, swap), insets.top); |
| 145 | + resolvedPadding(style, Edge::Top, layoutDirection, swap), |
| 146 | + insets.top, |
| 147 | + contentInsets.top); |
138 | 148 | auto bottom = padded( |
139 | 149 | resolvedPadding(style, Edge::Bottom, layoutDirection, swap), |
140 | | - insets.bottom); |
| 150 | + insets.bottom, |
| 151 | + contentInsets.bottom); |
141 | 152 | style.setPadding(Edge::Top, top); |
142 | 153 | style.setPadding(Edge::Bottom, bottom); |
143 | 154 | } |
144 | | - if (insets.left != 0 || insets.right != 0) { |
| 155 | + if (insets.left != 0 || insets.right != 0 || contentInsets.left != 0 || |
| 156 | + contentInsets.right != 0) { |
145 | 157 | auto left = padded( |
146 | | - resolvedPadding(style, Edge::Left, layoutDirection, swap), insets.left); |
| 158 | + resolvedPadding(style, Edge::Left, layoutDirection, swap), |
| 159 | + insets.left, |
| 160 | + contentInsets.left); |
147 | 161 | auto right = padded( |
148 | 162 | resolvedPadding(style, Edge::Right, layoutDirection, swap), |
149 | | - insets.right); |
| 163 | + insets.right, |
| 164 | + contentInsets.right); |
150 | 165 | // The logical edges take precedence over every other padding edge along |
151 | 166 | // the row. The physical edges are cleared, since at layout they are copied |
152 | 167 | // over the logical ones when left and right swap in RTL. |
|
0 commit comments