Commit fb49fca
authored
fix(iOS 26, Stack): center view inside bar button item (#3449)
## Description
Fixes alignment of custom view inside bar button item on iOS 26.
> [!NOTE]
>
> Please note that this will also change positioning of bar button items
with `hidesSharedBackground: true` on iOS 26.
| before | after |
| --- | --- |
| <video
src="https://github.com/user-attachments/assets/d188be5c-48bf-4dee-97e2-599eac487af0"
/> | <video
src="https://github.com/user-attachments/assets/82d5ca33-8ef2-40bb-8d4e-030b0b53054c"
/> |
Closes
#2990.
### Explanation
Starting from iOS 26, custom view inside `UIBarButtonItem` is stretched
to at least 36 width. This causes our `RNSScreenStackHeaderSubview` to
stretch if its width is smaller than 36, leaving subviews in the same
origin (for one subview, it's usually `(0,0)`; that's why it is aligned
to the left, visible in "before" recording).
In order to mitigate this, we add `wrapperView` which will be stretched
by UIKit to required minimum size. `RNSScreenStackHeaderSubview` will be
centered inside of it. Additional constraints and properties needed to
be added to make sure that `wrapperView` is not stretched to all
available space in `UINavigationBar` (this would happen in `headerRight`
if we used only `wrapperView.width >= RNSScreenStackHeaderSubview.width`
constraint):
- `wrapperView.width == RNSScreenStackHeaderSubview.width` - makes sure
that wrapper matches content. By using lower priority than default, we
allow UIKit to "take over" with its minimum width, while maintaining
"fit-content"/"content hugging" behavior,
- `[self setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal]` - prevents stretching to all
available width in `UINavigationBar`.
`RNSScreenStackHeaderSubview` needs to use `intrinsicContentSize` in
order to bridge auto-layout centering and frame size from Yoga.
## Changes
- on iOS 26, add wrapper view between `UIBarButtonItem` and
`RNSScreenStackHeaderSubview`
- center `RNSScreenStackHeaderSubview` inside `wrapperView` while
maintaining correct sizing via auto layout
- use `intrinsicContentSize` to bridge between auto-layout and frames
calculated by Yoga
- fix frame passed to shadow tree (now, `RNSScreenStackHeaderSubview`
can have non-zero offset (which was not the case previously); without
change to `self.bounds`, this offset would be accounted for 2 times when
using `[self convertRect:frame toView:ancestorView]`)
## Test code and steps to reproduce
Run `Test3446`.
## Checklist
- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes1 parent e172686 commit fb49fca
1 file changed
+65
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
91 | | - | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
170 | 173 | | |
171 | 174 | | |
172 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
173 | 183 | | |
| 184 | + | |
174 | 185 | | |
175 | 186 | | |
176 | 187 | | |
| |||
194 | 205 | | |
195 | 206 | | |
196 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
197 | 212 | | |
| 213 | + | |
198 | 214 | | |
199 | 215 | | |
200 | 216 | | |
| 217 | + | |
201 | 218 | | |
202 | 219 | | |
203 | 220 | | |
204 | 221 | | |
205 | 222 | | |
206 | 223 | | |
207 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
208 | 257 | | |
| 258 | + | |
209 | 259 | | |
210 | 260 | | |
| 261 | + | |
211 | 262 | | |
212 | 263 | | |
213 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
214 | 276 | | |
215 | 277 | | |
216 | 278 | | |
| |||
0 commit comments