2021-02-20 06:56:24 +01:00
|
|
|
//
|
|
|
|
// WelcomeViewController.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
2021-02-23 15:14:10 +01:00
|
|
|
// Created by BradGao on 2021/2/20.
|
2021-02-20 06:56:24 +01:00
|
|
|
//
|
|
|
|
|
2021-02-23 08:44:59 +01:00
|
|
|
import os.log
|
2021-02-20 06:56:24 +01:00
|
|
|
import UIKit
|
|
|
|
|
2021-02-23 08:44:59 +01:00
|
|
|
final class WelcomeViewController: UIViewController, NeedsDependency {
|
|
|
|
|
|
|
|
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
|
2021-02-26 09:43:59 +01:00
|
|
|
private(set) lazy var logoImageView: UIImageView = {
|
|
|
|
let image = view.traitCollection.userInterfaceIdiom == .phone ? Asset.Welcome.mastodonLogo.image : Asset.Welcome.mastodonLogoLarge.image
|
|
|
|
let imageView = UIImageView(image: image)
|
2021-02-20 06:56:24 +01:00
|
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
|
|
|
let sloganLabel: UILabel = {
|
|
|
|
let label = UILabel()
|
2021-02-26 09:43:59 +01:00
|
|
|
label.font = UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: .systemFont(ofSize: 34, weight: .bold))
|
2021-02-23 08:25:48 +01:00
|
|
|
label.textColor = Asset.Colors.Label.primary.color
|
2021-02-23 05:41:56 +01:00
|
|
|
label.text = L10n.Scene.Welcome.slogan
|
2021-02-20 06:56:24 +01:00
|
|
|
label.adjustsFontForContentSizeCategory = true
|
|
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
label.numberOfLines = 0
|
|
|
|
return label
|
|
|
|
}()
|
2021-02-20 13:23:29 +01:00
|
|
|
|
2021-02-22 16:16:13 +01:00
|
|
|
let signUpButton: PrimaryActionButton = {
|
2021-02-26 09:43:59 +01:00
|
|
|
let button = PrimaryActionButton()
|
2021-02-24 08:29:16 +01:00
|
|
|
button.setTitle(L10n.Common.Controls.Actions.signUp, for: .normal)
|
2021-02-20 13:23:29 +01:00
|
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return button
|
|
|
|
}()
|
|
|
|
|
|
|
|
let signInButton: UIButton = {
|
|
|
|
let button = UIButton(type: .system)
|
2021-02-23 08:44:59 +01:00
|
|
|
button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold))
|
2021-02-24 08:29:16 +01:00
|
|
|
button.setTitle(L10n.Common.Controls.Actions.signIn, for: .normal)
|
2021-02-20 13:23:29 +01:00
|
|
|
button.setTitleColor(Asset.Colors.lightBrandBlue.color, for: .normal)
|
|
|
|
button.setInsets(forContentPadding: UIEdgeInsets(top: 12, left: 0, bottom: 12, right: 0), imageTitlePadding: 0)
|
|
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return button
|
|
|
|
}()
|
2021-02-26 11:27:47 +01:00
|
|
|
|
|
|
|
deinit {
|
|
|
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
|
|
|
}
|
|
|
|
|
2021-02-20 06:56:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension WelcomeViewController {
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2021-02-26 09:43:59 +01:00
|
|
|
setupOnboardingAppearance()
|
2021-02-20 06:56:24 +01:00
|
|
|
|
|
|
|
view.addSubview(logoImageView)
|
|
|
|
NSLayoutConstraint.activate([
|
2021-02-26 09:43:59 +01:00
|
|
|
logoImageView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
|
2021-02-20 06:56:24 +01:00
|
|
|
logoImageView.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor, constant: 35),
|
2021-02-23 04:19:10 +01:00
|
|
|
view.readableContentGuide.trailingAnchor.constraint(equalTo: logoImageView.trailingAnchor, constant: 35),
|
2021-02-20 06:56:24 +01:00
|
|
|
logoImageView.heightAnchor.constraint(equalTo: logoImageView.widthAnchor, multiplier: 65.4/265.1),
|
|
|
|
])
|
|
|
|
|
|
|
|
view.addSubview(sloganLabel)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
sloganLabel.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor, constant: 16),
|
2021-02-23 04:19:10 +01:00
|
|
|
view.readableContentGuide.trailingAnchor.constraint(equalTo: sloganLabel.trailingAnchor, constant: 16),
|
2021-02-20 06:56:24 +01:00
|
|
|
sloganLabel.topAnchor.constraint(equalTo: logoImageView.bottomAnchor, constant: 168),
|
|
|
|
])
|
2021-02-20 13:23:29 +01:00
|
|
|
|
|
|
|
view.addSubview(signInButton)
|
|
|
|
view.addSubview(signUpButton)
|
|
|
|
NSLayoutConstraint.activate([
|
2021-02-26 11:27:47 +01:00
|
|
|
signInButton.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor, constant: WelcomeViewController.actionButtonMargin),
|
|
|
|
view.readableContentGuide.trailingAnchor.constraint(equalTo: signInButton.trailingAnchor, constant: WelcomeViewController.actionButtonMargin),
|
2021-02-26 09:43:59 +01:00
|
|
|
view.layoutMarginsGuide.bottomAnchor.constraint(equalTo: signInButton.bottomAnchor, constant: WelcomeViewController.viewBottomPaddingHeight),
|
2021-02-26 11:27:47 +01:00
|
|
|
signInButton.heightAnchor.constraint(equalToConstant: WelcomeViewController.actionButtonHeight).priority(.defaultHigh),
|
2021-02-20 13:23:29 +01:00
|
|
|
|
2021-02-26 09:43:59 +01:00
|
|
|
signInButton.topAnchor.constraint(equalTo: signUpButton.bottomAnchor, constant: 9),
|
2021-02-26 11:27:47 +01:00
|
|
|
signUpButton.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor, constant: WelcomeViewController.actionButtonMargin),
|
|
|
|
view.readableContentGuide.trailingAnchor.constraint(equalTo: signUpButton.trailingAnchor, constant: WelcomeViewController.actionButtonMargin),
|
2021-02-26 09:43:59 +01:00
|
|
|
signUpButton.heightAnchor.constraint(equalToConstant: WelcomeViewController.actionButtonHeight).priority(.defaultHigh),
|
2021-02-20 13:23:29 +01:00
|
|
|
])
|
2021-02-23 08:44:59 +01:00
|
|
|
|
2021-02-23 15:14:10 +01:00
|
|
|
signUpButton.addTarget(self, action: #selector(signUpButtonDidClicked(_:)), for: .touchUpInside)
|
|
|
|
signInButton.addTarget(self, action: #selector(signInButtonDidClicked(_:)), for: .touchUpInside)
|
2021-02-20 06:56:24 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 11:27:47 +01:00
|
|
|
override var preferredStatusBarStyle: UIStatusBarStyle { return .darkContent }
|
|
|
|
|
2021-02-23 08:44:59 +01:00
|
|
|
}
|
|
|
|
|
2021-02-23 15:14:10 +01:00
|
|
|
extension WelcomeViewController {
|
|
|
|
@objc
|
|
|
|
private func signUpButtonDidClicked(_ sender: UIButton) {
|
2021-02-26 11:27:47 +01:00
|
|
|
coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context, mode: .signUp)), from: self, transition: .show)
|
2021-02-23 15:14:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc
|
|
|
|
private func signInButtonDidClicked(_ sender: UIButton) {
|
2021-02-26 11:27:47 +01:00
|
|
|
coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context, mode: .signIn)), from: self, transition: .show)
|
2021-02-23 15:14:10 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-26 09:43:59 +01:00
|
|
|
|
|
|
|
// MARK: - OnboardingViewControllerAppearance
|
|
|
|
extension WelcomeViewController: OnboardingViewControllerAppearance { }
|
2021-02-26 11:27:47 +01:00
|
|
|
|
|
|
|
// MARK: - UIAdaptivePresentationControllerDelegate
|
|
|
|
extension WelcomeViewController: UIAdaptivePresentationControllerDelegate {
|
|
|
|
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
|
|
|
|
return .fullScreen
|
|
|
|
}
|
|
|
|
}
|