2022-11-10 17:52:48 +01:00
|
|
|
//
|
|
|
|
// MastodonLoginView.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Nathan Mattes on 10.11.22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import MastodonAsset
|
|
|
|
|
|
|
|
class MastodonLoginView: UIView {
|
|
|
|
|
|
|
|
// List with (filtered) domains
|
|
|
|
|
2022-11-10 18:32:00 +01:00
|
|
|
let titleLabel: UILabel
|
|
|
|
let subtitleLabel: UILabel
|
|
|
|
private let headerStackView: UIStackView
|
2022-11-11 18:46:06 +01:00
|
|
|
let searchTextField: UITextField
|
|
|
|
let tableView: UITableView
|
2022-11-13 00:22:22 +01:00
|
|
|
private var tableViewWrapper: UIView
|
2022-11-10 17:52:48 +01:00
|
|
|
let navigationActionView: NavigationActionView
|
2022-11-13 14:30:05 +01:00
|
|
|
var bottomConstraint: NSLayoutConstraint?
|
2022-11-10 17:52:48 +01:00
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
2022-11-10 18:32:00 +01:00
|
|
|
|
|
|
|
titleLabel = UILabel()
|
|
|
|
titleLabel.font = MastodonLoginViewController.largeTitleFont
|
|
|
|
titleLabel.textColor = MastodonLoginViewController.largeTitleTextColor
|
|
|
|
titleLabel.text = "Welcome Back" //TODO: @zeitschlag localization
|
|
|
|
titleLabel.numberOfLines = 0
|
|
|
|
|
|
|
|
subtitleLabel = UILabel()
|
|
|
|
subtitleLabel.font = MastodonLoginViewController.subTitleFont
|
|
|
|
subtitleLabel.textColor = MastodonLoginViewController.subTitleTextColor
|
|
|
|
subtitleLabel.text = "Log you in with the server where you created your account" //TODO: @zeitschlag localization
|
|
|
|
subtitleLabel.numberOfLines = 0
|
|
|
|
|
|
|
|
headerStackView = UIStackView(arrangedSubviews: [titleLabel, subtitleLabel])
|
|
|
|
headerStackView.axis = .vertical
|
|
|
|
headerStackView.spacing = 16
|
|
|
|
headerStackView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
2022-11-11 18:46:06 +01:00
|
|
|
searchTextField = UITextField()
|
|
|
|
searchTextField.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
searchTextField.backgroundColor = Asset.Scene.Onboarding.textFieldBackground.color
|
2022-11-12 23:39:58 +01:00
|
|
|
searchTextField.placeholder = "Search for your server" //TODO: @zeitschlag Localization
|
2022-11-11 18:46:06 +01:00
|
|
|
searchTextField.leftView = UIImageView(image: UIImage(systemName: "magnifyingglass"))
|
|
|
|
searchTextField.leftViewMode = .always
|
2022-11-13 13:46:32 +01:00
|
|
|
searchTextField.layer.cornerRadius = 10
|
2022-11-11 18:46:06 +01:00
|
|
|
|
2022-11-13 13:46:32 +01:00
|
|
|
tableView = ContentSizedTableView()
|
2022-11-11 18:46:06 +01:00
|
|
|
tableView.translatesAutoresizingMaskIntoConstraints = false
|
2022-11-13 13:46:32 +01:00
|
|
|
tableView.backgroundColor = Asset.Scene.Onboarding.textFieldBackground.color
|
2022-11-13 14:30:05 +01:00
|
|
|
tableView.keyboardDismissMode = .onDrag
|
2022-11-12 23:39:58 +01:00
|
|
|
|
2022-11-13 00:22:22 +01:00
|
|
|
tableViewWrapper = UIView()
|
|
|
|
tableViewWrapper.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
tableViewWrapper.backgroundColor = .clear
|
2022-11-13 13:46:32 +01:00
|
|
|
tableViewWrapper.layer.cornerRadius = 10
|
|
|
|
tableViewWrapper.layer.masksToBounds = true
|
2022-11-13 00:22:22 +01:00
|
|
|
tableViewWrapper.addSubview(tableView)
|
|
|
|
|
2022-11-10 17:52:48 +01:00
|
|
|
navigationActionView = NavigationActionView()
|
|
|
|
navigationActionView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
super.init(frame: frame)
|
|
|
|
|
2022-11-10 18:32:00 +01:00
|
|
|
addSubview(headerStackView)
|
2022-11-11 18:46:06 +01:00
|
|
|
addSubview(searchTextField)
|
2022-11-13 00:22:22 +01:00
|
|
|
addSubview(tableViewWrapper)
|
2022-11-10 17:52:48 +01:00
|
|
|
addSubview(navigationActionView)
|
2022-11-12 23:39:58 +01:00
|
|
|
backgroundColor = Asset.Scene.Onboarding.background.color
|
2022-11-10 17:52:48 +01:00
|
|
|
|
|
|
|
setupConstraints()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
private func setupConstraints() {
|
2022-11-13 14:30:05 +01:00
|
|
|
|
|
|
|
let bottomConstraint = safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: navigationActionView.bottomAnchor)
|
|
|
|
|
2022-11-10 17:52:48 +01:00
|
|
|
let constraints = [
|
2022-11-10 18:32:00 +01:00
|
|
|
|
|
|
|
headerStackView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
|
|
|
|
headerStackView.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
|
|
|
|
headerStackView.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
|
|
|
|
|
2022-11-11 18:46:06 +01:00
|
|
|
searchTextField.topAnchor.constraint(equalTo: headerStackView.bottomAnchor, constant: 32),
|
|
|
|
searchTextField.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
|
|
|
|
searchTextField.heightAnchor.constraint(equalToConstant: 55),
|
|
|
|
trailingAnchor.constraint(equalTo: searchTextField.trailingAnchor, constant: 16),
|
|
|
|
|
2022-11-13 00:22:22 +01:00
|
|
|
tableViewWrapper.topAnchor.constraint(equalTo: searchTextField.bottomAnchor),
|
|
|
|
tableViewWrapper.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
|
|
|
|
trailingAnchor.constraint(equalTo: tableViewWrapper.trailingAnchor, constant: 16),
|
2022-11-13 13:46:32 +01:00
|
|
|
tableViewWrapper.bottomAnchor.constraint(lessThanOrEqualTo: navigationActionView.topAnchor),
|
2022-11-13 00:22:22 +01:00
|
|
|
|
|
|
|
tableView.topAnchor.constraint(equalTo: tableViewWrapper.topAnchor),
|
|
|
|
tableView.leadingAnchor.constraint(equalTo: tableViewWrapper.leadingAnchor),
|
|
|
|
tableViewWrapper.trailingAnchor.constraint(equalTo: tableView.trailingAnchor),
|
2022-11-13 13:46:32 +01:00
|
|
|
tableViewWrapper.bottomAnchor.constraint(greaterThanOrEqualTo: tableView.bottomAnchor),
|
2022-11-11 18:46:06 +01:00
|
|
|
|
2022-11-10 17:52:48 +01:00
|
|
|
navigationActionView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
|
navigationActionView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
2022-11-13 14:30:05 +01:00
|
|
|
bottomConstraint,
|
2022-11-10 17:52:48 +01:00
|
|
|
]
|
2022-11-13 14:30:05 +01:00
|
|
|
|
|
|
|
self.bottomConstraint = bottomConstraint
|
2022-11-10 17:52:48 +01:00
|
|
|
NSLayoutConstraint.activate(constraints)
|
|
|
|
}
|
|
|
|
|
2022-11-13 00:22:22 +01:00
|
|
|
func updateCorners(numberOfResults: Int = 0) {
|
|
|
|
|
2022-11-13 13:46:32 +01:00
|
|
|
tableView.isHidden = (numberOfResults == 0)
|
|
|
|
tableViewWrapper.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] // tableViewMask
|
|
|
|
|
|
|
|
let maskedCorners: CACornerMask
|
2022-11-13 00:22:22 +01:00
|
|
|
|
|
|
|
if numberOfResults == 0 {
|
2022-11-13 13:46:32 +01:00
|
|
|
maskedCorners = [.layerMinXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMinYCorner, .layerMaxXMaxYCorner]
|
2022-11-13 00:22:22 +01:00
|
|
|
} else {
|
2022-11-13 13:46:32 +01:00
|
|
|
maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
|
2022-11-13 00:22:22 +01:00
|
|
|
}
|
|
|
|
|
2022-11-13 13:46:32 +01:00
|
|
|
searchTextField.layer.maskedCorners = maskedCorners
|
2022-11-13 00:22:22 +01:00
|
|
|
}
|
2022-11-10 17:52:48 +01:00
|
|
|
}
|