Skip to content

Keep pagers, lists and scroll views right beside a side bar on iOS, and add header-beside - #217

Open
cmcmanus96 wants to merge 4 commits into
NativePHP:mainfrom
cmcmanus96:scroll-edge-under-bars
Open

cmcmanus96 wants to merge 4 commits into
NativePHP:mainfrom
cmcmanus96:scroll-edge-under-bars

Conversation

@cmcmanus96

Copy link
Copy Markdown

Problem

On iOS, a window can have a vertical bar at its side: the iPhone Duo's rail, or the notch on an iPhone held sideways. A horizontal pager beside one goes wrong:

  • The next page shows under the bar.
  • The pager measures a page against visibleRect, which includes the bar's inset, while .paging steps by the scroll view's own width. The tab underline falls further behind on each later tab, and a reported page can be the wrong one.
  • When iOS resizes the window, for example on an unfold or in the background, the pager can come back between two pages.

Lists and scroll views stop short of the bar. Their scroll indicator floats in from the screen edge, and row backgrounds end before the bar. Apple's own lists run under it.

Fix

Four commits, best read one at a time:

  1. Page a horizontal pager by its own width beside a sideways bar. The pager measures a page by geometry.bounds.width and clips its sides, and so does a scrollable tab row. Pages still run under a bar at the bottom. Vertical pagers are unchanged.
  2. Bring a horizontal pager back to its page after iOS resizes it. PagerResume keeps the page the user chose (a tab tap, or a page PHP jumped to) and scrolls back to it once the size settles. It tries twice, then accepts the nearest page and reports it. One geometry sample drives the page, the tab progress and the report, so they can't disagree mid-resize.
  3. Draw a pager's header beside its pages on a wide window. header-beside="expanded" (any breakpoint name, or a width in points) moves a horizontal pager's header into its own leading column once the window is that wide. On a foldable the columns split at the fold, and a half-open fold keeps every control out of the crease. iOS decides from the live window width, so unfolding moves the header without a round trip to PHP. Android keeps the header above the tabs for now.
  4. Run lists and scroll views under a bar at their side. Lists, virtual lists, scroll views and the beside-header column ignore the horizontal container safe area and hand that inset back to their content. Each pager page also spans the side insets, so .paging still steps by exactly one page when the bar moves sides.
Before (main) After (this PR)

Closed iPhone Duo, rail on the left. On main, Trending is selected but the underline sits short of it, and the previous page's text shows under the rail. With this PR, the underline is under Trending and nothing shows under the rail.

Why one PR

I first split this into four PRs, but the middle states are worse than main. With only commits 1 and 2, rotating a closed Duo once moved the pager off Trending to between pages. main doesn't do that, and the whole set doesn't either:

Closed iPhone Duo, Trending selected, 4 rotation round trips Keeps Trending
main 8 of 8 (the previous page shows under the rail)
Commits 1 and 2 0 of 8 (between pages after the first rotation)
All four commits 8 of 8

Unfolding from Trending, 8 times on each build: all four commits held the page exactly every time, and so did commits 1 and 2. Commit 1 alone left a 1 pt sliver of the previous page on 2 of 8.

Commits 1 and 2 alone, after one rotation round trip: the pager is between pages and Latest is selected.

header-beside="expanded" on the unfolded Duo: the profile header in the leading column, the tabs and pages in the trailing one.

For review

  • On a screen with no side inset, such as a portrait iPhone, nothing changes.
  • Commit 2 is most of the diff. PagerPosition, PagerResume and PagerResize hold its state.
  • header-beside is new, opt-in API, iOS only for now.

Test plan

  • Source tests updated for the new geometry path, and new tests for the side clip, headerBeside() (breakpoint names, a width in points, an unknown name throws), and lists running under a side bar. 507 pass. Pint is clean.
  • Built into the /dev/null app (Adapt the app for iPhone Duo dev-null-app#172, which ships these as Composer patches today) and driven on an iPhone Duo simulator (iOS 27.2) with the counts above.
  • Android: no changes beyond headerBeside() parsing, which Android ignores.

Beside a vertical bar (the iPhone Duo's side rail, or a notched iPhone
held sideways) the pager's ScrollView draws into the bar's inset, so
the next page showed under the bar. Its visibleRect takes in that inset
too, so a page measured against it was wider than the step .paging
takes. The reported page and the tab underline fell further behind on
each later page.

A horizontal pager now measures a page by the ScrollView's own width,
which is what .paging steps by, and clips its sides. A scrollable tab
row clips its sides the same way. Pages still run under a bar at the
bottom, and vertical pagers are unchanged.
When iOS resizes the pager, it can come back between two pages. That
happens when iOS resizes the app in the background, or when the Duo
folds or unfolds while the app is in front. PagerResume keeps the page
the user chose, a tab tap or a page PHP jumped to, and scrolls back to
it once the size settles. It tries twice, then gives up, accepts the
nearest page and reports it to PHP. One geometry sample now drives the
page, the tab progress and the report, so they can't disagree mid
resize.
header-beside="expanded" (any breakpoint name, or a width in points)
moves a horizontal pager's header into a leading column of its own once
the window is that wide. The tabs and pages fill the trailing column.
On a foldable the columns split at the fold. When the fold is partly
closed they stop at the edges of its division region, so no control
sits in the crease. Elsewhere the two columns share the width evenly.
Narrower than the breakpoint, the header stays above the tabs, in each
page's list, as before.

Native decides from the live window width, as it does for responsive
classes, so PHP sends the header once and unfolding or Split View moves
it without a round trip. Both layouts share one paging scroll view, so
crossing the breakpoint keeps the page and every page's scroll offset.

iOS only for now. Android keeps the header above the tabs at any width.
Beside a vertical bar (the iPhone Duo's side rail, or a notched iPhone
held sideways) a list stopped at the bar's inset. Its scroll indicator
floated in from the screen edge, and row backgrounds ended short of
the bar. Apple's own lists run under the bar.

Lists, virtual lists, scroll views and a pager's beside-header column
now ignore the horizontal container safe area and hand that inset back
to their content as safe area. Rows stay where they were, their
backgrounds reach under the bar, and the indicator sits at the screen
edge.

A horizontal pager does the same at its sides. Each page now spans the
side insets as well as the bottom one, so .paging still steps by one
page, and the pager measures its page width with the side insets
included.

On a screen with no side inset, such as a portrait iPhone, nothing
changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant