This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BottomSheetViewController: UIViewController { | |
// ... | |
// sub-class of this view controller will call this function to set a content | |
func setContent(content: UIView) { | |
contentView.addSubview(content) | |
NSLayoutConstraint.activate([ | |
content.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), | |
content.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), | |
content.topAnchor.constraint(equalTo: contentView.topAnchor), | |
content.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BottomSheetViewController: UIViewController { | |
// ... | |
private var minTopSpacing: CGFloat = 80 | |
// MARK: - View Setup | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupViews() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class BottomSheetViewController: UIViewController { | |
// MARK: - UI | |
/// Main bottom sheet container view | |
private lazy var mainContainerView: UIView = { | |
let view = UIView() | |
view.translatesAutoresizingMaskIntoConstraints = false | |
view.backgroundColor = .systemBackground | |
view.layer.cornerRadius = 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func showResultScreen() { | |
let homeVC = ResultViewController() | |
navigationController?.pushViewController(homeVC, animated: true) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ResultViewController.swift | |
// | |
import UIKit | |
class ResultViewController: UIViewController { | |
lazy var messageLabel: UILabel = { | |
let label = UILabel() | |
label.text = "Login success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setupPublishers() { | |
// 1 | |
NotificationCenter.default | |
.publisher(for: UITextField.textDidChangeNotification, object: emailTextField) | |
.map { ($0.object as! UITextField).text ?? "" } | |
.assign(to: \.email, on: viewModel) | |
.store(in: &cancellables) | |
NotificationCenter.default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setupViews() { | |
view.addSubview(stackView) | |
stackView.addArrangedSubview(emailTextField) | |
stackView.addArrangedSubview(passwordTextField) | |
stackView.addArrangedSubview(submitButton) | |
stackView.addArrangedSubview(errorLabel) // append the error label here | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy var errorLabel: UILabel = { | |
let label = UILabel() | |
label.text = "Oops, incorrect email or password!" | |
label.textColor = .white | |
label.backgroundColor = .red | |
label.textAlignment = .center | |
label.translatesAutoresizingMaskIntoConstraints = false | |
label.alpha = 0 | |
return label | |
}() |
NewerOlder