Hello,
I took a little bit of a break from looking at this and then decided to come back to it today.
I tried to proceed with a solution using NavigationStack but encountered two issues. I'll detail them below.
My NavigationStack follows this hierarchy. Welcome -> Enter Name -> Enter Job
I use NavigationLink as follows to go from one view to another:
NavigationLink(destination: OnboardingNameView(vc: vc)) {
OnboardingButtonView(buttonString: "next".localized())
}
Issue 01:
If I press Next on WelcomeView, it takes me to EnterNameView as expected. If I hit back to return to WelcomeView, the Next Button no longer works until I force quit and re-open the app.
Issue 02:
On EnterNameView the Next Button is greyed out and can not be pressed. Normally it will appear blue and can be used as normal.
I tested both of these issues in iOS 17 vs iOS 18 using the exact same code. No issues in iOS 17 and everything works as expected.
It seems to fix this I may need to completely re-build every facet of my navigation. This is a lot of work so I opted to look for an alternate solution.
Alternate Solution
Previously I detailed that NavigationView would present a blank screen with a sidebar button. This is still the case. I could never pressed the sidebar button as it would appear outside of the safe area and thus taps would not work. When I added padding I could press the button and it printed this in the console:
unknown display mode: Automatic
With this in mind I found that you can still use NavigationView in iOS 18 with:
.navigationViewStyle(.stack)
It seems that the .automatic navigationViewStyle has been removed in iOS 18 which is why it doesn't work by default.
However I still had an issue. Same code, in iOS 17 it automatically adds safe area insets to NavigationView or NavigationStack, in iOS 18 this is not the case.
I found that if I add 0.5 Vertical Padding as per the below the NavigationView and/or NavigationStack would show as intended:
.padding(.vertical, 0.5)
The only other issue that I am facing is that the slide animation when you navigate forward and back in a NavigationView or NavigationStack does not work in iOS 18 which my existing code. It does work with a clean project using NavigationStack and Rectangles with different colors. I'm not sure what it is in my existing code that causes the animation to break, however the animation works fine in iOS 17. I have seen that a few other developers have had the 'no animation' issue in iOS 18.
As this overarching issue essentially breaks my onboarding process which means new users can not access the app if running iOS 18, I opted for a manual version check workaround. For reference, Apple will not let you use a normal version check for an unreleased iOS Version as per the below:
if #available(iOS 16.0, *)
Please see below for a complete code snippet with all workarounds. I may not have animation on iOS 18 but at least users can use my app as intended on iOS 17 and still access it if they opt to try the iOS 18 Beta.
import SwiftUI
struct FirstLoadOnboardingView: View {
@StateObject var vc: FirstLoadOnboardingViewController
@State private var verticalPadding: Double = 0
var body: some View {
NavigationView {
OnboardingWelcomeView(vc: vc)
}
.navigationViewStyle(.stack)
.padding(.vertical, verticalPadding)
.onAppear {
let systemVersion = UIDevice.current.systemVersion
if systemVersion.contains("18.") {
// Update Vertical Padding for iOS 18
verticalPadding = 0.5
}
}
}
}