From 027d686eb730b3f18245342303e28963b49443cb Mon Sep 17 00:00:00 2001 From: Drew Cortright Date: Wed, 6 Jun 2018 22:31:05 -0700 Subject: [PATCH] UserName Text Field Added in an optional username text field in the sign up view controller. --- LoginKit/Assets/SignupViewController.xib | 62 +++++++++++++++++++-- LoginKit/Classes/LoginCoordinator.swift | 22 +++++--- LoginKit/Classes/SignupViewController.swift | 15 ++++- 3 files changed, 85 insertions(+), 14 deletions(-) diff --git a/LoginKit/Assets/SignupViewController.xib b/LoginKit/Assets/SignupViewController.xib index 276a34c..62d9d51 100644 --- a/LoginKit/Assets/SignupViewController.xib +++ b/LoginKit/Assets/SignupViewController.xib @@ -1,10 +1,11 @@ - + - + + @@ -17,6 +18,7 @@ + @@ -94,7 +96,7 @@ - + @@ -145,8 +147,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/LoginKit/Classes/LoginCoordinator.swift b/LoginKit/Classes/LoginCoordinator.swift index 37b7e82..f8e23b2 100644 --- a/LoginKit/Classes/LoginCoordinator.swift +++ b/LoginKit/Classes/LoginCoordinator.swift @@ -28,11 +28,13 @@ public protocol ConfigurationSource { var passwordPlaceholder: String { get } var repeatPasswordPlaceholder: String { get } var namePlaceholder: String { get } - + var userNamePlaceholder: String { get } + var shouldShowSignupButton: Bool { get } var shouldShowLoginButton: Bool { get } var shouldShowFacebookButton: Bool { get } var shouldShowForgotPassword: Bool { get } + var shouldShowUserName: Bool { get } } @@ -56,12 +58,14 @@ public struct DefaultConfiguration: ConfigurationSource { public var passwordPlaceholder: String public var repeatPasswordPlaceholder: String public var namePlaceholder: String - + public var userNamePlaceholder: String + public var shouldShowSignupButton: Bool public var shouldShowLoginButton: Bool public var shouldShowFacebookButton: Bool public var shouldShowForgotPassword: Bool - + public var shouldShowUserName: Bool + public init(backgroundImage: UIImage = UIImage(), backgroundImageGradient: Bool = true, mainLogoImage: UIImage = UIImage(), @@ -77,10 +81,12 @@ public struct DefaultConfiguration: ConfigurationSource { passwordPlaceholder: String = "Password", repeatPasswordPlaceholder: String = "Repeat Password", namePlaceholder: String = "Full Name", + userNamePlaceholder: String = "User Name", shouldShowSignupButton: Bool = true, shouldShowLoginButton: Bool = true, shouldShowFacebookButton: Bool = true, - shouldShowForgotPassword: Bool = true) { + shouldShowForgotPassword: Bool = true, + shouldShowUserName: Bool = true) { self.backgroundImage = backgroundImage self.backgroundImageGradient = backgroundImageGradient self.mainLogoImage = mainLogoImage @@ -96,10 +102,12 @@ public struct DefaultConfiguration: ConfigurationSource { self.passwordPlaceholder = passwordPlaceholder self.repeatPasswordPlaceholder = repeatPasswordPlaceholder self.namePlaceholder = namePlaceholder + self.userNamePlaceholder = userNamePlaceholder self.shouldShowSignupButton = shouldShowSignupButton self.shouldShowLoginButton = shouldShowLoginButton self.shouldShowFacebookButton = shouldShowFacebookButton self.shouldShowForgotPassword = shouldShowForgotPassword + self.shouldShowUserName = shouldShowUserName } } @@ -219,7 +227,7 @@ open class LoginCoordinator { print("Implement this method in your subclass to handle login.") } - open func signup(name: String, email: String, password: String) { + open func signup(name: String, userName: String, email: String, password: String) { print("Implement this method in your subclass to handle signup.") } @@ -298,8 +306,8 @@ extension LoginCoordinator: LoginViewControllerDelegate { extension LoginCoordinator: SignupViewControllerDelegate { - public func didSelectSignup(_ viewController: UIViewController, email: String, name: String, password: String) { - signup(name: name, email: email, password: password) + public func didSelectSignup(_ viewController: UIViewController, email: String, name: String, userName: String, password: String) { + signup(name: name, userName: userName, email: email, password: password) } public func signupDidSelectBack(_ viewController: UIViewController) { diff --git a/LoginKit/Classes/SignupViewController.swift b/LoginKit/Classes/SignupViewController.swift index cfedade..4b9ec32 100644 --- a/LoginKit/Classes/SignupViewController.swift +++ b/LoginKit/Classes/SignupViewController.swift @@ -11,7 +11,7 @@ import Validator public protocol SignupViewControllerDelegate: class { - func didSelectSignup(_ viewController: UIViewController, email: String, name: String, password: String) + func didSelectSignup(_ viewController: UIViewController, email: String, name: String, userName: String, password: String) func signupDidSelectBack(_ viewController: UIViewController) } @@ -53,6 +53,7 @@ open class SignupViewController: UIViewController, KeyboardMovable, BackgroundMo @IBOutlet var fields: [SkyFloatingLabelTextField]! @IBOutlet weak var emailTextField: SkyFloatingLabelTextField! @IBOutlet weak var nameTextField: SkyFloatingLabelTextField! + @IBOutlet weak var userNameTextField: SkyFloatingLabelTextField! @IBOutlet weak var passwordTextField: SkyFloatingLabelTextField! @IBOutlet weak var repeatPasswordTextField: SkyFloatingLabelTextField! @IBOutlet weak var backgroundImageView: GradientImageView! @@ -95,6 +96,7 @@ open class SignupViewController: UIViewController, KeyboardMovable, BackgroundMo } func applyConfiguration() { + view.backgroundColor = configuration.tintColor signupButton.setTitle(configuration.signupButtonText, for: .normal) @@ -112,6 +114,13 @@ open class SignupViewController: UIViewController, KeyboardMovable, BackgroundMo passwordTextField.errorColor = configuration.errorTintColor repeatPasswordTextField.placeholder = configuration.repeatPasswordPlaceholder repeatPasswordTextField.errorColor = configuration.errorTintColor + + if(configuration.shouldShowUserName) { + userNameTextField.placeholder = configuration.userNamePlaceholder + userNameTextField.errorColor = configuration.errorTintColor + } else { + userNameTextField.removeFromSuperview() + } } func setupFonts() { @@ -129,13 +138,13 @@ open class SignupViewController: UIViewController, KeyboardMovable, BackgroundMo } @IBAction func didSelectSignup(_ sender: AnyObject) { - guard let email = emailTextField.text, let name = nameTextField.text, let password = passwordTextField.text else { + guard let email = emailTextField.text, let name = nameTextField.text, let userName = userNameTextField.text, let password = passwordTextField.text else { return } signupAttempted = true validateFields { - delegate?.didSelectSignup(self, email: email, name: name, password: password) + delegate?.didSelectSignup(self, email: email, name: name, userName: userName, password: password) } }