Skip to content

fix(navigation-bar): keep the title on one line, clear of the side controls - #58

Open
ross-dash wants to merge 4 commits into
masterfrom
fix/nav-bar-title-inset
Open

ross-dash wants to merge 4 commits into
masterfrom
fix/nav-bar-title-inset

Conversation

@ross-dash

@ross-dash ross-dash commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What

NavigationBar now keeps the central title clear of the side controls and on a single line:

  • The leading and trailing slots are measured, and the central slot is inset on both sides by the wider of them (plus 10pt spacing), so the title stays visually centred.
  • The central slot gets .lineLimit(1).truncationMode(.tail) — a title that does not fit ends in an ellipsis instead of wrapping or running under the back/close circle.
  • With no side controls the inset is the regular 20pt edge padding.
  • docs/navigation-and-containers.md describes the behaviour.

Before / After

navbar-compare-light navbar-compare-dark

Why

Long titles (e.g. merchant names on the Explore details screen in dashwallet-ios) wrapped to two lines and ran under the circle buttons. The app worked around it with a hard-coded horizontal padding in its own wrapper; with this change the wrapper can drop it.

Testing

Checked in dashwallet-ios on the merchant details screen with the longest name in the Explore database: the title shows as one line ending in "…", clear of the back button. Short titles are unchanged and centred.

🤖 Generated with Claude Code

optimisticcreator and others added 2 commits November 10, 2026 14:40
The central slot was overlaid at full width, so a long single-line title
truncated at the bar's edges and drew over the back/close or trailing
circles. The bar now measures both side slots and insets the central one
on both sides by the wider of them, plus the edge padding and a 10pt gap,
keeping the title centered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ross-dash
ross-dash requested a review from romchornyi November 10, 2026 15:33
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@romchornyi-pitcrew romchornyi-pitcrew left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 3 major · 6 non-blocking recommendations · no code blockers, reviewed at 4b4274fdda

Level Verdict
1 · Idea ✅ valid Long titles really do wrap and run under the circle buttons. Fixing it in the bar is better than each host padding by hand
2 · Architecture ✅ right layer It belongs in NavigationBar
3 · Completeness 🟡 untracked gaps No snapshot or preview of the new state. One app host stacks its own padding on top of the new inset
4 · Code 🟡 3 major Repo rules (Before / After, snapshot) and how the side slots are measured

Major

  • Before / After screenshots. The PR changes Sources/, but the description has no light and dark Before / After images and doesn't tick "No visual change". The Before / After screenshots check is red. The template's Breaking Changes and Checklist sections are missing as well.
  • No snapshot for the new state (NavigationBarSnapshotTests). testVariants and the previews render only the short "Title". That fits inside the inset, so the snapshot check passes without testing the change. The repo asks for a snapshot and a preview for every new visual state. Worth covering: a long title truncating, a bar with only a back button, and a central-only bar.
  • A side slot with several views is measured as its widest view (NavigationBar.swift#L42, #L47, #L80-L92). With two views in the builder, the slot is a TupleView, and .background(reader) lands on each child separately. reduce then keeps the max, not the total. For example, trailing: { NavigationBarCircleButton(…); NavigationBarCircleMenu(…) } reports 34pt instead of about 78pt, and a long title runs under the first button, which is the bug this PR fixes. No current host does this, so it's latent. Measuring each slot as one row (HStack(spacing: 0) { leading } before the reader) closes it. (traced in code, not run)
6 non-blocking recommendations
  1. The inset has no upper bound (#L62-L67). With a wide side slot (a text button plus a menu), 2 × inset can pass the bar's width: the title gets a lone "…", and the padded view grows past the bar. Clamp the inset, or keep a minimum title width. (not verified)
  2. First frame. leadingWidth / trailingWidth start at 0, so the first layout uses the 20pt inset, and the title truncates again once the preferences arrive. That can show as a jump during a push, or when a side control appears inside withAnimation. There's no feedback loop: the sides never depend on the inset. (not verified on a device)
  3. Altitude / reuse. With the iOS 18 floor, a small custom Layout could place the three slots in one pass. That removes the state round trip behind points 1 and 2. Short of that, onGeometryChange (or the package's readingFrame) replaces the reader view and the two identical PreferenceKeys.
  4. A central-only bar now gets a 20pt inset (#L65). Before, the central slot spanned the full width. Content that pads itself (a search field, a segmented control) ends up 40pt narrower.
  5. Docs (navigation-and-containers.md#L14-L17). "Always one line" is a default, not a guarantee: a host's own .lineLimit(2) still wins, and non-Text content is only offered less width. "One line by default" plus a sentence on non-Text content would be accurate.
  6. App follow-up. In dashwallet-ios, WalletAccountsScreen.swift#L97-L103 pads its central title by 60pt itself. With this change the two insets add up to about 124pt per side, and a wallet name like "Main wallet (imported 2024)" truncates where it used to fit. That padding should go when the app picks up this version. The merchant-details wrapper the description mentions isn't on the app's develop branch yet.
Review details
  • Layered review: idea → architecture → completeness → code.
  • Code level: the general lane (/code-review high) plus a UI lane covering hosts in this package and in dashwallet-ios, Dynamic Type, VoiceOver, RTL, snapshots and docs.
  • Verifier: the slot-measurement finding was confirmed independently by both lanes.
  • Checked with no finding: RTL, Dynamic Type (bar fonts don't scale), VoiceOver (it reads the full title), the Home logo, and the other app hosts.
  • Nothing was run on a device.

🤖 Reviewed with Claude Code

optimisticcreator and others added 2 commits November 16, 2026 14:25
… row

A small Layout places the three slots, replacing the width preferences:
- a slot with several views is measured as one row, not as its widest view;
- the title gets its inset in the first layout pass, with no jump once
  measurements arrive;
- side slots wider than the bar leave the title no room instead of
  pushing it past the bar's edges;
- with no side slots the central slot spans the full width again.

Adds a long-title snapshot (both sides, back only, two views in one slot,
no sides) and preview, and says "one line by default" in the docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ross-dash

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Addressed in aca5caf (merged with master in fc60924):

Major

  • Before / After. The description has the light and dark images, and the check is green. I'll add the long-title state once CI has rendered its references.
  • Snapshot for the new state. New testLongTitles plus a "NavigationBar Long Titles" preview: a long title with back and info, with back only, with two views in one trailing slot, and with no side slots. CI records the references on the next run; I'll fetch and commit them.
  • A multi-view side slot measured as its widest view. The preference readers are gone. A small Layout places the three slots, and each slot is wrapped as exactly one subview (HStack { leading }, ZStack { central }, HStack { trailing }), so two buttons in one slot are measured together. The snapshot's third bar (refresh + more in one builder) covers it.

Recommendations

  1. No upper bound on the inset. The central slot is offered max(0, width − 2 × inset), so side slots wider than the bar leave it no room instead of growing it past the bar.
  2. First frame. The layout measures the sides and places the title in the same pass, so there is no 0-width first layout and no jump.
  3. Altitude. Done as the Layout suggested; the two PreferenceKeys, the reader view and the @State are removed.
  4. Central-only bar. With no side slots the inset is 0 again, so the central slot spans the full width as before this PR.
  5. Docs. navigation-and-containers.md now describes the layout and says "one line by default": a host's .lineLimit still wins, and non-Text content is only offered the narrower width.
  6. App follow-up. Agreed: the 60pt central padding in WalletAccountsScreen goes in the dashwallet-ios PR that picks up this version.

Not verified: right-to-left. A custom Layout should be mirrored by SwiftUI, but there are no RTL snapshots and I haven't run it on a device.

🤖 Generated with Claude Code

@romchornyi-pitcrew romchornyi-pitcrew left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 1 major (inline) · 3 non-blocking recommendations · no code blockers, re-reviewed at fc609246cf (delta since 4b4274fdda)

Level Verdict
1 · Idea ✅ valid unchanged
2 · Architecture ✅ right layer the bar now lays its three slots out in one pass with a private Layout (NavigationBar.swift#L57)
3 · Completeness 🟡 untracked gaps testLongTitles and a preview cover every new state, but their snapshot references are not committed, so the snapshot job is red
4 · Code ✅ clean slots measured as rows, the inset clamped, no state round trip

Closed since the last review

  • Major: a slot with several views measured as its widest view. Each slot is wrapped in one HStack before the layout reads it (#L39-L49), so two buttons count as their combined width. testLongTitles draws exactly that case.
  • Major: Before / After screenshots. Light and dark comparisons are in the description; the check is green.
  • Rec 1, no upper bound on the inset. The central width is clamped at zero (#L105).
  • Rec 2, first frame. Gone with the Layout: no measured widths in @State, no preference keys.
  • Rec 3, altitude. Done as suggested.
  • Rec 4, central-only bar. No side slots give an inset of 0 (#L96-L100), so the central slot spans the full width as before.
  • Rec 5, docs. "One line by default", the host's .lineLimit and non-Text content are all described.

Major (inline)

  • The testLongTitles references are missing — NavigationBarSnapshotTests.swift#L80 — CI fails with "No reference was found on disk" for long-titles-light and long-titles-dark. testVariants passes unchanged, which also shows short titles lay out exactly as before. Fetching the two references the job recorded (.github/scripts/fetch-snapshots.sh), checking them by eye and committing them turns the job green.
3 non-blocking recommendations
  1. App follow-up, unchanged — WalletAccountsScreen.swift#L97-L103 still pads its central title by 60pt itself; it should drop that padding when the app takes this version.
  2. RTL — the layout places the leading slot at bounds.minX with a .leading anchor. SwiftUI mirrors a custom Layout in a right-to-left environment, so the back button should still land on the right; a quick RTL preview would confirm it. (not verified)
  3. PR description — the template's Breaking Changes and Checklist sections are still missing. "None" is the honest Breaking Changes answer: the public initialisers are unchanged.
Review details
  • Re-review of the delta 4b4274fdda..fc609246cf (aca5caf plus a merge of master), against the findings of the previous review.
  • Levels: idea → architecture → completeness → code. Static read; the snapshot job's log was read for the failure.
  • Checked with no finding: an omitted slot (an empty HStack, width 0), the central slot's height and vertical centring, the 74pt minimum height, VoiceOver order (now leading, central, trailing), a host's own .lineLimit.
  • Nothing was run on a device.

🤖 Reviewed with Claude Code

)
NavigationBar(central: { longTitle() })
}
try assertComponentSnapshots(of: view, named: "long-titles")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major: no reference for this snapshot. The snapshot job fails here with "No reference was found on disk" for long-titles-light and long-titles-dark. Fetch the references the job recorded with .github/scripts/fetch-snapshots.sh, check them by eye (a tail ellipsis clear of the wider side in the first three bars, full width in the last) and commit them.

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.

3 participants