forked from ijoshsmith/Wizardry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsernameStepViewController.swift
49 lines (41 loc) · 1.49 KB
/
UsernameStepViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// UsernameStepViewController.swift
// WizardryDemo
//
// Created by Joshua Smith on 5/2/16.
// Copyright © 2016 iJoshSmith. All rights reserved.
//
import UIKit
/// Displays the first step in the Sign Up Wizard, where a username is entered and validated.
final class UsernameStepViewController: UIViewController {
@IBOutlet fileprivate weak var activityIndicator: UIActivityIndicatorView!
@IBOutlet fileprivate weak var usernameTextField: UITextField!
/// The username to display when the view is first shown.
var initialUsername: String?
/// The proposed username entered into the text field.
var currentUsername: String? {
if let username = usernameTextField.text {
return username.trimmingCharacters(in: CharacterSet.whitespaces)
}
else {
return nil
}
}
/// This is set to true when asking the server if the current username is available.
var isCheckingUsernameAvailability: Bool = false {
didSet {
if isCheckingUsernameAvailability {
activityIndicator.startAnimating()
}
else {
activityIndicator.stopAnimating()
}
usernameTextField.isUserInteractionEnabled = (isCheckingUsernameAvailability == false)
}
}
override func viewDidLoad() {
super.viewDidLoad()
usernameTextField.text = initialUsername
usernameTextField.becomeFirstResponder()
}
}