// // AppDelegate.swiftmport UIKit import Firebase import GoogleSignIn import FirebaseAuth import FirebaseCore @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate{ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. FirebaseApp.configure() GIDSignIn.sharedInstance()?.clientID = FirebaseApp.app()?.options.clientID GIDSignIn.sharedInstance().delegate = self return true } func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) { // ... if let error = error { print(error.localizedDescription) return } guard let authentication = user.authentication else { return } let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken) Auth.auth().signIn(with: credential) { (res, err) in if err != nil{ print((err?.localizedDescription)!) return } print(res!.user.email ) UserDefaults.standard.set(true, forKey: "status") NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil) } } func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) { // Perform any operations when the user disconnects from app here. // ... } // MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } } // // ContentView.swift import SwiftUI import Firebase import GoogleSignIn import FirebaseAuth struct ContentView: View { @State var status = UserDefaults.standard.value(forKey: "status") as? Bool ?? false var body: some View { VStack{ if status{ Home2() } else{ Home() } }.animation(.spring()) .onAppear(){ NotificationCenter.default.addObserver(forName: NSNotification.Name("statusChange"), object: nil, queue: .main){ (_) in let status = UserDefaults.standard.value(forKey: "status") as? Bool ?? false self.status = status } } //LinearGradient(gradient: .init(colors: [Color("Color"),Color("Color1")]), startPoint: .top, endPoint: .bottom).edgesIgnoringSafeArea(.all) // Home() } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } struct Home: View { @State var index = 0 @State var show = false var body : some View{ ZStack{ VStack{ Image("logo") .resizable() .scaledToFit() HStack{ Button(action: { self.index = 0 }){ Text("Existing") .foregroundColor(self.index == 0 ? .black : .white) .fontWeight(.bold) .padding(.vertical, UIScreen.main.bounds.height * 10/896) .frame(width: ((UIScreen.main.bounds.width / 2 ) - 50)) .font(Font.system(size: setCustomFont())) }.background(self.index == 0 ? Color.white : Color.clear) .clipShape(Capsule()) Button(action: { self.index = 1 }){ Text("New") .foregroundColor(self.index == 1 ? .black : .white) .fontWeight(.bold) .padding(.vertical, UIScreen.main.bounds.height * 10/896) .frame(width: ((UIScreen.main.bounds.width / 2) - 50)) .font(Font.system(size: setCustomFont())) }.background(self.index == 1 ? Color.white : Color.clear) .clipShape(Capsule()) }.background(Color.black.opacity(0.1)) .clipShape(Capsule()) .padding(.top, UIScreen.main.bounds.height * 25/896) if self.index == 0{ Login() }else{ SignUp(show: self.$show) } Button(action: { }) { Text("Forgot Password?") .foregroundColor(.black) .padding(.top, UIScreen.main.bounds.height * 100/896) .font(Font.system(size: setCustomFont())) } HStack(spacing: UIScreen.main.bounds.width * 15/414){ Color.black.opacity(0.7) .frame(width: UIScreen.main.bounds.width * 20/414, height: UIScreen.main.bounds.height * 1/896) Text("Or") .foregroundColor(.black) .font(Font.system(size: setCustomFont())) Color.black.opacity(0.7) .frame(width: UIScreen.main.bounds.width * 20/414, height: UIScreen.main.bounds.height * 1/896) } HStack{ GoogleSignView() } .padding(.top, UIScreen.main.bounds.height * 10/896) } .padding() }.background(LinearGradient(gradient: .init(colors: [Color("Color"),Color("Color1")]), startPoint: .top, endPoint: .bottom).edgesIgnoringSafeArea(.all)) } } struct Login : View{ @State var mail = "" @State var pass = "" @State var msg = "" @State var alert = false @State var hidden = false var body : some View{ VStack{ VStack{ HStack(spacing: UIScreen.main.bounds.width * 15/414){ Image(systemName: "envelope") .foregroundColor(.black) TextField("Enter Email Address", text: self.$mail) .font(Font.system(size: setCustomFont())) }.padding(.vertical, UIScreen.main.bounds.height * 20/896) Divider() ZStack{ HStack{ if self.hidden { HStack(spacing: UIScreen.main.bounds.width * 15/414){ Image(systemName: "lock") .foregroundColor(.black) SecureField("Password", text: self.$pass) .font(Font.system(size: setCustomFont())) } }else{ HStack(spacing: UIScreen.main.bounds.width * 15/414){ Image(systemName: "lock") scaledToFit() .foregroundColor(.black) TextField("Password", text: self.$pass) .font(Font.system(size: setCustomFont())) } } Button(action: { self.hidden.toggle() }) { Image(systemName: self.hidden ? "eye.fill": "eye.slash.fill") .foregroundColor((self.hidden == true ) ? Color.green : Color.secondary) } }.padding(.vertical, UIScreen.main.bounds.height * 20/896) } } .padding(.vertical) .padding(.horizontal, UIScreen.main.bounds.width * 20/414) .background(Color.white) .cornerRadius(10) .padding(.top, UIScreen.main.bounds.height * 25/896) Button(action: { signInWithEmail(email: self.mail, password: self.pass) {(verified, status) in if !verified{ self.msg = status self.alert.toggle() }else{ UserDefaults.standard.set(true, forKey: "status") NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil) } } }) { Text("LOGIN") .fontWeight(.bold) .padding(.vertical) .frame(width: UIScreen.main.bounds.width - 100) .font(Font.system(size: setCustomFont())) } .background( Color.white ) .cornerRadius(20) .padding(.bottom, UIScreen.main.bounds.height * (-1*(40/896))) .padding(.top, UIScreen.main.bounds.height * 20/896) .shadow(radius:25) } .alert(isPresented: $alert) { Alert(title: Text("Error"), message: Text(self.msg), dismissButton: .default(Text("Dk"))) } } } struct SignUp : View{ @State var mail = "" @State var pass = "" @State var repass = "" @State var alert = false @State var msg = "" @State var hidden = false @Binding var show : Bool var body : some View{ VStack{ VStack{ HStack(spacing: UIScreen.main.bounds.width * 15/414){ Image(systemName: "envelope") .foregroundColor(.black) TextField("Enter Email Address", text: self.$mail) .font(Font.system(size: setCustomFont())) }.padding(.vertical, UIScreen.main.bounds.height * 20/896) Divider() HStack(spacing: UIScreen.main.bounds.width * 15/414){ Image(systemName: "lock") .foregroundColor(.black) TextField("Enter Password", text: self.$pass) .font(Font.system(size: setCustomFont())) }.padding(.vertical, UIScreen.main.bounds.height * 20/896) Divider() ZStack{ HStack{ if self.hidden { HStack(spacing: 15){ Image(systemName: "lock") .foregroundColor(.black) SecureField("Re-Enter Passord", text: self.$repass) .font(Font.system(size: setCustomFont())) } }else{ HStack(spacing: UIScreen.main.bounds.width * 15/414){ Image(systemName: "lock") .foregroundColor(.black) TextField("Re-Enter Password", text: self.$repass) .font(Font.system(size: setCustomFont())) } } Button(action: { self.hidden.toggle() }) { Image(systemName: self.hidden ? "eye.fill": "eye.slash.fill") .foregroundColor((self.hidden == true ) ? Color.green : Color.secondary) } }.padding(.vertical, UIScreen.main.bounds.height * 20/896) } }.padding(.vertical, UIScreen.main.bounds.height * 20/896) .padding(.horizontal, UIScreen.main.bounds.width * 20/414) .background(Color.white) .cornerRadius(10) .padding(.top, UIScreen.main.bounds.height * 25/896) Button(action: { signUpWithEmail(email: self.mail, password: self.pass){ (verified, status) in if !verified{ self.msg = status self.alert.toggle() }else{ UserDefaults.standard.set(true, forKey: "status") self.show.toggle() NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil) } } }) { Text("SIGNUP") .font(Font.system(size: setCustomFont())) .fontWeight(.bold) .padding(.vertical) .frame(width: UIScreen.main.bounds.width - 100) } .background( Color.white ) .cornerRadius(20) .padding(.bottom, UIScreen.main.bounds.height * (-1*(40/896))) .padding(.top, UIScreen.main.bounds.height * 20/896) .shadow(radius:25) }.alert (isPresented: $alert){ Alert(title: Text("Error"), message: Text(self.msg), dismissButton: .default(Text(""))) } } } struct GoogleSignView : UIViewRepresentable { func makeUIView(context: UIViewRepresentableContext<GoogleSignView>) -> GIDSignInButton{ let button = GIDSignInButton() button.colorScheme = .dark GIDSignIn.sharedInstance()?.presentingViewController = UIApplication.shared.windows.last?.rootViewController return button } func updateUIView(_ uiView: GIDSignInButton, context: UIViewRepresentableContext<GoogleSignView>) { } } func signInWithEmail(email: String, password: String, completion: @escaping (Bool, String)->Void){ Auth.auth().signIn(withEmail: email, password: password) { (res, err) in if err != nil{ completion(false,(err?.localizedDescription)!) return } completion(true, (res?.user.email)!) } } func signUpWithEmail(email: String, password: String, completion: @escaping (Bool, String)->Void){ Auth.auth().createUser(withEmail: email, password: password) { (res, err) in if err != nil{ completion(false,(err?.localizedDescription)!) return } completion(true, (res?.user.email)!) } } struct Home2 : View { var body : some View{ ZStack{ Color.blue .edgesIgnoringSafeArea(.all) VStack{ Text("Welcome User") .font(.largeTitle) .foregroundColor(.white) .fontWeight(.bold) .multilineTextAlignment(.center) .offset(y: -40) Button(action: { try! Auth.auth().signOut() GIDSignIn.sharedInstance()?.signOut() UserDefaults.standard.set(false, forKey: "status") NotificationCenter.default.post(name: NSNotification.Name("statusChange"), object: nil) }) { HStack{ Image(systemName: "arrow.down.left.circle.fill") Text("Logout") .font(Font.system(size: setCustomFont())) } }.buttonStyle(GradientButtonStyle()) .padding(.top, UIScreen.main.bounds.height * 500/896) } } } } struct GradientButtonStyle: ButtonStyle { func makeBody(configuration: Self.Configuration) -> some View { configuration.label .foregroundColor(Color.blue) .padding() .padding(.horizontal) .frame(width: UIScreen.main.bounds.width - 100 ) .background(Color.white) .cornerRadius(15.0) .scaleEffect(configuration.isPressed ? 1.3 : 1.0) } } struct scaleButton: ButtonStyle { func makeBody(configuration: Self.Configuration) -> some View { configuration.label .scaleEffect(configuration.isPressed ? 1.3 : 1.0) } } func setCustomFont() -> CGFloat { //Current runable device/simulator width find let bounds = UIScreen.main.bounds let width = bounds.size.width // basewidth you have set like your base storybord is IPhoneSE this storybord width 320px. let baseWidth: CGFloat = 414 // "14" font size is defult font size let fontSize = 14 * (width / baseWidth) return fontSize } // // SceneDelegate.swift import UIKit import SwiftUI class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). // Create the SwiftUI view that provides the window contents. let contentView = ContentView() // Use a UIHostingController as window root view controller. if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) window.rootViewController = UIHostingController(rootView: contentView) self.window = window window.makeKeyAndVisible() } } func sceneDidDisconnect(_ scene: UIScene) { // Called as the scene is being released by the system. // This occurs shortly after the scene enters the background, or when its session is discarded. // Release any resources associated with this scene that can be re-created the next time the scene connects. // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). } func sceneDidBecomeActive(_ scene: UIScene) { // Called when the scene has moved from an inactive state to an active state. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. } func sceneWillResignActive(_ scene: UIScene) { // Called when the scene will move from an active state to an inactive state. // This may occur due to temporary interruptions (ex. an incoming phone call). } func sceneWillEnterForeground(_ scene: UIScene) { // Called as the scene transitions from the background to the foreground. // Use this method to undo the changes made on entering the background. } func sceneDidEnterBackground(_ scene: UIScene) { // Called as the scene transitions from the foreground to the background. // Use this method to save data, release shared resources, and store enough scene-specific state information // to restore the scene back to its current state. } }