This is the login View
struct loginView: View {
@State var viewModelLogin = LoginViewViewModel()
@State private var path = NavigationPath()
var body: some View {
ZStack{
Color.default
.ignoresSafeArea(.all)
VStack{
VStack{
Image("headsmainlogo")
Text(loginScreenText.loginHeadText).font((Font.custom("Hanuman-Bold", size:48)))
.bold()
.foregroundColor(Color("HeadsTitleColor"))
Text(loginScreenText.loginSubHeadingText)
.font(.system(size: 11))
.foregroundColor(Color("subheadingHeads"))
Text(loginScreenText.loginSubHeadingText2)
.font(.system(size: 11))
.foregroundColor(Color("subheadingHeads"))
Spacer()
}
ZStack{
RoundedRectangle(cornerRadius: 26)
.fill(Color.white)
.frame(width: 366, height: 512)
.shadow(radius: 7)
.overlay(
RoundedRectangle(cornerRadius: 26)
.stroke(Color.white, lineWidth: 2)
)
VStack{
Text(loginScreenText.loginText)
.padding(.top,33)
.font(.system(size: 24))
.bold()
Text(loginScreenText.loginSubHeadingText)
.padding(.top,1)
.font(.system(size: 12))
Text(loginScreenText.loginSubHeadingText2)
.font(.system(size: 12))
.padding(.bottom,25)
//if somehow login form is empty to show the error message
ZStack {
if viewModelLogin.errorMessage.isEmpty{
Text(viewModelLogin.errorMessage)
.foregroundColor(.red)
}
//Email or user id Text filed
TextField(loginScreenText.loginUserId, text: $viewModelLogin.email)
.autocorrectionDisabled()
.autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
.foregroundColor(.black)
.padding(.horizontal, 34)
.padding(.vertical, 4)
.padding(10)
.overlay(
HStack {
Image(systemName: "person")
.foregroundColor(Color("iconColor"))
.padding(.leading, 20)
Spacer()
}
)
.overlay(RoundedRectangle(cornerRadius: 25).stroke(Color.gray, lineWidth: 1))
.frame(width: 318, height: 46)
// Password TextField
SecureField(loginScreenText.loginPassword, text: $viewModelLogin.password)
.autocorrectionDisabled()
.autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
.foregroundColor(.black)
.padding(.horizontal, 34)
.padding(.vertical, 4)
.padding(10)
.overlay(
HStack {
Image(systemName: "lock")
.foregroundColor(Color("iconColor"))
.padding(.leading, 20)
Spacer()
Image(systemName: "eye")
.foregroundColor(Color("iconColor"))
.padding(.trailing, 20)
}
)
.overlay(RoundedRectangle(cornerRadius: 25).stroke(Color.gray, lineWidth: 1))
.frame(width: 318, height: 46)
.offset(y: 70)
.textContentType(.password)
}
Spacer()
}
Button(action: {
viewModelLogin.login()
}, label: {
Text(loginScreenText.loginContinueButton).font((Font.custom("Inter-Var...slnt,wght", size:17)).leading(.tight))
.foregroundColor(.white)
.bold()
.padding(.vertical,12)
.padding(.horizontal,32)
.frame(width: 318, height: 48)
.background(Color.blue)
.cornerRadius(100)
})
.offset(y:54)
VStack {
Text(loginScreenText.loginHavingSomeTrouble)
.font(.system(size: 12))
Link(destination: URL(string: "https://www.apple.com")!) {
Text(loginScreenText.loginLodgeGrievenceText)
.underline()
.font(.system(size: 16))
}
}
.offset(y: 165)
}
}
}
}
}
#Preview {
loginView()
}
This is View modal of login
import Foundation
class LoginViewViewModel:ObservableObject{
@Published var email=""
@Published var password=""
@Published var errorMessage=""
init(email: String = "", passw ord: String = "") {
self.email = email
self.password = password
}
func login(){
guard validatelogin() else{
return
}
}
func validatelogin()->Bool{
errorMessage=""
guard !email.trimmingCharacters(in: .whitespaces).isEmpty, !password.trimmingCharacters(in:.whitespaces).isEmpty else{
errorMessage="please fill the data"
return false
}
guard email.contains("@") && email.contains(".") else{
errorMessage="please enter a valid email"
return false
}
return true
}
}
This is the main content view
struct ContentView: View {
@State private var showSplash=true
var body: some View {
ZStack{
if showSplash{
splashView()
.transition(.opacity)
.animation(.easeOut(duration: 2.5))
}else{
loginView()
}
}
.onAppear{
DispatchQueue.main
.asyncAfter(deadline: .now() + 3)
{
withAnimation{
self.showSplash=false
}
}
}
}
}
#Preview {
ContentView()
}
I want to navigate to dashboard view that I created so I want when it will login in it should navigate to the dashboard and if it is move to the dashboard page it should not have the back button to go the login page
i have different type to naviagte this but didinot work
if anyone will solve this please use the NavigationStack