Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'init(destination:isActive:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a NavigationStack or NavigationSplitView

I have tried different iterations of examples posted on this site but nothing is going right.

I have also tried following the examples listed here:

Navigation to new navigation types:

I am getting the warning in this posts' title for deprecation of NavigationLink(destination:isActive)

struct PhoneLogin: View {
    @StateObject var phoneLoginData = PhoneLoginViewModel()
    @State var isSmall = UIScreen.main.bounds.height < 750
    
    var body: some View {
        VStack {
            VStack {
                Text("Continue With Phone")
                    .font(.title2)
                    .fontWeight(.bold)
                    .foregroundColor(.black)
                    .padding()
                
                Image("phone_logo")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .padding()
                
                Text("You'll receive a 4-digit code \n to verify next")
                    .font(isSmall ? .none : .title2)
                    .foregroundColor(.gray)
                    .multilineTextAlignment(.center)
                    .padding()
                
                // Mobile Number Field . . . . .
                
                HStack {
                    VStack(alignment: .leading, spacing: 6) {
                        Text("Enter Your Number")
                            .font(.caption)
                            .foregroundColor(.gray)
                        
                        Text("+ \(phoneLoginData.getCountryCode()) \(phoneLoginData.phNo)")
                            .font(.title2)
                            .fontWeight(.bold)
                            .foregroundColor(.black)
                    }
                    
                    Spacer(minLength: 0)

                    NavigationLink(
                        destination: Verification(phoneLoginData: phoneLoginData), isActive: $phoneLoginData.goToVerify) {
                        
                        Text("")
                            .hidden()
                    }
                    
                    Button(action: phoneLoginData.sendCode, label: {
                        Text("Continue")
                            .foregroundColor(.black)
                            .padding(.vertical, 18)
                            .padding(.horizontal, 38)
                            .background(Color.yellow)
                            .cornerRadius(15)
                    })
                    
                    .disabled(phoneLoginData.phNo == "" ? true : false)
                }
                .padding()
                .background(Color.white)
                .cornerRadius(20)
                .shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: -5)
            }
            .frame(height: UIScreen.main.bounds.height / 1.8)
            .background(Color.white)
            .cornerRadius(20)
            
            // Custom Number Pad
            CustomNumberPad(value: $phoneLoginData.phNo, isVerify: false)
        }
        .background(Color("bg").ignoresSafeArea(.all, edges: .bottom))
    }
}
like image 786
LizG Avatar asked Sep 12 '25 03:09

LizG


1 Answers

I finally figured it out:

REPLACED:

NavigationLink(
     destination: Verification(phoneLoginData: phoneLoginData), 
     isActive: $phoneLoginData.goToVerify) {
          Text("")
               .hidden()
     }

WITH:

Making sure the below code is placed anywhere inside a NavigationStack (ios 16):

.navigationDestination(
     isPresented: $phoneLoginData.goToVerify) {
          Verification(phoneLoginData: phoneLoginData)
          Text("")
              .hidden()
     }
like image 172
LizG Avatar answered Sep 16 '25 08:09

LizG