2022-11-10 17:52:48 +01:00
|
|
|
//
|
|
|
|
// MastodonLoginView.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Nathan Mattes on 10.11.22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import MastodonAsset
|
2022-11-13 15:04:42 +01:00
|
|
|
import MastodonLocalization
|
2022-11-10 17:52:48 +01:00
|
|
|
|
|
|
|
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-16 07:38:04 +01:00
|
|
|
|
2022-11-11 18:46:06 +01:00
|
|
|
let searchTextField: UITextField
|
2022-11-16 07:38:04 +01:00
|
|
|
private let searchTextFieldLeftView: UIView
|
|
|
|
private let searchTextFieldMagnifyingGlass: UIImageView
|
|
|
|
private let searchContainerLeftPaddingView: UIView
|
|
|
|
|
2022-11-11 18:46:06 +01:00
|
|
|
let tableView: UITableView
|
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
|
2022-11-13 15:04:42 +01:00
|
|
|
titleLabel.text = L10n.Scene.Login.title
|
2022-11-10 18:32:00 +01:00
|
|
|
titleLabel.numberOfLines = 0
|
|
|
|
|
|
|
|
subtitleLabel = UILabel()
|
|
|
|
subtitleLabel.font = MastodonLoginViewController.subTitleFont
|
|
|
|
subtitleLabel.textColor = MastodonLoginViewController.subTitleTextColor
|
2022-11-13 15:04:42 +01:00
|
|
|
subtitleLabel.text = L10n.Scene.Login.subtitle
|
2022-11-10 18:32:00 +01:00
|
|
|
subtitleLabel.numberOfLines = 0
|
|
|
|
|
|
|
|
headerStackView = UIStackView(arrangedSubviews: [titleLabel, subtitleLabel])
|
|
|
|
headerStackView.axis = .vertical
|
|
|
|
headerStackView.spacing = 16
|
|
|
|
headerStackView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
2022-11-16 07:38:04 +01:00
|
|
|
searchTextFieldMagnifyingGlass = UIImageView(image: UIImage(
|
|
|
|
systemName: "magnifyingglass",
|
|
|
|
withConfiguration: UIImage.SymbolConfiguration(pointSize: 15, weight: .regular)
|
|
|
|
))
|
|
|
|
searchTextFieldMagnifyingGlass.tintColor = Asset.Colors.Label.secondary.color.withAlphaComponent(0.6)
|
|
|
|
searchTextFieldMagnifyingGlass.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
searchContainerLeftPaddingView = UIView()
|
|
|
|
searchContainerLeftPaddingView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
searchTextFieldLeftView = UIView()
|
|
|
|
searchTextFieldLeftView.addSubview(searchTextFieldMagnifyingGlass)
|
|
|
|
searchTextFieldLeftView.addSubview(searchContainerLeftPaddingView)
|
|
|
|
|
2022-11-11 18:46:06 +01:00
|
|
|
searchTextField = UITextField()
|
|
|
|
searchTextField.translatesAutoresizingMaskIntoConstraints = false
|
2022-11-16 08:16:32 +01:00
|
|
|
searchTextField.backgroundColor = Asset.Scene.Onboarding.searchBarBackground.color
|
2022-11-13 15:04:42 +01:00
|
|
|
searchTextField.placeholder = L10n.Scene.Login.ServerSearchField.placeholder
|
2022-11-16 07:38:04 +01:00
|
|
|
searchTextField.leftView = searchTextFieldLeftView
|
2022-11-11 18:46:06 +01:00
|
|
|
searchTextField.leftViewMode = .always
|
2022-11-13 13:46:32 +01:00
|
|
|
searchTextField.layer.cornerRadius = 10
|
2022-11-16 07:37:13 +01:00
|
|
|
searchTextField.keyboardType = .URL
|
|
|
|
searchTextField.autocorrectionType = .no
|
|
|
|
searchTextField.autocapitalizationType = .none
|
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-16 08:16:32 +01:00
|
|
|
tableView.layer.cornerRadius = 10
|
2022-11-13 00:22:22 +01:00
|
|
|
|
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-16 08:16:32 +01:00
|
|
|
addSubview(tableView)
|
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-16 07:38:04 +01:00
|
|
|
searchTextFieldMagnifyingGlass.topAnchor.constraint(equalTo: searchTextFieldLeftView.topAnchor),
|
|
|
|
searchTextFieldMagnifyingGlass.leadingAnchor.constraint(equalTo: searchTextFieldLeftView.leadingAnchor, constant: 8),
|
|
|
|
searchTextFieldMagnifyingGlass.bottomAnchor.constraint(equalTo: searchTextFieldLeftView.bottomAnchor),
|
|
|
|
|
|
|
|
searchContainerLeftPaddingView.topAnchor.constraint(equalTo: searchTextFieldLeftView.topAnchor),
|
|
|
|
searchContainerLeftPaddingView.leadingAnchor.constraint(equalTo: searchTextFieldMagnifyingGlass.trailingAnchor),
|
|
|
|
searchContainerLeftPaddingView.trailingAnchor.constraint(equalTo: searchTextFieldLeftView.trailingAnchor),
|
|
|
|
searchContainerLeftPaddingView.bottomAnchor.constraint(equalTo: searchTextFieldLeftView.bottomAnchor),
|
|
|
|
searchContainerLeftPaddingView.widthAnchor.constraint(equalToConstant: 4).priority(.defaultHigh),
|
|
|
|
|
2022-11-16 08:16:32 +01:00
|
|
|
tableView.topAnchor.constraint(equalTo: searchTextField.bottomAnchor, constant: 2),
|
|
|
|
tableView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
|
|
|
|
trailingAnchor.constraint(equalTo: tableView.trailingAnchor, constant: 16),
|
|
|
|
tableView.bottomAnchor.constraint(lessThanOrEqualTo: navigationActionView.topAnchor),
|
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)
|
2022-11-16 08:16:32 +01:00
|
|
|
tableView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
|
2022-11-13 13:46:32 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|