@@ -22,13 +22,17 @@ final class IosNavigationBarFactory: NSObject, FlutterPlatformViewFactory {
2222 }
2323}
2424
25- private final class NavigationTitleView : UIView , UIGestureRecognizerDelegate {
25+ final class NavigationTitleView : UIView , UIGestureRecognizerDelegate {
26+ var maximumWidth : CGFloat = 240 {
27+ didSet { if maximumWidth != oldValue { invalidateIntrinsicContentSize ( ) } }
28+ }
2629 var onActivate : ( ( ) -> Void ) ?
2730 var onExpiryPressed : ( ( String ) -> Void ) ?
2831 private let titleLabel = UILabel ( )
2932 private let subtitleLabel = UILabel ( )
3033 private var avatarView : UIImageView ?
3134 private var presenceView : UIView ?
35+ private var subtitlePresenceView : UIView ?
3236 private var expiryView : UIButton ?
3337
3438 init ( title : String ? , subtitle : String , color : UIColor ) {
@@ -45,6 +49,9 @@ private final class NavigationTitleView: UIView, UIGestureRecognizerDelegate {
4549 label . adjustsFontForContentSizeCategory = false
4650 addSubview ( label )
4751 }
52+ // Flutter creates platform views with a zero frame. Keep a nonzero
53+ // intrinsic width and let UINavigationBar compress it between its items.
54+ setContentCompressionResistancePriority ( . defaultLow , for : . horizontal )
4855 isAccessibilityElement = true
4956 accessibilityTraits = . button
5057 let tap = UITapGestureRecognizer ( target : self , action : #selector( activate ) )
@@ -71,6 +78,17 @@ private final class NavigationTitleView: UIView, UIGestureRecognizerDelegate {
7178 }
7279 }
7380
81+ func setSubtitlePresence ( _ color : UIColor ) {
82+ let dot = UIView ( )
83+ dot . backgroundColor = color
84+ dot . layer . cornerRadius = 3
85+ dot . isAccessibilityElement = false
86+ dot . accessibilityIdentifier = " dm-navigation-status-dot "
87+ addSubview ( dot )
88+ subtitlePresenceView = dot
89+ invalidateIntrinsicContentSize ( )
90+ }
91+
7492 func setEphemeralStatus ( _ label : String ) {
7593 let clock = UIButton ( type : . custom )
7694 clock . setImage ( UIImage ( systemName : " clock " ) , for : . normal )
@@ -86,8 +104,14 @@ private final class NavigationTitleView: UIView, UIGestureRecognizerDelegate {
86104 }
87105
88106 func gestureRecognizer ( _ gestureRecognizer : UIGestureRecognizer , shouldReceive touch : UITouch ) -> Bool {
89- var touched = touch . view
90- while let view = touched {
107+ acceptsTitleTouch ( in : touch . view )
108+ }
109+
110+ // UIKit can wrap titleView in a UIControl. Only controls inside our title
111+ // (such as the retention disclosure) should consume the title tap.
112+ func acceptsTitleTouch ( in touchedView : UIView ? ) -> Bool {
113+ var touched = touchedView
114+ while let view = touched , view !== self {
91115 if view is UIControl { return false }
92116 touched = view . superview
93117 }
@@ -105,7 +129,7 @@ private final class NavigationTitleView: UIView, UIGestureRecognizerDelegate {
105129 }
106130
107131 override var intrinsicContentSize : CGSize {
108- CGSize ( width : max ( titleLabel . intrinsicContentSize . width , subtitleLabel . intrinsicContentSize . width ) + 16 + ( avatarView == nil ? 0 : 40 ) + ( expiryView == nil ? 0 : 44 ) ,
132+ CGSize ( width : min ( maximumWidth , max ( titleLabel . intrinsicContentSize . width , subtitleLabel . intrinsicContentSize . width + ( subtitlePresenceView == nil ? 0 : 12 ) ) + 16 + ( avatarView == nil ? 0 : 40 ) + ( expiryView == nil ? 0 : 44 ) ) ,
109133 height : max ( 44 , titleLabel . intrinsicContentSize . height + subtitleLabel . intrinsicContentSize . height ) )
110134 }
111135
@@ -131,6 +155,14 @@ private final class NavigationTitleView: UIView, UIGestureRecognizerDelegate {
131155 y : 0 , width : 44 , height : bounds . height )
132156 titleLabel . frame = CGRect ( x : textX , y : top , width : textWidth , height : titleHeight )
133157 subtitleLabel . frame = CGRect ( x : textX , y : top + titleHeight , width : textWidth , height : subtitleHeight )
158+ if let dot = subtitlePresenceView {
159+ let labelWidth = min ( subtitleLabel . intrinsicContentSize . width , max ( 0 , textWidth - 12 ) )
160+ let groupX = textX + ( textWidth - labelWidth - 12 ) / 2
161+ dot . frame = CGRect ( x : rtl ? groupX + labelWidth + 6 : groupX ,
162+ y : top + titleHeight + ( subtitleHeight - 6 ) / 2 , width : 6 , height : 6 )
163+ subtitleLabel . frame = CGRect ( x : rtl ? groupX : groupX + 12 ,
164+ y : top + titleHeight , width : labelWidth , height : subtitleHeight )
165+ }
134166 let avatarX : CGFloat = rtl ? bounds . width - 40 : 8
135167 avatarView ? . frame = CGRect ( x : avatarX , y : ( bounds . height - 32 ) / 2 , width : 32 , height : 32 )
136168 presenceView ? . frame = CGRect ( x : avatarX + ( rtl ? 0 : 24 ) , y : ( bounds . height - 32 ) / 2 + 24 , width : 8 , height : 8 )
@@ -232,6 +264,9 @@ private final class IosNavigationBarView: NSObject, FlutterPlatformView {
232264 private func configure ( _ args : [ String : Any ] ) {
233265 navigation . overrideUserInterfaceStyle = args [ " dark " ] as? Bool == true ? . dark : . light
234266 material . overrideUserInterfaceStyle = navigation . overrideUserInterfaceStyle
267+ // Refresh the system material tint whenever the Flutter theme changes.
268+ material . contentView . backgroundColor = args [ " background " ] is NSNumber
269+ ? Self . color ( args [ " background " ] ) . withAlphaComponent ( 0.25 ) : . clear
235270 let bar = navigation . navigationBar
236271 let color = Self . color ( args [ " foreground " ] )
237272 bar . tintColor = color
@@ -248,9 +283,9 @@ private final class IosNavigationBarView: NSObject, FlutterPlatformView {
248283 let largeTitle = args [ " largeTitle " ] as? Bool == true
249284 if bar . prefersLargeTitles != largeTitle { measuredWidth = 0 }
250285 bar . prefersLargeTitles = largeTitle
251- // Compact chat headers can open over a bottom-anchored timeline before
252- // Flutter emits any scroll notification. Keep their title readable at rest .
253- material . alpha = largeTitle ? min ( 1 , offset / 12 ) : 1
286+ // A title alone does not need a backdrop. Reveal material only as the
287+ // page scrolls beneath the navigation controls, for every title size .
288+ material . alpha = min ( 1 , offset / 12 )
254289 // Use the same ultra-thin material and soft lower edge on every page.
255290 // Compact titles have a member-count line, so begin their fade below it
256291 // rather than washing out the subtitle or ending in a hard rectangle.
@@ -279,6 +314,9 @@ private final class IosNavigationBarView: NSObject, FlutterPlatformView {
279314 button . setAvatar ( makeItem ( avatar ) . image ,
280315 presence : args [ " titlePresenceColor " ] is NSNumber ? Self . color ( args [ " titlePresenceColor " ] ) : nil )
281316 }
317+ if args [ " titleAvatar " ] as? [ String : Any ] == nil , args [ " titlePresenceColor " ] is NSNumber {
318+ button . setSubtitlePresence ( Self . color ( args [ " titlePresenceColor " ] ) )
319+ }
282320 if let label = args [ " ephemeralLabel " ] as? String {
283321 button . setEphemeralStatus ( label )
284322 }
@@ -338,7 +376,7 @@ private final class IosNavigationBarView: NSObject, FlutterPlatformView {
338376
339377 private func setScrollOffset ( _ value : CGFloat ) {
340378 offset = max ( 0 , value )
341- material . alpha = navigation . navigationBar . prefersLargeTitles ? min ( 1 , offset / 12 ) : 1
379+ material . alpha = min ( 1 , offset / 12 )
342380 applyScroll ( )
343381 }
344382
@@ -376,6 +414,9 @@ private final class IosNavigationBarView: NSObject, FlutterPlatformView {
376414 ? UIBarButtonItem ( primaryAction : action )
377415 : UIBarButtonItem ( title : action . title , image : action . image , primaryAction : nil ,
378416 menu : UIMenu ( children : children . map ( makeAction ) ) )
417+ if #available( iOS 26 . 0 , * ) {
418+ item . hidesSharedBackground = data [ " plain " ] as? Bool == true
419+ }
379420 item . accessibilityLabel = data [ " label " ] as? String
380421 item . isEnabled = data [ " enabled " ] as? Bool == true
381422 if data [ " avatarInitial " ] is String { item . title = nil }
0 commit comments