-1

Long story short this is an onboarding view after a user goes through auth. My main navigation of the app uses navigationview but I can't use that for onboarding. I've put a fullscreencover over the main screen for this onboarding stuff.

However, when trying to simply navigate between the views from different files between the onboarding screens, the button doesn't show the other view. I've tried everything under the son from @Appstorage and @Environment stuff but can't get it to work.

Also please note I cut off the bottom of the rest of the file as that had nothing to do with this logic.

import SwiftUI

struct OnboardingTestView: View {
    @State var shouldShowOnboarding = true
    var body: some View {
        if shouldShowOnboarding {
            OffsetChoicesView(shouldShowOnboarding: $shouldShowOnboarding)
        }
        if shouldShowOnboarding == false {
            PersonalInfoView()
        }
    }
}

struct OnboardingTestView_Previews: PreviewProvider {
    static var previews: some View {
        OnboardingTestView()
    }
}

//*********************************************************************
//OffsetChoicesView

struct OffsetChoicesView: View {
    @Binding var shouldShowOnboarding: Bool
    var body: some View {
        
        ZStack {
            Color(#colorLiteral(red: 0.9803921569, green: 0.9568627451, blue: 0.9568627451, alpha: 1)).edgesIgnoringSafeArea(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
            
            VStack {

            Progress1View()
                .padding(.bottom, 40)
                .padding(.top)
            
            Spacer()
                Button(action: {
                    shouldShowOnboarding = false
                }) {
                    NextButtonView()
                        .padding(.top)
                        .padding(.bottom)
                }
            
            }
  • Instead of `if shouldShowOnboarding == false {` try just an `else {` – aheze Aug 18 '21 at 02:37
  • Also, try embedding your if statement inside a `VStack` or `Group` – aheze Aug 18 '21 at 02:40
  • this code shows `PersonalInfoView` on `NextButtonView` button tap to me. p.s. even if you're using `fullScreenCover`, you can declare one more `NavigationView` inside that one and use `NavigationLink` without a problem – Phil Dukhov Aug 18 '21 at 05:54

1 Answers1

0

You can try something like this - utilizes @AppStorage

I was not quite sure what the OffsetChoiceView() parameters are supposed to be.. so I just removed them in the example. This should be whatever your onboarding view is called.

    import SwiftUI

struct OnboardingTestView: View {
    //@State var shouldShowOnboarding = true
    
    @AppStorage("showOnboarding") var showOnboarding: Bool = true
    var body: some View {
        if (showOnboarding == true) {
            OffsetChoicesView()
        } else if (showOnboarding == false) {
            PersonalInfoView()
        }
    }
}

struct OnboardingTestView_Previews: PreviewProvider {
    static var previews: some View {
        OnboardingTestView()
    }
}

//*********************************************************************
//OffsetChoicesView

struct OffsetChoicesView: View {
    //@Binding var shouldShowOnboarding: Bool
    @AppStorage("showOnboarding") var showOnboarding: Bool = false
    var body: some View {
        
        ZStack {
            Color(#colorLiteral(red: 0.9803921569, green: 0.9568627451, blue: 0.9568627451, alpha: 1)).edgesIgnoringSafeArea(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
            
            VStack {

            Progress1View()
                .padding(.bottom, 40)
                .padding(.top)
            
            Spacer()
                Button(action: {
                    showOnboarding = false
                }) {
                    NextButtonView()
                        .padding(.top)
                        .padding(.bottom)
                }
            
            }
nickreps
  • 903
  • 8
  • 20
  • Cant you use `Bool` with `AppStorage` ? – Adrien Aug 18 '21 at 13:32
  • Yes, you should be able to. Try changing AppStorage to the following (on mobile, so best guess): @AppStorage("showOnboarding") var showOnboarding: Bool = false – nickreps Aug 18 '21 at 18:30