Repository navigation
[ScrollView][iOS] Restore previous padding behaviour under navigation and tab bars - #60163
Conversation
Alternative: Simplify and just handle the cross axis instead?The result we've ended up with is now similar to simply scoping down our Duo-intended padding additions to the cross-axis only — and we could consider narrowing/reverting. Counterpoints:
System bars are an extension of the insets problem we were already solving — just a special case which I missed until this was tested in a real app. |
|
I might want to rephrase the doc comments tomorrow for clarity, but opening for review first. |
|
Open pick requests to 0.88 for the ScrollView stack of changes were closed. We're focusing on holistically shipping this + blog post comms in 0.89. |
cipolleschi
left a comment
There was a problem hiding this comment.
Approving: this restores padding in the common navigation and tab bar cases. The edge case noted inline is non-blocking and can be addressed in a follow-up.
| CGRect frame = [view convertRect:view.bounds toView:nil]; | ||
| CGRect bounds = window.bounds; | ||
| return UIEdgeInsetsMake( | ||
| MAX(0, insets.top - CGRectGetMinY(frame)), |
There was a problem hiding this comment.
Non-blocking edge case for a follow-up: an ancestor scaled above 1 can expand the converted frame beyond the window and overestimate the window-only inset. In a UIKit probe on an iOS 27 simulator, a full-screen UIScrollView under a UINavigationController, with an ancestor scaled to 1.2 and contentInsetAdjustmentBehavior set to always, retains a 116 pt top adjustment while this helper returns 149.4 pt. RCTWindowSafeAreaContentInset then keeps the 116 pt adjustment, so 20 pt of content-container padding is still absorbed despite the navigation bar.
A follow-up could bound the estimate to the window safe-area contribution UIKit actually propagates and add a native regression test. The added C++ test supplies the already-classified inset, so it does not exercise this helper.
…vigation and tab bars
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D133527191. |
cortinico
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
This pull request was successfully merged by @huntie in c652e84 When will my fix make it into a release? | How to file a pick request? |
… and tab bars ## Summary **Context** Follow-up to #59836, which is on `0.89-stable`. **Problem** With `contentInsetAdjustmentBehavior`, #59836 lays out each edge at the larger of the `contentContainerStyle` padding and the safe area inset. This is ideal for iPhone Duo / iPhone landscape horizontal insets. **However**, for the scrollable axis (when vertical), UIKit's inset also covers any system navigation bar, tab bar or toolbar the scroll view sits under. In this case, absorbing padding smaller than the bar is **unexpected** — a screen under a native stack header (react-native-screens, Expo Router) or above a tab bar loses its top or bottom padding. (Below image is a mock explainer): <img width="760" alt="Mock of iPhone Duo under a solid header: in 0.89.0-rc the list sits flush against the header, with this diff it sits 16 pt below" src="https://github.com/user-attachments/assets/5a017e02-1837-4285-afd0-1bfd7332598a" /> **This diff** Apply the larger-of rule along the scrollable axis **only** on an edge where the window's safe area (the status bar, sensor housing or home indicator) ***alone*** makes up the inset. Where a bar adds to it, the padding adds on top, as in earlier releases: | Vertical ScrollView, `automatic` | 0.88 | 0.89.0-rc | This diff | |---|---|---|---| | Full screen under dynamic island only, 16 pt padding | 59 + 16⚠️ | larger of the two ✅ | larger of the two | | Under a navigation bar, 16 pt padding | bar + 16 | bar + 0 ❌ | ✅ bar + 16 | | Above a tab bar | bar + padding | absorbed ❌ | ✅ bar + padding | | Above the home indicator only | 34 + padding⚠️ | larger of the two ✅ | larger of the two | | Beside the iPhone Duo side bar, 16 pt padding | 16, under the side bar ❌ | larger of the two ✅ | larger of the two | | iPhone in landscape, beside the Dynamic Island, 16 pt padding | inset + 16 ❌ | larger of the two ✅ | larger of the two | **Phrased another way**: Auto-positioning under a system header turns off inset vs padding behaviour. For vertical, this would now only take effect for a full screen view. ScrollViews not against the system edges (e.g. already in a SafeAreaView or under an opaque custom header), are **unchanged**. **Changes** - Across the scrollable axis, unchanged: the larger of the padding and the whole safe area, such as the side bar on iPhone Duo. - Clarify the `contentInsetAdjustmentBehavior` and `contentContainerStyle` docs to match. Changelog: [iOS][Fixed] - **ScrollView**: With `contentInsetAdjustmentBehavior`, `contentContainerStyle` padding adds to an inset that includes a navigation bar, tab bar or toolbar, instead of being absorbed by it ## Test Plan Set up temporarily in RNTester: the full screen ScrollView example under a native navigation bar, with 20 pt padding (green). (**Ignore** white gap above the navigation bar, this is a separate Duo bug.) | iPhone Duo folded, before | after | |---|---| | <img src="https://github.com/user-attachments/assets/dd242b39-940d-489c-8fcb-a7d68504409b" width="300" /> | <img src="https://github.com/user-attachments/assets/7740f26f-d0ce-420f-b19a-6b485cc94d51" width="300" /> | | ❌ The navigation bar inset absorbs the padding, so the content sits flush against the bar | ✅ The 20 pt padding adds below the bar | - `RCTScrollViewComponentView.mm` compiles in an RNTester simulator build. - `ScrollContentViewTest.cpp`: added `keepsColumnPaddingBelowANavigationBar`. Differential Revision: D133527191 Pull Request resolved: #60163 (cherry picked from commit c652e84)
|
This pull request was successfully merged by @huntie in 3cf0cfb When will my fix make it into a release? | How to file a pick request? |
Summary
Context
Follow-up to #59836, which is on
0.89-stable.Problem
With
contentInsetAdjustmentBehavior, #59836 lays out each edge at the larger of thecontentContainerStylepadding and the safe area inset.This is ideal for iPhone Duo / iPhone landscape horizontal insets. However, for the scrollable axis (when vertical), UIKit's inset also covers any system navigation bar, tab bar or toolbar the scroll view sits under. In this case, absorbing padding smaller than the bar is unexpected — a screen under a native stack header (react-native-screens, Expo Router) or above a tab bar loses its top or bottom padding.
(Below image is a mock explainer):
This diff
Apply the larger-of rule along the scrollable axis only on an edge where the window's safe area (the status bar, sensor housing or home indicator) alone makes up the inset. Where a bar adds to it, the padding adds on top, as in earlier releases:
automaticPhrased another way: Auto-positioning under a system header turns off inset vs padding behaviour. For vertical, this would now only take effect for a full screen view.
ScrollViews not against the system edges (e.g. already in a SafeAreaView or under an opaque custom header), are unchanged.
Changes
contentInsetAdjustmentBehaviorandcontentContainerStyledocs to match.Changelog:
[iOS][Fixed] - ScrollView: With
contentInsetAdjustmentBehavior,contentContainerStylepadding adds to an inset that includes a navigation bar, tab bar or toolbar, instead of being absorbed by itTest Plan
Set up temporarily in RNTester: the full screen ScrollView example under a native navigation bar, with 20 pt padding (green).
(Ignore white gap above the navigation bar, this is a separate Duo bug.)
RCTScrollViewComponentView.mmcompiles in an RNTester simulator build.ScrollContentViewTest.cpp: addedkeepsColumnPaddingBelowANavigationBar.