Skip to content

Commit c96d707

Browse files
authored
fix(ios): let channel titles use available navigation space (#8137)
Channel titles could truncate while space remained between the navigation buttons. The title was sized before inheriting its displayed fonts, and longer names also hit a fixed 240-point cap. Use Auto Layout and stack views for the title, subtitle, avatar, and presence indicator. UIKit now updates the layout when fonts change without resetting the title frame. The navigation bar constrains the bubble between its buttons; short names remain compact and long names use the available space before truncating. [Before/after simulator captures](#8137 (comment)) ### Validation - All 97 native iOS tests passed on an iPhone 17 Pro running iOS 26.5. Coverage includes inherited text size, increasing and decreasing text size, 320/393/600-point widths, right-to-left avatar placement, presence indicators, and title accessibility/taps. - Exercised the production native header in the simulator and captured the full channel name with its member count after the refactor. No relay/community connection was needed. - [CI passed for the Auto Layout refactor](https://github.com/block/buzz/actions/runs/37644234496), including mobile tests, Android debug, iOS simulator, native pagination accessibility, and unsigned iOS release builds. Mobile push checks also passed. - The earlier broad local gate hit ACP deadline and desktop subprocess timing failures; all failed tests passed on retry, including the complete serialized ACP suite. Remaining checks and builds passed. - Agent review completed. Human app-test confirmation is not applicable under the author's standing Buzz mobile exception. ### Post-merge validation During the mobile release baking period, exercise long channel names at default and larger text sizes on narrow and wide screens; verify Back, Huddle, and title taps remain accessible and do not overlap. buzz-review-completed --------- Signed-off-by: Tom Brow <[email protected]>
1 parent da651ad commit c96d707

2 files changed

Lines changed: 212 additions & 69 deletions

File tree

‎mobile/ios/Runner/IosNavigationBar.swift‎

Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ final class IosNavigationBarFactory: NSObject, FlutterPlatformViewFactory {
2323
}
2424

2525
final class NavigationTitleView: UIVisualEffectView, UIGestureRecognizerDelegate {
26-
var maximumWidth: CGFloat = 240 {
27-
didSet { if maximumWidth != oldValue { invalidateIntrinsicContentSize() } }
28-
}
2926
var onActivate: (() -> Void)?
3027
private let titleLabel = UILabel()
3128
private let subtitleLabel = UILabel()
32-
private var avatarView: UIImageView?
33-
private var presenceView: UIView?
34-
private var subtitlePresenceView: UIView?
29+
private let contentStack = UIStackView()
30+
private let textStack = UIStackView()
31+
private let subtitleStack = UIStackView()
3532

3633
init(title: String?, subtitle: String, color: UIColor) {
3734
if #available(iOS 26.0, *) {
@@ -42,17 +39,36 @@ final class NavigationTitleView: UIVisualEffectView, UIGestureRecognizerDelegate
4239
clipsToBounds = true
4340
layer.cornerCurve = .continuous
4441
titleLabel.text = title
45-
titleLabel.font = .preferredFont(forTextStyle: .headline)
4642
titleLabel.textColor = color
4743
subtitleLabel.text = subtitle
48-
subtitleLabel.font = .preferredFont(forTextStyle: .caption1)
4944
subtitleLabel.textColor = .secondaryLabel
5045
for label in [titleLabel, subtitleLabel] {
5146
label.textAlignment = .center
5247
label.lineBreakMode = .byTruncatingTail
5348
label.adjustsFontForContentSizeCategory = false
54-
contentView.addSubview(label)
49+
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
5550
}
51+
subtitleStack.axis = .horizontal
52+
subtitleStack.alignment = .center
53+
subtitleStack.spacing = 6
54+
subtitleStack.addArrangedSubview(subtitleLabel)
55+
textStack.axis = .vertical
56+
textStack.alignment = .center
57+
textStack.addArrangedSubview(titleLabel)
58+
textStack.addArrangedSubview(subtitleStack)
59+
contentStack.axis = .horizontal
60+
contentStack.alignment = .center
61+
contentStack.spacing = 8
62+
contentStack.addArrangedSubview(textStack)
63+
contentStack.translatesAutoresizingMaskIntoConstraints = false
64+
contentView.addSubview(contentStack)
65+
NSLayoutConstraint.activate([
66+
contentStack.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 12),
67+
contentStack.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -12),
68+
contentStack.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
69+
])
70+
translatesAutoresizingMaskIntoConstraints = false
71+
updateFonts()
5672
// Flutter creates platform views with a zero frame. Keep a nonzero
5773
// intrinsic width and let UINavigationBar compress it between its items.
5874
setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
@@ -64,11 +80,23 @@ final class NavigationTitleView: UIVisualEffectView, UIGestureRecognizerDelegate
6480
}
6581

6682
func setAvatar(_ image: UIImage?, presence: UIColor?) {
67-
let avatar = UIImageView(image: image)
83+
// Bar-item images carry alignment insets; the title owns its 32pt layout.
84+
let avatar = UIImageView(image: image?.withAlignmentRectInsets(.zero))
6885
avatar.accessibilityIdentifier = "dm-navigation-avatar"
6986
avatar.contentMode = .scaleAspectFit
70-
contentView.addSubview(avatar)
71-
avatarView = avatar
87+
let avatarContainer = UIView()
88+
avatar.translatesAutoresizingMaskIntoConstraints = false
89+
avatarContainer.addSubview(avatar)
90+
contentStack.insertArrangedSubview(avatarContainer, at: 0)
91+
NSLayoutConstraint.activate([
92+
avatarContainer.widthAnchor.constraint(equalToConstant: 32),
93+
avatarContainer.heightAnchor.constraint(equalToConstant: 32),
94+
avatar.leadingAnchor.constraint(equalTo: avatarContainer.leadingAnchor),
95+
avatar.trailingAnchor.constraint(equalTo: avatarContainer.trailingAnchor),
96+
avatar.topAnchor.constraint(equalTo: avatarContainer.topAnchor),
97+
avatar.bottomAnchor.constraint(equalTo: avatarContainer.bottomAnchor),
98+
])
99+
textStack.alignment = .leading
72100
for label in [titleLabel, subtitleLabel] { label.textAlignment = .natural }
73101
if let presence {
74102
let badge = UIView()
@@ -77,9 +105,16 @@ final class NavigationTitleView: UIVisualEffectView, UIGestureRecognizerDelegate
77105
badge.layer.borderWidth = 1.5
78106
badge.layer.borderColor = UIColor.systemBackground.cgColor
79107
badge.accessibilityIdentifier = "dm-navigation-presence"
80-
contentView.addSubview(badge)
81-
presenceView = badge
108+
badge.translatesAutoresizingMaskIntoConstraints = false
109+
avatarContainer.addSubview(badge)
110+
NSLayoutConstraint.activate([
111+
badge.widthAnchor.constraint(equalToConstant: 8),
112+
badge.heightAnchor.constraint(equalToConstant: 8),
113+
badge.trailingAnchor.constraint(equalTo: avatarContainer.trailingAnchor),
114+
badge.bottomAnchor.constraint(equalTo: avatarContainer.bottomAnchor),
115+
])
82116
}
117+
invalidateIntrinsicContentSize()
83118
}
84119

85120
func setSubtitlePresence(_ color: UIColor) {
@@ -88,8 +123,11 @@ final class NavigationTitleView: UIVisualEffectView, UIGestureRecognizerDelegate
88123
dot.layer.cornerRadius = 3
89124
dot.isAccessibilityElement = false
90125
dot.accessibilityIdentifier = "dm-navigation-status-dot"
91-
contentView.addSubview(dot)
92-
subtitlePresenceView = dot
126+
subtitleStack.insertArrangedSubview(dot, at: 0)
127+
NSLayoutConstraint.activate([
128+
dot.widthAnchor.constraint(equalToConstant: 6),
129+
dot.heightAnchor.constraint(equalToConstant: 6),
130+
])
93131
invalidateIntrinsicContentSize()
94132
}
95133

@@ -125,13 +163,25 @@ final class NavigationTitleView: UIVisualEffectView, UIGestureRecognizerDelegate
125163
}
126164

127165
override var intrinsicContentSize: CGSize {
128-
CGSize(width: min(maximumWidth, max(titleLabel.intrinsicContentSize.width, subtitleLabel.intrinsicContentSize.width + (subtitlePresenceView == nil ? 0 : 12)) + 24 + (avatarView == nil ? 0 : 40)),
129-
height: max(44, titleLabel.intrinsicContentSize.height + subtitleLabel.intrinsicContentSize.height))
166+
let contentSize = contentStack.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
167+
return CGSize(width: contentSize.width + 24, height: max(44, contentSize.height))
130168
}
131169

132-
override func layoutSubviews() {
133-
super.layoutSubviews()
134-
layer.cornerRadius = bounds.height / 2
170+
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
171+
super.traitCollectionDidChange(previousTraitCollection)
172+
if previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory {
173+
updateFonts()
174+
invalidateIntrinsicContentSize()
175+
setNeedsLayout()
176+
}
177+
}
178+
179+
override func sizeThatFits(_ size: CGSize) -> CGSize {
180+
let desired = intrinsicContentSize
181+
return CGSize(width: min(size.width, desired.width), height: desired.height)
182+
}
183+
184+
private func updateFonts() {
135185
// Compact navigation remains a 44pt toolbar. Scale within that budget;
136186
// the complete title/subtitle remains available as one VoiceOver label.
137187
titleLabel.font = UIFontMetrics(forTextStyle: .headline).scaledFont(
@@ -140,26 +190,11 @@ final class NavigationTitleView: UIVisualEffectView, UIGestureRecognizerDelegate
140190
subtitleLabel.font = UIFontMetrics(forTextStyle: .caption1).scaledFont(
141191
for: .systemFont(ofSize: 12), maximumPointSize: 14,
142192
compatibleWith: traitCollection)
143-
let titleHeight = titleLabel.intrinsicContentSize.height
144-
let subtitleHeight = subtitleLabel.intrinsicContentSize.height
145-
let top = (bounds.height - titleHeight - subtitleHeight) / 2
146-
let hasAvatar = avatarView != nil
147-
let rtl = effectiveUserInterfaceLayoutDirection == .rightToLeft
148-
let textX: CGFloat = hasAvatar && !rtl ? 52 : 12
149-
let textWidth = max(0, bounds.width - 24 - (hasAvatar ? 40 : 0))
150-
titleLabel.frame = CGRect(x: textX, y: top, width: textWidth, height: titleHeight)
151-
subtitleLabel.frame = CGRect(x: textX, y: top + titleHeight, width: textWidth, height: subtitleHeight)
152-
if let dot = subtitlePresenceView {
153-
let labelWidth = min(subtitleLabel.intrinsicContentSize.width, max(0, textWidth - 12))
154-
let groupX = textX + (textWidth - labelWidth - 12) / 2
155-
dot.frame = CGRect(x: rtl ? groupX + labelWidth + 6 : groupX,
156-
y: top + titleHeight + (subtitleHeight - 6) / 2, width: 6, height: 6)
157-
subtitleLabel.frame = CGRect(x: rtl ? groupX : groupX + 12,
158-
y: top + titleHeight, width: labelWidth, height: subtitleHeight)
159-
}
160-
let avatarX: CGFloat = rtl ? bounds.width - 44 : 12
161-
avatarView?.frame = CGRect(x: avatarX, y: (bounds.height - 32) / 2, width: 32, height: 32)
162-
presenceView?.frame = CGRect(x: avatarX + (rtl ? 0 : 24), y: (bounds.height - 32) / 2 + 24, width: 8, height: 8)
193+
}
194+
195+
override func layoutSubviews() {
196+
super.layoutSubviews()
197+
layer.cornerRadius = bounds.height / 2
163198
}
164199
}
165200

0 commit comments

Comments
 (0)