0
votes

Code below:

NavigationView{
            ZStack{
                Color("SmokyBlack").ignoresSafeArea()
                VStack{
                    //ModularContent(titleName: titleName, subtitleText: subtitleText, imageName: imageName)
                        
                    NavigationLink(destination: SecondOnboardingView()){
                        OnboardingButton(buttonText: btnName, updateOnboarding: false)
                    }
                }
            }// parent vstack
            .preferredColorScheme(/*@START_MENU_TOKEN@*/.dark/*@END_MENU_TOKEN@*/)
            .navigationBarHidden(true)
        } //nav view ends

My Issue: https://imgur.com/a/ALBdEBs

The button is clearly being pressed but nothing is happening

edit: code for the button. I have tried changing this button to plain text but it still doesn't work.

struct OnboardingButton: View {
    var buttonText: String
    var updateOnboarding: Bool
    
    @AppStorage("onboardingCheck") var onboardingCheck: Bool?
    
    var body: some View {
        Button(action: {onboardingCheck=updateOnboarding},
            label: {
                ZStack{
                    RoundedRectangle(cornerRadius: 5)
                        .foregroundColor(.white)
                        .frame(width: 300, height: 60, alignment: .center)
                    Text(buttonText)
                        .foregroundColor(.black)
                        .font(.system(size: 20))
                        .fontWeight(.semibold)
                }
            })
            
    }
}
1
NavigationLink is basically a button, so here you likely are triggering the button inside OnboardingButton. Fix by changing from Button to Text in OnboardingButton for example. - George
You should post the code for OnboardingButton. If it is an actual button then it’s action maybe overriding the navigation link’s action. Have you tried using Text instead of your custom button? - Andrew
I have, it does the same thing as posted above - Enscivwy
Edited the post to add the code for the button - Enscivwy

1 Answers

1
votes

I seem to have figured out why.

Button(action: {onboardingCheck=updateOnboarding}, from OnboardingButton seems to only accept true as an answer to continue . To work around this, I simply made a different file that does not use Button() but instead the following:

struct OnboardingButtonTwo: View {
    var buttonText: String
    var body: some View {
        ZStack{
            RoundedRectangle(cornerRadius: 5)
                .foregroundColor(.white)
                .frame(width: 300, height: 60, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
            Text(buttonText)
                .foregroundColor(.black)
                .font(.system(size: 20))
                .fontWeight(.semibold)
        }
        .padding(.bottom, 10)
    }
}