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-09-15 14:18:19 +02:00
|
|
|
import Combine
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonLocalization
|
2021-02-20 06:56:24 +01:00
|
|
|
|
2021-02-23 08:44:59 +01:00
|
|
|
final class WelcomeViewController: UIViewController, NeedsDependency {
|
|
|
|
|
2021-12-31 09:47:13 +01:00
|
|
|
let logger = Logger(subsystem: "WelcomeViewController", category: "ViewController")
|
|
|
|
|
2021-02-23 08:44:59 +01:00
|
|
|
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
|
2021-09-15 14:18:19 +02:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
2021-11-04 12:24:46 +01:00
|
|
|
var observations = Set<NSKeyValueObservation>()
|
2021-09-15 14:18:19 +02:00
|
|
|
private(set) lazy var viewModel = WelcomeViewModel(context: context)
|
|
|
|
|
2021-03-16 11:24:48 +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-09-15 14:18:19 +02:00
|
|
|
private(set) lazy var dismissBarButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(WelcomeViewController.dismissBarButtonItemDidPressed(_:)))
|
|
|
|
|
2021-02-26 09:43:59 +01:00
|
|
|
private(set) lazy var logoImageView: UIImageView = {
|
2021-11-04 12:24:46 +01:00
|
|
|
let image = Asset.Scene.Welcome.mastodonLogo.image
|
2021-02-26 09:43:59 +01:00
|
|
|
let imageView = UIImageView(image: image)
|
2021-02-20 06:56:24 +01:00
|
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
private(set) lazy var sloganLabel: UILabel = {
|
2021-02-20 06:56:24 +01:00
|
|
|
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-12-31 09:47:13 +01:00
|
|
|
let buttonContainer = UIStackView()
|
|
|
|
|
2021-11-04 12:24:46 +01:00
|
|
|
private(set) lazy var signUpButton: PrimaryActionButton = {
|
2021-02-26 09:43:59 +01:00
|
|
|
let button = PrimaryActionButton()
|
2021-06-23 08:46:58 +02:00
|
|
|
button.adjustsBackgroundImageWhenUserInterfaceStyleChanges = false
|
2022-05-23 05:17:26 +02:00
|
|
|
button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))
|
|
|
|
button.setTitle(L10n.Common.Controls.Actions.signUp, for: .normal)
|
2021-11-04 12:24:46 +01:00
|
|
|
let backgroundImageColor: UIColor = .white
|
|
|
|
let backgroundImageHighlightedColor: UIColor = UIColor(white: 0.8, alpha: 1.0)
|
2021-03-16 08:42:15 +01:00
|
|
|
button.setBackgroundImage(.placeholder(color: backgroundImageColor), for: .normal)
|
2021-06-16 07:47:40 +02:00
|
|
|
button.setBackgroundImage(.placeholder(color: backgroundImageHighlightedColor), for: .highlighted)
|
2021-12-31 09:47:13 +01:00
|
|
|
button.setTitleColor(.black, for: .normal)
|
2021-02-20 13:23:29 +01:00
|
|
|
return button
|
|
|
|
}()
|
2022-01-05 08:11:35 +01:00
|
|
|
let signUpButtonShadowView = UIView()
|
2021-02-20 13:23:29 +01:00
|
|
|
|
2021-12-31 10:31:13 +01:00
|
|
|
private(set) lazy var signInButton: PrimaryActionButton = {
|
2021-12-31 09:47:13 +01:00
|
|
|
let button = PrimaryActionButton()
|
|
|
|
button.adjustsBackgroundImageWhenUserInterfaceStyleChanges = false
|
2022-05-23 05:17:26 +02:00
|
|
|
button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))
|
2022-03-15 19:31:57 +01:00
|
|
|
button.setTitle(L10n.Scene.Welcome.logIn, for: .normal)
|
2021-12-31 09:47:13 +01:00
|
|
|
let backgroundImageColor = Asset.Scene.Welcome.signInButtonBackground.color
|
|
|
|
let backgroundImageHighlightedColor = Asset.Scene.Welcome.signInButtonBackground.color.withAlphaComponent(0.8)
|
|
|
|
button.setBackgroundImage(.placeholder(color: backgroundImageColor), for: .normal)
|
|
|
|
button.setBackgroundImage(.placeholder(color: backgroundImageHighlightedColor), for: .highlighted)
|
2021-12-31 10:31:13 +01:00
|
|
|
let titleColor: UIColor = UIColor.white.withAlphaComponent(0.9)
|
2021-03-01 11:32:31 +01:00
|
|
|
button.setTitleColor(titleColor, for: .normal)
|
2021-02-20 13:23:29 +01:00
|
|
|
return button
|
|
|
|
}()
|
2021-12-31 10:31:13 +01:00
|
|
|
let signInButtonShadowView = UIView()
|
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-12-31 09:47:13 +01:00
|
|
|
definesPresentationContext = true
|
|
|
|
preferredContentSize = CGSize(width: 547, height: 678)
|
2021-11-04 12:24:46 +01:00
|
|
|
|
2021-10-08 12:10:06 +02:00
|
|
|
navigationController?.navigationBar.prefersLargeTitles = true
|
|
|
|
navigationItem.largeTitleDisplayMode = .never
|
2021-06-16 07:47:40 +02:00
|
|
|
view.overrideUserInterfaceStyle = .light
|
|
|
|
|
2021-02-26 09:43:59 +01:00
|
|
|
setupOnboardingAppearance()
|
2021-03-16 11:24:48 +01:00
|
|
|
setupIllustrationLayout()
|
2021-12-31 09:47:13 +01:00
|
|
|
|
|
|
|
buttonContainer.axis = .vertical
|
|
|
|
buttonContainer.spacing = 12
|
|
|
|
buttonContainer.isLayoutMarginsRelativeArrangement = true
|
|
|
|
|
|
|
|
buttonContainer.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(buttonContainer)
|
2021-02-20 13:23:29 +01:00
|
|
|
NSLayoutConstraint.activate([
|
2021-12-31 09:47:13 +01:00
|
|
|
buttonContainer.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
|
|
|
|
buttonContainer.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
|
|
|
|
view.layoutMarginsGuide.bottomAnchor.constraint(equalTo: buttonContainer.bottomAnchor),
|
|
|
|
])
|
|
|
|
|
|
|
|
signUpButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.addArrangedSubview(signUpButton)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
signUpButton.heightAnchor.constraint(equalToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1),
|
|
|
|
])
|
|
|
|
signInButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.addArrangedSubview(signInButton)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
signInButton.heightAnchor.constraint(equalToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1),
|
|
|
|
])
|
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
signUpButtonShadowView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.addSubview(signUpButtonShadowView)
|
|
|
|
buttonContainer.sendSubviewToBack(signUpButtonShadowView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
signUpButtonShadowView.topAnchor.constraint(equalTo: signUpButton.topAnchor),
|
|
|
|
signUpButtonShadowView.leadingAnchor.constraint(equalTo: signUpButton.leadingAnchor),
|
|
|
|
signUpButtonShadowView.trailingAnchor.constraint(equalTo: signUpButton.trailingAnchor),
|
|
|
|
signUpButtonShadowView.bottomAnchor.constraint(equalTo: signUpButton.bottomAnchor),
|
|
|
|
])
|
|
|
|
|
2021-12-31 10:31:13 +01:00
|
|
|
signInButtonShadowView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.addSubview(signInButtonShadowView)
|
|
|
|
buttonContainer.sendSubviewToBack(signInButtonShadowView)
|
2021-12-31 09:47:13 +01:00
|
|
|
NSLayoutConstraint.activate([
|
2021-12-31 10:31:13 +01:00
|
|
|
signInButtonShadowView.topAnchor.constraint(equalTo: signInButton.topAnchor),
|
|
|
|
signInButtonShadowView.leadingAnchor.constraint(equalTo: signInButton.leadingAnchor),
|
|
|
|
signInButtonShadowView.trailingAnchor.constraint(equalTo: signInButton.trailingAnchor),
|
|
|
|
signInButtonShadowView.bottomAnchor.constraint(equalTo: signInButton.bottomAnchor),
|
2021-02-20 13:23:29 +01:00
|
|
|
])
|
2021-03-16 08:42:15 +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-09-15 14:18:19 +02:00
|
|
|
|
2022-10-09 14:07:57 +02:00
|
|
|
viewModel.$needsShowDismissEntry
|
2021-09-15 14:18:19 +02:00
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink { [weak self] needsShowDismissEntry in
|
|
|
|
guard let self = self else { return }
|
|
|
|
self.navigationItem.leftBarButtonItem = needsShowDismissEntry ? self.dismissBarButtonItem : nil
|
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
2021-02-20 06:56:24 +01:00
|
|
|
}
|
|
|
|
|
2021-12-31 10:31:13 +01:00
|
|
|
override func viewDidLayoutSubviews() {
|
|
|
|
super.viewDidLayoutSubviews()
|
|
|
|
|
|
|
|
setupButtonShadowView()
|
|
|
|
}
|
|
|
|
|
2021-03-01 10:38:45 +01:00
|
|
|
override func viewSafeAreaInsetsDidChange() {
|
|
|
|
super.viewSafeAreaInsetsDidChange()
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
var overlap: CGFloat = 5
|
2021-11-04 12:24:46 +01:00
|
|
|
// shift illustration down for non-notch phone
|
2021-03-16 11:24:48 +01:00
|
|
|
if view.safeAreaInsets.bottom == 0 {
|
|
|
|
overlap += 56
|
|
|
|
}
|
|
|
|
welcomeIllustrationViewBottomAnchorLayoutConstraint?.constant = overlap
|
2021-03-01 10:38:45 +01:00
|
|
|
}
|
2021-12-31 09:47:13 +01:00
|
|
|
|
|
|
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
|
|
super.traitCollectionDidChange(previousTraitCollection)
|
|
|
|
|
|
|
|
setupIllustrationLayout()
|
2021-12-31 10:31:13 +01:00
|
|
|
setupButtonShadowView()
|
2021-12-31 09:47:13 +01:00
|
|
|
}
|
2021-03-01 10:38:45 +01:00
|
|
|
|
2021-02-23 08:44:59 +01:00
|
|
|
}
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
extension WelcomeViewController {
|
2021-02-26 11:27:47 +01:00
|
|
|
|
2021-12-31 10:31:13 +01:00
|
|
|
private func setupButtonShadowView() {
|
2022-01-05 08:11:35 +01:00
|
|
|
signUpButtonShadowView.layer.setupShadow(
|
|
|
|
color: .black,
|
|
|
|
alpha: 0.25,
|
|
|
|
x: 0,
|
|
|
|
y: 1,
|
|
|
|
blur: 2,
|
|
|
|
spread: 0,
|
|
|
|
roundedRect: signInButtonShadowView.bounds,
|
|
|
|
byRoundingCorners: .allCorners,
|
|
|
|
cornerRadii: CGSize(width: 10, height: 10)
|
|
|
|
)
|
2021-12-31 10:31:13 +01:00
|
|
|
signInButtonShadowView.layer.setupShadow(
|
|
|
|
color: .black,
|
|
|
|
alpha: 0.25,
|
|
|
|
x: 0,
|
|
|
|
y: 1,
|
|
|
|
blur: 2,
|
|
|
|
spread: 0,
|
|
|
|
roundedRect: signInButtonShadowView.bounds,
|
|
|
|
byRoundingCorners: .allCorners,
|
|
|
|
cornerRadii: CGSize(width: 10, height: 10)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-31 09:47:13 +01:00
|
|
|
private func updateButtonContainerLayoutMargins(traitCollection: UITraitCollection) {
|
|
|
|
switch traitCollection.userInterfaceIdiom {
|
|
|
|
case .phone:
|
|
|
|
buttonContainer.layoutMargins = UIEdgeInsets(
|
|
|
|
top: 0,
|
|
|
|
left: WelcomeViewController.actionButtonMargin,
|
|
|
|
bottom: WelcomeViewController.viewBottomPaddingHeight,
|
|
|
|
right: WelcomeViewController.actionButtonMargin
|
|
|
|
)
|
|
|
|
default:
|
|
|
|
let margin = traitCollection.horizontalSizeClass == .regular ? WelcomeViewController.actionButtonMarginExtend : WelcomeViewController.actionButtonMargin
|
|
|
|
buttonContainer.layoutMargins = UIEdgeInsets(
|
|
|
|
top: 0,
|
|
|
|
left: margin,
|
|
|
|
bottom: WelcomeViewController.viewBottomPaddingHeightExtend,
|
|
|
|
right: margin
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
private func setupIllustrationLayout() {
|
2021-12-31 09:47:13 +01:00
|
|
|
welcomeIllustrationView.layout = {
|
|
|
|
switch traitCollection.userInterfaceIdiom {
|
|
|
|
case .phone:
|
|
|
|
return .compact
|
|
|
|
default:
|
|
|
|
return .regular
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
// set logo
|
|
|
|
if logoImageView.superview == nil {
|
|
|
|
view.addSubview(logoImageView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
logoImageView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
|
|
|
|
logoImageView.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor, constant: 35),
|
|
|
|
view.readableContentGuide.trailingAnchor.constraint(equalTo: logoImageView.trailingAnchor, constant: 35),
|
|
|
|
logoImageView.heightAnchor.constraint(equalTo: logoImageView.widthAnchor, multiplier: 65.4/265.1),
|
|
|
|
])
|
|
|
|
logoImageView.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
|
|
|
}
|
|
|
|
|
2021-12-31 09:47:13 +01:00
|
|
|
// set illustration
|
2021-11-04 12:24:46 +01:00
|
|
|
guard welcomeIllustrationView.superview == nil else {
|
|
|
|
return
|
2021-03-16 11:24:48 +01:00
|
|
|
}
|
2021-12-31 09:47:13 +01:00
|
|
|
welcomeIllustrationView.contentMode = .scaleAspectFit
|
2021-03-16 11:24:48 +01:00
|
|
|
|
2021-11-04 12:24:46 +01:00
|
|
|
welcomeIllustrationView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
welcomeIllustrationViewBottomAnchorLayoutConstraint = welcomeIllustrationView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 5)
|
|
|
|
|
|
|
|
view.addSubview(welcomeIllustrationView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
view.leftAnchor.constraint(equalTo: welcomeIllustrationView.leftAnchor, constant: 15),
|
|
|
|
welcomeIllustrationView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 15),
|
2021-12-31 09:47:13 +01:00
|
|
|
welcomeIllustrationViewBottomAnchorLayoutConstraint!.priority(.required - 1),
|
2021-11-04 12:24:46 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
welcomeIllustrationView.cloudBaseImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -5, maxX: 5, minY: -5, maxY: 5)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.rightHillImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -15, maxX: 25, minY: -10, maxY: 10)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.leftHillImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -25, maxX: 15, minY: -15, maxY: 15)
|
|
|
|
)
|
|
|
|
welcomeIllustrationView.centerHillImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -14, maxX: 14, minY: -5, maxY: 25)
|
|
|
|
)
|
|
|
|
|
|
|
|
let topPaddingView = UIView()
|
|
|
|
topPaddingView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(topPaddingView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
topPaddingView.topAnchor.constraint(equalTo: logoImageView.bottomAnchor),
|
|
|
|
topPaddingView.leadingAnchor.constraint(equalTo: logoImageView.leadingAnchor),
|
|
|
|
topPaddingView.trailingAnchor.constraint(equalTo: logoImageView.trailingAnchor),
|
|
|
|
])
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(welcomeIllustrationView.elephantOnAirplaneWithContrailImageView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
view.leftAnchor.constraint(equalTo: welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.leftAnchor, constant: 12), // add 12pt bleeding
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.topAnchor.constraint(equalTo: topPaddingView.bottomAnchor),
|
|
|
|
// make a little bit large
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.84),
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.heightAnchor.constraint(equalTo: welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.widthAnchor, multiplier: 105.0/318.0),
|
|
|
|
])
|
|
|
|
let bottomPaddingView = UIView()
|
|
|
|
bottomPaddingView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(bottomPaddingView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
bottomPaddingView.topAnchor.constraint(equalTo: welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.bottomAnchor),
|
|
|
|
bottomPaddingView.leadingAnchor.constraint(equalTo: logoImageView.leadingAnchor),
|
|
|
|
bottomPaddingView.trailingAnchor.constraint(equalTo: logoImageView.trailingAnchor),
|
|
|
|
bottomPaddingView.bottomAnchor.constraint(equalTo: view.centerYAnchor),
|
|
|
|
bottomPaddingView.heightAnchor.constraint(equalTo: topPaddingView.heightAnchor, multiplier: 4),
|
|
|
|
])
|
|
|
|
|
|
|
|
welcomeIllustrationView.elephantOnAirplaneWithContrailImageView.addMotionEffect(
|
|
|
|
UIInterpolatingMotionEffect.motionEffect(minX: -20, maxX: 12, minY: -20, maxY: 12) // maxX should not larger then the bleeding (12pt)
|
|
|
|
)
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
view.bringSubviewToFront(logoImageView)
|
2021-11-04 12:24:46 +01:00
|
|
|
view.bringSubviewToFront(sloganLabel)
|
2021-03-16 11:24:48 +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) {
|
2022-11-09 14:13:33 +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) {
|
2022-11-09 14:13:33 +01:00
|
|
|
//TODO: @zeitschlag Present new login-scene
|
|
|
|
_ = coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context, mode: .signIn)), from: self, transition: .show)
|
2021-02-23 15:14:10 +01:00
|
|
|
}
|
2021-09-15 14:18:19 +02:00
|
|
|
|
|
|
|
@objc
|
|
|
|
private func dismissBarButtonItemDidPressed(_ sender: UIButton) {
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
}
|
2021-02-23 15:14:10 +01:00
|
|
|
}
|
2021-02-26 09:43:59 +01:00
|
|
|
|
|
|
|
// MARK: - OnboardingViewControllerAppearance
|
2021-10-08 12:10:06 +02:00
|
|
|
extension WelcomeViewController: OnboardingViewControllerAppearance {
|
|
|
|
func setupNavigationBarAppearance() {
|
|
|
|
// always transparent
|
|
|
|
let barAppearance = UINavigationBarAppearance()
|
|
|
|
barAppearance.configureWithTransparentBackground()
|
|
|
|
navigationItem.standardAppearance = barAppearance
|
|
|
|
navigationItem.compactAppearance = barAppearance
|
|
|
|
navigationItem.scrollEdgeAppearance = barAppearance
|
|
|
|
if #available(iOS 15.0, *) {
|
|
|
|
navigationItem.compactScrollEdgeAppearance = barAppearance
|
|
|
|
} else {
|
|
|
|
// Fallback on earlier versions
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-26 11:27:47 +01:00
|
|
|
|
|
|
|
// MARK: - UIAdaptivePresentationControllerDelegate
|
|
|
|
extension WelcomeViewController: UIAdaptivePresentationControllerDelegate {
|
2021-12-31 09:47:13 +01:00
|
|
|
|
2021-02-26 11:27:47 +01:00
|
|
|
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
|
2021-12-31 09:47:13 +01:00
|
|
|
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public)")
|
|
|
|
|
2021-12-31 10:31:13 +01:00
|
|
|
// update button layout
|
2021-12-31 09:47:13 +01:00
|
|
|
updateButtonContainerLayoutMargins(traitCollection: traitCollection)
|
2021-12-31 10:31:13 +01:00
|
|
|
|
|
|
|
let navigationController = navigationController as? OnboardingNavigationController
|
|
|
|
|
2021-09-27 10:30:36 +02:00
|
|
|
switch traitCollection.userInterfaceIdiom {
|
|
|
|
case .phone:
|
2021-12-31 10:31:13 +01:00
|
|
|
navigationController?.gradientBorderView.isHidden = true
|
2021-09-27 10:30:36 +02:00
|
|
|
// make underneath view controller alive to fix layout issue due to view life cycle
|
|
|
|
return .fullScreen
|
|
|
|
default:
|
2021-12-31 09:47:13 +01:00
|
|
|
switch traitCollection.horizontalSizeClass {
|
|
|
|
case .compact:
|
2021-12-31 10:31:13 +01:00
|
|
|
navigationController?.gradientBorderView.isHidden = true
|
2021-12-31 09:47:13 +01:00
|
|
|
return .fullScreen
|
2021-12-31 10:31:13 +01:00
|
|
|
default:
|
|
|
|
navigationController?.gradientBorderView.isHidden = false
|
2021-12-31 09:47:13 +01:00
|
|
|
return .formSheet
|
|
|
|
}
|
2021-09-27 10:30:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 09:47:13 +01:00
|
|
|
func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-27 10:30:36 +02:00
|
|
|
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
|
|
|
|
return false
|
2021-02-26 11:27:47 +01:00
|
|
|
}
|
|
|
|
}
|