@@ -0,0 +1,140 @@
1+//
2+// LogInViewController.swift
3+// NewsFeed
4+//
5+// Created by cstore on 20/01/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class InviteViewController: UIViewController {
12+
13+ @IBOutlet weak var mailTextField: UITextField!
14+
15+ @IBOutlet weak var inviteLabel: UILabel!
16+
17+ static let titleColor = UIColor(red: 0, green: 137/255, blue: 249/255, alpha: 0.5)
18+
19+ var bottomConstraint: NSLayoutConstraint?
20+
21+ let logInButton: UIButton = {
22+ let button = UIButton(type: .system)
23+ button.setTitle("Invite", for: .normal)
24+ button.setTitleColor(titleColor, for: .normal)
25+ button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
26+ button.isEnabled = false
27+ button.addTarget(self, action: #selector(activateLogInProcess), for: .touchUpInside)
28+ return button
29+ }()
30+
31+ let keyboardBar: UIView = {
32+ let view = UIView()
33+ view.backgroundColor = .white
34+ return view
35+ }()
36+
37+ override func viewDidLoad() {
38+ super.viewDidLoad()
39+ setUpView()
40+ configureTapgesture()
41+ }
42+
43+ override func viewWillAppear(_ animated: Bool) {
44+ super.viewWillAppear(animated)
45+ // MARK:- uncomment when mail registration will be availiable
46+ //self.navigationController?.setNavigationBarHidden(true, animated: animated)
47+
48+
49+ navigationController?.navigationBar.prefersLargeTitles = false
50+ }
51+
52+ override func viewWillDisappear(_ animated: Bool) {
53+ super.viewWillDisappear(animated)
54+ // MARK:- uncomment when mail registration will be availiable
55+ //self.navigationController?.setNavigationBarHidden(false, animated: animated)
56+ }
57+
58+ private func configureTapgesture(){
59+ let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
60+ view.addGestureRecognizer(tapGesture)
61+ }
62+
63+ @objc func handleTap(){
64+ view.endEditing(true)
65+ }
66+
67+ @objc func activateLogInProcess(){
68+ if logInButton.isEnabled {
69+ // instead of transporting user for new vc, make him a sign that everything was complete
70+ inviteLabel.text?.append(" ✅")
71+ view.endEditing(true)
72+ }
73+ }
74+
75+ func setUpView(){
76+ mailTextField.delegate = self
77+ view.addSubview(keyboardBar)
78+
79+ view.addConstraintsWithFormat(format: "H:|[v0]|", views: keyboardBar)
80+ view.addConstraintsWithFormat(format: "V:[v0(50)]", views: keyboardBar)
81+
82+ setUpBarComponents()
83+
84+ bottomConstraint = NSLayoutConstraint(item: keyboardBar, attribute: .bottom, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0)
85+ view.addConstraint(bottomConstraint!)
86+
87+ // for keyboard notifications
88+ NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotifications), name: UIResponder.keyboardWillShowNotification, object: nil)
89+
90+ NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotifications), name: UIResponder.keyboardWillHideNotification, object: nil)
91+
92+ // for log in button notifications
93+ NotificationCenter.default.addObserver(self, selector: #selector(inputDidChanged), name: UITextField.textDidChangeNotification, object: mailTextField)
94+
95+ NotificationCenter.default.addObserver(self, selector: #selector(inputDidChanged), name: UITextField.textDidBeginEditingNotification, object: mailTextField)
96+ }
97+
98+
99+ @objc func inputDidChanged(notification: NSNotification){
100+ if mailTextField.text?.isEmpty ?? true
101+ {
102+ logInButton.isEnabled = false
103+ logInButton.setTitleColor(InviteViewController.titleColor.withAlphaComponent(0.5), for: .normal)
104+ }
105+ else
106+ {
107+ logInButton.isEnabled = true
108+ logInButton.setTitleColor(InviteViewController.titleColor.withAlphaComponent(1), for: .normal)
109+ }
110+ }
111+
112+ @objc func handleKeyboardNotifications(notification: NSNotification){
113+ if let userInfo = notification.userInfo{
114+ // UIKeyboardFrameEndUserInfoKey
115+ let keyBoardFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
116+ bottomConstraint?.constant = notification.name == UIResponder.keyboardWillShowNotification ? -keyBoardFrame.height+view.safeAreaInsets.bottom : 0
117+
118+ UIView.animate(withDuration: 0, delay: 0, options: .curveEaseOut, animations: {
119+ self.view.layoutIfNeeded()
120+ }) { (completed) in
121+
122+ }
123+ }
124+ }
125+
126+ func setUpBarComponents(){
127+ keyboardBar.addSubview(logInButton)
128+ keyboardBar.addConstraintsWithFormat(format: "H:[v0(60)]-16-|", views: logInButton)
129+ keyboardBar.addConstraintsWithFormat(format: "V:|[v0]|", views: logInButton)
130+ }
131+}
132+
133+
134+extension InviteViewController: UITextFieldDelegate{
135+ func textFieldShouldReturn(_ textField: UITextField) -> Bool
136+ {
137+ textField.resignFirstResponder()
138+ return true
139+ }
140+}