I'm encountering an issue with navigation title behavior in watchOS SwiftUI. When using a String
for the navigation title, long titles automatically scroll as expected. However, when switching to Text
with custom foreground color, the scrolling behavior is lost.
Important Observation: The system Settings app on watchOS successfully displays navigation titles with blue color while maintaining scroll behavior. This suggests it should be technically possible - am I missing some implementation approach?
struct ContentView: View {
var body: some View {
NavigationStack {
NavigationLink("Go Next") {
LinkView()
}
}
}
}
struct LinkView: View {
enum NavigationTitleMode: String {
case string
case text
}
@State private var titleMode: NavigationTitleMode = .string
let title: String = "Watch UI Test Navigation Title"
var body: some View {
switch titleMode {
case .string:
content
.navigationTitle(title)
case .text:
content
.navigationTitle {
Text(title)
.foregroundStyle(.blue)
}
}
}
var content: some View {
VStack {
Text("Mode: \(titleMode.rawValue)")
Button("Change Mode", systemImage: "pencil") {
if titleMode == .string {
titleMode = .text
} else {
titleMode = .string
}
}
}
.padding()
.navigationBarTitleDisplayMode(.inline)
}
}
String Mode:
Text Mode:
Environment
- watchOS 26.0
- Xcode 26.0 (17A324)
- Swift 5.9