1

Here is the code of login page, navigate from tabview using navigation-link and here I want to pop back once get the api response,

Also if any way to pop back using navigationLink same link push, please let me know.

thanks in advance!!

struct LoginBody: View {
        @ObservedObject var viewModel = LoginViewModel()
        @State private var email: String = ""
        @State private var password: String = ""
    
    @Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode>


var loginButton: some View { 
    Button(action: {
        DispatchQueue.main.async {
            print("Email:- ", email)
            print("Password:- ", password)
            
            viewModel.loginAPI(email: email, password: password)
            
            DispatchQueue.main.asyncAfter(deadline: .now() + 8, execute: {
                print("presentationMode dismiss")
                self.presentationMode.wrappedValue.dismiss()
            })
        }
    }) {
        HStack(alignment: .center) {
            Spacer()
            Text("Login")
                .font(.system(size: 20).bold())
                .frame(alignment: .center)
            Spacer()
        }
    }
    .padding(EdgeInsets(top: 15, leading: 20, bottom: 15, trailing: 20))
    .background(Color(#colorLiteral(red: 0.3340760444, green: 0.764342023, blue: 0.8197288968, alpha: 1)))
    .foregroundColor(Color.white)
    .cornerRadius(5)
    .shadow(color: Color.init(red: 0.0, green: 0.0, blue: 0.0, opacity: 0.4), radius: 2, x: 0, y: 2)
    .frame(height: 40, alignment: .center)
}

}

vipinsaini0
  • 541
  • 1
  • 7
  • 26

1 Answers1

-1

don't know how you get this to compile, but rename "loginButton" to "body".