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-03-01 10:38:45 +01:00
|
|
|
let welcomeIllustrationView = WelcomeIllustrationView()
|
2021-03-01 11:32:31 +01:00
|
|
|
var welcomeIllustrationViewBottomAnchorLayoutConstraint: NSLayoutConstraint?
|
2021-03-01 10:38:45 +01:00
|
|
|
|
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
|
|
|
|
}()
|
|
|
|
|
2021-03-01 11:32:31 +01:00
|
|
|
private(set) lazy var signInButton: UIButton = {
|
2021-02-20 13:23:29 +01:00
|
|
|
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-03-01 11:32:31 +01:00
|
|
|
let titleColor: UIColor = traitCollection.userInterfaceIdiom == .phone ? UIColor.white.withAlphaComponent(0.8) : Asset.Colors.Button.highlight.color
|
|
|
|
button.setTitleColor(titleColor, for: .normal)
|
2021-02-20 13:23:29 +01:00
|
|
|
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-03-01 10:38:45 +01:00
|
|
|
|
2021-03-01 11:32:31 +01:00
|
|
|
if traitCollection.userInterfaceIdiom == .phone {
|
|
|
|
welcomeIllustrationView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(welcomeIllustrationView)
|
|
|
|
welcomeIllustrationViewBottomAnchorLayoutConstraint = welcomeIllustrationView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
view.leftAnchor.constraint(equalTo: welcomeIllustrationView.leftAnchor, constant: 44),
|
|
|
|
welcomeIllustrationView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 44),
|
|
|
|
welcomeIllustrationViewBottomAnchorLayoutConstraint!,
|
|
|
|
])
|
2021-03-02 04:49:27 +01:00
|
|
|
view.backgroundColor = .black
|
|
|
|
welcomeIllustrationView.alpha = 0.9
|
2021-03-02 06:45:47 +01:00
|
|
|
|
|
|
|
welcomeIllustrationView.cloudBaseImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -5, maxX: 5, minY: -5, maxY: 5)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.rightHillImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -12, maxX: 12, minY: -12, maxY: 12)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.leftHillImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -12, maxX: 12, minY: -20, maxY: 20)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.centerHillImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -14, maxX: 14, minY: -30, maxY: 30)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.lineDashTwoImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -25, maxX: 25, minY: -40, maxY: 40)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.elephantTwoImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -30, maxX: 30, minY: -30, maxY: 30)
|
|
|
|
)
|
2021-03-01 11:32:31 +01:00
|
|
|
}
|
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
|
|
|
|
2021-03-01 11:32:31 +01:00
|
|
|
if traitCollection.userInterfaceIdiom == .phone {
|
|
|
|
let imageSizeScale: CGFloat = view.frame.width > 375 ? 1.5 : 1.0
|
|
|
|
welcomeIllustrationView.cloudFirstImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(welcomeIllustrationView.cloudFirstImageView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
welcomeIllustrationView.cloudFirstImageView.rightAnchor.constraint(equalTo: view.centerXAnchor),
|
|
|
|
welcomeIllustrationView.cloudFirstImageView.widthAnchor.constraint(equalToConstant: 272 / traitCollection.displayScale * imageSizeScale),
|
|
|
|
welcomeIllustrationView.cloudFirstImageView.heightAnchor.constraint(equalToConstant: 113 / traitCollection.displayScale * imageSizeScale),
|
|
|
|
])
|
|
|
|
welcomeIllustrationView.cloudSecondImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(welcomeIllustrationView.cloudSecondImageView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
welcomeIllustrationView.cloudSecondImageView.topAnchor.constraint(equalTo: logoImageView.bottomAnchor),
|
|
|
|
welcomeIllustrationView.cloudSecondImageView.rightAnchor.constraint(equalTo: logoImageView.rightAnchor, constant: 20),
|
|
|
|
welcomeIllustrationView.cloudSecondImageView.widthAnchor.constraint(equalToConstant: 152 / traitCollection.displayScale),
|
|
|
|
welcomeIllustrationView.cloudSecondImageView.heightAnchor.constraint(equalToConstant: 96 / traitCollection.displayScale),
|
|
|
|
welcomeIllustrationView.cloudFirstImageView.topAnchor.constraint(equalTo: welcomeIllustrationView.cloudSecondImageView.bottomAnchor),
|
|
|
|
])
|
|
|
|
welcomeIllustrationView.cloudThirdImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(welcomeIllustrationView.cloudThirdImageView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
logoImageView.topAnchor.constraint(equalTo: welcomeIllustrationView.cloudThirdImageView.bottomAnchor, constant: 10),
|
|
|
|
welcomeIllustrationView.cloudThirdImageView.rightAnchor.constraint(equalTo: view.centerXAnchor),
|
|
|
|
welcomeIllustrationView.cloudThirdImageView.widthAnchor.constraint(equalToConstant: 126 / traitCollection.displayScale),
|
|
|
|
welcomeIllustrationView.cloudThirdImageView.heightAnchor.constraint(equalToConstant: 68 / traitCollection.displayScale),
|
|
|
|
])
|
|
|
|
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(welcomeIllustrationView.elephantOnAirplaneWithContrailImageView)
|
|
|
|
NSLayoutConstraint.activate([
|
2021-03-02 06:45:47 +01:00
|
|
|
view.leftAnchor.constraint(equalTo: welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.leftAnchor, constant: 12), // add 12pt bleeding
|
2021-03-01 11:32:31 +01:00
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.bottomAnchor.constraint(equalTo: sloganLabel.topAnchor),
|
|
|
|
// make a little bit large
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.widthAnchor.constraint(equalToConstant: 656 / traitCollection.displayScale * imageSizeScale),
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.heightAnchor.constraint(equalToConstant: 195 / traitCollection.displayScale * imageSizeScale),
|
|
|
|
])
|
2021-03-02 06:45:47 +01:00
|
|
|
|
|
|
|
welcomeIllustrationView.cloudFirstImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -30, maxX: 30, minY: -20, maxY: 10)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.cloudSecondImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -10, maxX: 30, minY: -8, maxY: 10)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.cloudThirdImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -20, maxX: 10, minY: -6, maxY: 10)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -20, maxX: 12, minY: -20, maxY: 12) // maxX should not larger then the bleeding (12pt)
|
|
|
|
)
|
|
|
|
|
2021-03-01 11:32:31 +01:00
|
|
|
view.bringSubviewToFront(logoImageView)
|
|
|
|
view.bringSubviewToFront(sloganLabel)
|
|
|
|
}
|
2021-03-01 10:38:45 +01:00
|
|
|
|
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-03-01 10:38:45 +01:00
|
|
|
override func viewSafeAreaInsetsDidChange() {
|
|
|
|
super.viewSafeAreaInsetsDidChange()
|
|
|
|
|
|
|
|
// make illustration bottom over the bleeding
|
2021-03-01 11:32:31 +01:00
|
|
|
let overlap: CGFloat = 145
|
|
|
|
welcomeIllustrationViewBottomAnchorLayoutConstraint?.constant = overlap - view.safeAreaInsets.bottom
|
2021-03-01 10:38:45 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|