I need help migrating my code for iOS 16 support:
//
// RegistrationView.swift
// Recosia
//
// Created by Alex Slater on 16/11/2022.
//
import SwiftUI
struct RegistrationView: View {
@State private var email = ""
@State private var username = ""
@State private var fullname = ""
@State private var password = ""
@Environment(\.presentationMode) var presentationMode
@EnvironmentObject var viewModel: AuthViewModel
@State var root = [Root]()
var body: some View {
VStack {
NavigationStack(root: $root) {
//content
.onChange(of: viewModel.didAuthenticateUser) { newValue in
guard newValue else {return}
root.append(.profile)
}.navigationDestination(for: Root.self) { navigation in
switch navigation {
case .profile:
ProfilePhotoSelectorView()
}
}
}
}
// NavigationLink(destination: ProfilePhotoSelectorView(),
// isActive: $viewModel.didAuthenticateUser,
// label: { })
AuthHeaderView(title1: "Sign up", title2: "to Recosia")
VStack(spacing: 40) {
CustomInputField(imageName: "at.circle.fill", placeholderText: "Username", text: $username)
CustomInputField(imageName: "person", placeholderText: "Full Name", text: $fullname)
CustomInputField(imageName: "envelope", placeholderText: "Email", text: $email)
CustomInputField(imageName: "lock",
placeholderText: "Password",
isSecureField: true,
text: $password)
}
.padding(32)
Button {
viewModel.register(withEmail: email,
password: password,
fullname: fullname,
username: username)
} label: {
Text("Create Account")
.font(.headline)
.foregroundColor(.white)
.frame(width: 340, height: 50)
.background(Color(.systemPink))
.clipShape(Capsule())
.padding()
}
.shadow(color: .gray.opacity(0.5), radius: 10, x: 0, y: 0)
Spacer()
Button {
presentationMode.wrappedValue.dismiss()
} label: {
HStack {
Text("Already have an account?")
.font(.caption)
.foregroundColor(Color(.black))
Text("Sign In")
.font(.footnote)
.fontWeight(.semibold)
.foregroundColor(Color(.systemPink))
}
.padding(.bottom, 32)
}
}
.ignoresSafeArea()
}
}
struct RegistrationView_Previews: PreviewProvider {
static var previews: some View {
RegistrationView()
}
}
enum Root {
case profile
}
with the error:
init(destination:isActive:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a NavigationStack or NavigationSplitView
I have tried re-arranging my code but I'm getting confused, can someone help!
Much appreciated :)
I tried using a NavigationStack
with a .navigationDestination
, but it says that it expects other arguments but the code presented above is all I have.