I've looked into a few other questions regarding this subject (60797431, 57889990), but all refer to the now deprecated init(destination:isActive:label:). I also tried asking Google's AI, however that went terribly...I suppose I got what I expected.
So, is there a relatively simple way to link the NavigationLink to the submission (i.e. pressing enter/return on the phone's keyboard) of the TextField, or is the only option to set up full navigation paths, which I don't really want to do?
Of .navigationDestination
I have tried using the navigationDestination view modifier, but it seems to immediately come with some significant setup, including the absence of an automatic 'Back' button, (when I tap it I go back to the page before, the listing of departments), as well as the lack of a sliding transition, both of which come packaged with NavigationLink.
I understand that this goes hand in hand somewhat with navigation paths.
//MARK: Enter email
struct LoginView: View {
let department: (id: Int, name: String)
@State private var email = ""
@State private var codeView = false
var body: some View {
NavigationStack {
List {
Section {
LabeledContent {
TextField("\("jane.citizen1@icloud.com")", text: $email)
.keyboardType(.emailAddress)
.textInputAutocapitalization(.never)
.submitLabel(.next)
.multilineTextAlignment(.leading)
} label: { Text("Email Address")}
} header: {
VStack(alignment: .leading, spacing: 4) {
Text("Sign In")
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.top, 5)
.font(.largeTitle)
.bold()
.foregroundColor(.primary) // Override default gray header color
Text(department.name)
.frame(maxWidth: .infinity, alignment: .leading)
.font(.title3)
.foregroundColor(.secondary)
}
.listRowInsets(EdgeInsets())
.textCase(nil) // Prevents SwiftUI from forcing ALL CAPS on the header
.padding(.bottom, 10)
}
}
NavigationLink() {
VerificationCodeView(/*...*/)
} label: {
Text("Next").padding(5)
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.padding()
}.background { Colour(.systemGroupedBackground) }
}
}
Plus a couple other questions:
- If I do have to use full navigation paths; given that the navigation prior and to this page are using NavigationLink, will I have to migrate the rest of the pages to the path method as well? Or will I be able to grab the current path, or perhaps the solution is just to start a new path.
- Is it good practice to be using a NavigationStack in every destination view? I'm aware that
NavigationLinks depend on them to an extent, however I don't entirely understand the effect of theNavigationStackon content and mechanics.