Thanks for the reply Nigel.
I stumbled upon this while working on one of the challenges for the Moonshot program in 100 Days of SwiftUI and became fixated on it. You're absolutely right about the title being moved over if the View is too large. I didn't notice it because my title only moved up to the top when scrolling down. Changing the title to .inline exhibits the problem you described.
.navigationBarTitle("Moonshot", displayMode: .inline)
.navigationBarItems(trailing:
Button(action: { self.showingLaunchDate.toggle() }) {
Text(showingLaunchDate ? "Show Crew" : "Show Launch Date")
.frame(width: 150, alignment: .trailing)
Because I added a specific frame width of 150, the text stay aligned to the right side of the nav bar when switching between "Show Crew" and "Show Launch Date".
For now, I think it best not to provide a ternary operator inside the navigation bar that changes between different sized views and just stick with the design guidelines of having minimal complexity.
One final note... it appears that the shifting View happens not only between Long and Short Views, but 2 Views with any difference in width.
For instance, replace the textView function in my example above with this and you'll see that the text will still move back and forth when toggling...
func textView() -> Text {
if showingLongTextView {
return Text("Shorty View")
} else {
return Text("Short view")
}
}
Best, Zoyd