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
|
|
|
//
|
|
|
|
|
|
|
|
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
|
2023-04-08 23:10:34 +02:00
|
|
|
import MastodonSDK
|
2021-02-20 06:56:24 +01:00
|
|
|
|
2021-02-23 08:44:59 +01:00
|
|
|
final class WelcomeViewController: UIViewController, NeedsDependency {
|
2022-12-28 15:28:09 +01:00
|
|
|
|
|
|
|
private enum Constants {
|
2023-01-06 13:44:11 +01:00
|
|
|
static let topAnchorInset: CGFloat = 20
|
2022-12-28 15:28:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
2023-04-08 23:10:34 +02:00
|
|
|
|
|
|
|
private(set) lazy var authenticationViewModel = AuthenticationViewModel(
|
|
|
|
context: context,
|
|
|
|
coordinator: coordinator,
|
|
|
|
isAuthenticationExist: false
|
|
|
|
)
|
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
var observations = Set<NSKeyValueObservation>()
|
|
|
|
private(set) lazy var viewModel = WelcomeViewModel(context: context)
|
|
|
|
|
|
|
|
let welcomeIllustrationView = WelcomeIllustrationView()
|
2023-04-08 23:10:34 +02:00
|
|
|
let separatorView = WelcomeSeparatorView(frame: .zero)
|
|
|
|
|
|
|
|
private(set) lazy var mastodonLogo: UIImageView = {
|
|
|
|
let imageView = UIImageView(image: Asset.Scene.Welcome.mastodonLogo.image)
|
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Extract all those UI-elements in a UIView-subclass
|
2022-12-28 15:28:09 +01:00
|
|
|
private(set) lazy var dismissBarButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(WelcomeViewController.dismissBarButtonItemDidPressed(_:)))
|
|
|
|
|
|
|
|
let buttonContainer = UIStackView()
|
2023-04-08 23:10:34 +02:00
|
|
|
|
|
|
|
private(set) lazy var joinDefaultServerButton: UIButton = {
|
|
|
|
var buttonConfiguration = UIButton.Configuration.filled()
|
|
|
|
buttonConfiguration.baseForegroundColor = .white
|
|
|
|
buttonConfiguration.background.backgroundColor = Asset.Colors.Brand.blurple.color
|
|
|
|
buttonConfiguration.background.cornerRadius = 14
|
|
|
|
buttonConfiguration.activityIndicatorColorTransformer = UIConfigurationColorTransformer({ _ in
|
|
|
|
return UIColor.white
|
|
|
|
})
|
|
|
|
|
|
|
|
buttonConfiguration.contentInsets = .init(top: WelcomeViewController.actionButtonPadding.top,
|
|
|
|
leading: WelcomeViewController.actionButtonPadding.left,
|
|
|
|
bottom: WelcomeViewController.actionButtonPadding.bottom,
|
|
|
|
trailing: WelcomeViewController.actionButtonPadding.right)
|
|
|
|
|
|
|
|
let button = UIButton(configuration: buttonConfiguration)
|
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
return button
|
|
|
|
}()
|
2023-04-08 23:10:34 +02:00
|
|
|
|
|
|
|
private(set) lazy var signUpButton: UIButton = {
|
|
|
|
|
|
|
|
var buttonConfiguration = UIButton.Configuration.borderedTinted()
|
|
|
|
buttonConfiguration.attributedTitle = AttributedString(
|
|
|
|
L10n.Scene.Welcome.pickServer,
|
|
|
|
attributes: .init([.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))])
|
|
|
|
)
|
|
|
|
|
|
|
|
buttonConfiguration.background.cornerRadius = 14
|
|
|
|
buttonConfiguration.background.strokeColor = UIColor.white.withAlphaComponent(0.6)
|
|
|
|
buttonConfiguration.background.strokeWidth = 1
|
|
|
|
buttonConfiguration.baseBackgroundColor = .clear
|
|
|
|
buttonConfiguration.baseForegroundColor = .white
|
|
|
|
|
|
|
|
buttonConfiguration.contentInsets = .init(top: WelcomeViewController.actionButtonPadding.top,
|
|
|
|
leading: WelcomeViewController.actionButtonPadding.left,
|
|
|
|
bottom: WelcomeViewController.actionButtonPadding.bottom,
|
|
|
|
trailing: WelcomeViewController.actionButtonPadding.right)
|
|
|
|
|
|
|
|
let button = UIButton(configuration: buttonConfiguration)
|
|
|
|
|
|
|
|
return button
|
|
|
|
}()
|
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
private(set) lazy var signInButton: UIButton = {
|
2023-04-08 23:10:34 +02:00
|
|
|
var buttonConfiguration = UIButton.Configuration.plain()
|
|
|
|
buttonConfiguration.baseForegroundColor = .white
|
|
|
|
buttonConfiguration.attributedTitle = AttributedString(
|
|
|
|
L10n.Scene.Welcome.logIn,
|
|
|
|
attributes: .init([.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))])
|
|
|
|
)
|
|
|
|
|
|
|
|
let button = UIButton(configuration: buttonConfiguration)
|
2022-12-28 15:28:09 +01:00
|
|
|
return button
|
|
|
|
}()
|
2023-04-08 23:10:34 +02:00
|
|
|
|
|
|
|
private(set) lazy var learnMoreButton: UIButton = {
|
|
|
|
var buttonConfiguration = UIButton.Configuration.plain()
|
|
|
|
buttonConfiguration.baseForegroundColor = .white
|
|
|
|
buttonConfiguration.attributedTitle = AttributedString(
|
|
|
|
L10n.Scene.Welcome.learnMore,
|
|
|
|
attributes: .init([.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))])
|
|
|
|
)
|
|
|
|
|
|
|
|
let button = UIButton(configuration: buttonConfiguration)
|
|
|
|
return button
|
2022-12-28 15:28:09 +01:00
|
|
|
}()
|
2023-01-08 14:25:22 +01:00
|
|
|
|
2023-04-08 23:10:34 +02:00
|
|
|
private(set) lazy var bottomButtonStackView: UIStackView = {
|
|
|
|
let bottomButtonStackView = UIStackView(arrangedSubviews: [learnMoreButton, signInButton])
|
|
|
|
bottomButtonStackView.axis = .horizontal
|
|
|
|
bottomButtonStackView.distribution = .fill
|
|
|
|
bottomButtonStackView.alignment = .center
|
|
|
|
bottomButtonStackView.spacing = 16
|
|
|
|
bottomButtonStackView.setContentHuggingPriority(.required, for: .vertical)
|
|
|
|
|
|
|
|
return bottomButtonStackView
|
2023-01-08 14:25:22 +01:00
|
|
|
}()
|
2021-02-20 06:56:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension WelcomeViewController {
|
2022-12-28 15:28:09 +01:00
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
definesPresentationContext = true
|
|
|
|
preferredContentSize = CGSize(width: 547, height: 678)
|
|
|
|
|
2023-03-28 21:44:51 +02:00
|
|
|
navigationController?.navigationBar.prefersLargeTitles = true /// enable large title support for this and all subsequent VCs
|
|
|
|
navigationItem.largeTitleDisplayMode = .never
|
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
view.overrideUserInterfaceStyle = .light
|
|
|
|
|
|
|
|
setupOnboardingAppearance()
|
2023-04-08 23:10:34 +02:00
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
view.addSubview(welcomeIllustrationView)
|
|
|
|
welcomeIllustrationView.translatesAutoresizingMaskIntoConstraints = false
|
2023-04-08 23:10:34 +02:00
|
|
|
|
|
|
|
mastodonLogo.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(mastodonLogo)
|
2022-12-28 15:28:09 +01:00
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
2023-04-08 23:10:34 +02:00
|
|
|
mastodonLogo.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 24),
|
|
|
|
mastodonLogo.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
|
|
|
mastodonLogo.widthAnchor.constraint(equalToConstant: 300),
|
2022-12-28 15:28:09 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
buttonContainer.axis = .vertical
|
|
|
|
buttonContainer.spacing = 12
|
|
|
|
buttonContainer.isLayoutMarginsRelativeArrangement = true
|
|
|
|
|
|
|
|
buttonContainer.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(buttonContainer)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
buttonContainer.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
|
|
|
|
buttonContainer.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
|
|
|
|
view.layoutMarginsGuide.bottomAnchor.constraint(equalTo: buttonContainer.bottomAnchor),
|
|
|
|
])
|
2023-04-08 23:10:34 +02:00
|
|
|
|
|
|
|
joinDefaultServerButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.addArrangedSubview(joinDefaultServerButton)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
joinDefaultServerButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight)
|
|
|
|
])
|
2022-12-28 15:28:09 +01:00
|
|
|
|
|
|
|
signUpButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.addArrangedSubview(signUpButton)
|
|
|
|
NSLayoutConstraint.activate([
|
2023-04-08 23:10:34 +02:00
|
|
|
signUpButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight)
|
2022-12-28 15:28:09 +01:00
|
|
|
])
|
2023-04-08 23:10:34 +02:00
|
|
|
|
|
|
|
buttonContainer.addArrangedSubview(separatorView)
|
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
signInButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
NSLayoutConstraint.activate([
|
2023-04-08 23:10:34 +02:00
|
|
|
signInButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight)
|
2022-12-28 15:28:09 +01:00
|
|
|
])
|
2023-01-07 16:02:46 +01:00
|
|
|
|
2023-04-08 23:10:34 +02:00
|
|
|
learnMoreButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
learnMoreButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight),
|
|
|
|
bottomButtonStackView.heightAnchor.constraint(equalTo: learnMoreButton.heightAnchor),
|
|
|
|
])
|
|
|
|
|
|
|
|
buttonContainer.addArrangedSubview(bottomButtonStackView)
|
2023-01-08 14:25:22 +01:00
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
NSLayoutConstraint.activate([
|
2023-04-08 23:10:34 +02:00
|
|
|
welcomeIllustrationView.topAnchor.constraint(equalTo: view.topAnchor),
|
|
|
|
welcomeIllustrationView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
|
|
view.trailingAnchor.constraint(equalTo: welcomeIllustrationView.trailingAnchor),
|
|
|
|
separatorView.centerYAnchor.constraint(equalTo: welcomeIllustrationView.bottomAnchor)
|
2022-12-28 15:28:09 +01:00
|
|
|
])
|
2023-01-08 14:25:22 +01:00
|
|
|
|
2023-04-08 23:10:34 +02:00
|
|
|
joinDefaultServerButton.addTarget(self, action: #selector(joinDefaultServer(_:)), for: .touchUpInside)
|
|
|
|
signUpButton.addTarget(self, action: #selector(signUp(_:)), for: .touchUpInside)
|
|
|
|
signInButton.addTarget(self, action: #selector(signIn(_:)), for: .touchUpInside)
|
|
|
|
learnMoreButton.addTarget(self, action: #selector(learnMore(_:)), for: .touchUpInside)
|
|
|
|
|
|
|
|
view.backgroundColor = Asset.Scene.Welcome.Illustration.backgroundGreen.color
|
2022-12-28 15:28:09 +01:00
|
|
|
|
|
|
|
viewModel.$needsShowDismissEntry
|
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink { [weak self] needsShowDismissEntry in
|
|
|
|
guard let self = self else { return }
|
2023-01-06 13:44:11 +01:00
|
|
|
self.navigationItem.leftBarButtonItem = needsShowDismissEntry ? self.dismissBarButtonItem : nil
|
2022-12-28 15:28:09 +01:00
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
2023-04-08 23:10:34 +02:00
|
|
|
|
2023-04-12 14:04:06 +02:00
|
|
|
setupIllustrationLayout()
|
2023-07-02 14:43:49 +02:00
|
|
|
|
|
|
|
joinDefaultServerButton.configuration?.showsActivityIndicator = true
|
|
|
|
joinDefaultServerButton.isEnabled = false
|
|
|
|
joinDefaultServerButton.configuration?.title = nil
|
|
|
|
|
|
|
|
viewModel.downloadDefaultServer { [weak self] in
|
|
|
|
guard let selectedDefaultServer = self?.viewModel.randomDefaultServer else { return }
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
self?.joinDefaultServerButton.configuration?.showsActivityIndicator = false
|
|
|
|
self?.joinDefaultServerButton.isEnabled = true
|
|
|
|
self?.joinDefaultServerButton.configuration?.attributedTitle = AttributedString(
|
|
|
|
L10n.Scene.Welcome.joinDefaultServer(selectedDefaultServer.domain),
|
|
|
|
attributes: .init([.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2022-12-28 15:28:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
|
|
super.traitCollectionDidChange(previousTraitCollection)
|
|
|
|
|
|
|
|
view.layoutIfNeeded()
|
|
|
|
}
|
2023-01-06 13:44:11 +01:00
|
|
|
|
|
|
|
private var computedTopAnchorInset: CGFloat {
|
|
|
|
(navigationController?.navigationBar.bounds.height ?? UINavigationBar().bounds.height) + Constants.topAnchorInset
|
|
|
|
}
|
2021-02-23 08:44:59 +01:00
|
|
|
}
|
|
|
|
|
2021-03-16 11:24:48 +01:00
|
|
|
extension WelcomeViewController {
|
2023-04-08 23:10:34 +02:00
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
private func updateButtonContainerLayoutMargins(traitCollection: UITraitCollection) {
|
|
|
|
switch traitCollection.userInterfaceIdiom {
|
|
|
|
case .phone:
|
|
|
|
buttonContainer.layoutMargins = UIEdgeInsets(
|
|
|
|
top: 0,
|
|
|
|
left: WelcomeViewController.actionButtonMargin,
|
2023-04-08 23:10:34 +02:00
|
|
|
bottom: 0,
|
2022-12-28 15:28:09 +01:00
|
|
|
right: WelcomeViewController.actionButtonMargin
|
|
|
|
)
|
|
|
|
default:
|
|
|
|
let margin = traitCollection.horizontalSizeClass == .regular ? WelcomeViewController.actionButtonMarginExtend : WelcomeViewController.actionButtonMargin
|
|
|
|
buttonContainer.layoutMargins = UIEdgeInsets(
|
|
|
|
top: 0,
|
|
|
|
left: margin,
|
2023-04-08 23:10:34 +02:00
|
|
|
bottom: 0,
|
2022-12-28 15:28:09 +01:00
|
|
|
right: margin
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func setupIllustrationLayout() {
|
|
|
|
welcomeIllustrationView.setup()
|
|
|
|
}
|
2021-02-23 08:44:59 +01:00
|
|
|
}
|
|
|
|
|
2021-02-23 15:14:10 +01:00
|
|
|
extension WelcomeViewController {
|
2023-01-08 14:25:22 +01:00
|
|
|
|
|
|
|
//MARK: - Actions
|
2022-12-28 15:28:09 +01:00
|
|
|
@objc
|
2023-04-08 23:10:34 +02:00
|
|
|
private func joinDefaultServer(_ sender: UIButton) {
|
2023-07-02 14:43:49 +02:00
|
|
|
|
|
|
|
guard let server = viewModel.randomDefaultServer else { return }
|
2023-04-08 23:10:34 +02:00
|
|
|
sender.configuration?.title = nil
|
|
|
|
sender.isEnabled = false
|
|
|
|
sender.configuration?.showsActivityIndicator = true
|
|
|
|
|
|
|
|
authenticationViewModel.isAuthenticating.send(true)
|
|
|
|
|
|
|
|
context.apiService.instance(domain: server.domain)
|
|
|
|
.compactMap { [weak self] response -> AnyPublisher<MastodonPickServerViewModel.SignUpResponseFirst, Error>? in
|
|
|
|
guard let self = self else { return nil }
|
|
|
|
guard response.value.registrations != false else {
|
|
|
|
return Fail(error: AuthenticationViewModel.AuthenticationError.registrationClosed).eraseToAnyPublisher()
|
|
|
|
}
|
|
|
|
return self.context.apiService.createApplication(domain: server.domain)
|
|
|
|
.map { MastodonPickServerViewModel.SignUpResponseFirst(instance: response, application: $0) }
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|
}
|
|
|
|
.switchToLatest()
|
|
|
|
.tryMap { response -> MastodonPickServerViewModel.SignUpResponseSecond in
|
|
|
|
let application = response.application.value
|
|
|
|
guard let authenticateInfo = AuthenticationViewModel.AuthenticateInfo(
|
|
|
|
domain: server.domain,
|
|
|
|
application: application
|
|
|
|
) else {
|
|
|
|
throw APIService.APIError.explicit(.badResponse)
|
|
|
|
}
|
|
|
|
return MastodonPickServerViewModel.SignUpResponseSecond(
|
|
|
|
instance: response.instance,
|
|
|
|
authenticateInfo: authenticateInfo
|
|
|
|
)
|
|
|
|
}
|
|
|
|
.compactMap { [weak self] response -> AnyPublisher<MastodonPickServerViewModel.SignUpResponseThird, Error>? in
|
|
|
|
guard let self = self else { return nil }
|
|
|
|
let instance = response.instance
|
|
|
|
let authenticateInfo = response.authenticateInfo
|
|
|
|
return self.context.apiService.applicationAccessToken(
|
|
|
|
domain: server.domain,
|
|
|
|
clientID: authenticateInfo.clientID,
|
|
|
|
clientSecret: authenticateInfo.clientSecret,
|
|
|
|
redirectURI: authenticateInfo.redirectURI
|
|
|
|
)
|
|
|
|
.map {
|
|
|
|
MastodonPickServerViewModel.SignUpResponseThird(
|
|
|
|
instance: instance,
|
|
|
|
authenticateInfo: authenticateInfo,
|
|
|
|
applicationToken: $0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|
}
|
|
|
|
.switchToLatest()
|
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink { [weak self] completion in
|
|
|
|
guard let self = self else { return }
|
|
|
|
self.authenticationViewModel.isAuthenticating.send(false)
|
|
|
|
|
|
|
|
switch completion {
|
2023-07-02 14:43:49 +02:00
|
|
|
case .failure(let error ):
|
|
|
|
guard let randomServer = self.viewModel.pickRandomDefaultServer() else { return }
|
|
|
|
|
|
|
|
viewModel.randomDefaultServer = randomServer
|
|
|
|
|
|
|
|
sender.isEnabled = true
|
|
|
|
sender.configuration?.showsActivityIndicator = false
|
|
|
|
sender.configuration?.attributedTitle = AttributedString(
|
|
|
|
L10n.Scene.Welcome.joinDefaultServer(randomServer.domain),
|
|
|
|
attributes: .init([.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))])
|
|
|
|
)
|
|
|
|
case .finished:
|
|
|
|
sender.isEnabled = true
|
|
|
|
sender.configuration?.showsActivityIndicator = false
|
|
|
|
sender.configuration?.attributedTitle = AttributedString(
|
|
|
|
L10n.Scene.Welcome.joinDefaultServer(server.domain),
|
|
|
|
attributes: .init([.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))])
|
|
|
|
)
|
2023-04-08 23:10:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} receiveValue: { [weak self] response in
|
|
|
|
guard let self = self else { return }
|
|
|
|
if let rules = response.instance.value.rules, !rules.isEmpty {
|
|
|
|
// show server rules before register
|
|
|
|
let mastodonServerRulesViewModel = MastodonServerRulesViewModel(
|
|
|
|
domain: server.domain,
|
|
|
|
authenticateInfo: response.authenticateInfo,
|
|
|
|
rules: rules,
|
|
|
|
instance: response.instance.value,
|
|
|
|
applicationToken: response.applicationToken.value
|
|
|
|
)
|
|
|
|
_ = self.coordinator.present(scene: .mastodonServerRules(viewModel: mastodonServerRulesViewModel), from: self, transition: .show)
|
|
|
|
} else {
|
|
|
|
let mastodonRegisterViewModel = MastodonRegisterViewModel(
|
|
|
|
context: self.context,
|
|
|
|
domain: server.domain,
|
|
|
|
authenticateInfo: response.authenticateInfo,
|
|
|
|
instance: response.instance.value,
|
|
|
|
applicationToken: response.applicationToken.value
|
|
|
|
)
|
|
|
|
_ = self.coordinator.present(scene: .mastodonRegister(viewModel: mastodonRegisterViewModel), from: nil, transition: .show)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc
|
|
|
|
private func signUp(_ sender: UIButton) {
|
2022-12-28 15:28:09 +01:00
|
|
|
_ = coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context)), from: self, transition: .show)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc
|
2023-04-08 23:10:34 +02:00
|
|
|
private func signIn(_ sender: UIButton) {
|
2022-12-28 15:28:09 +01:00
|
|
|
_ = coordinator.present(scene: .mastodonLogin, from: self, transition: .show)
|
|
|
|
}
|
2023-04-08 23:10:34 +02:00
|
|
|
|
2022-12-28 15:28:09 +01:00
|
|
|
@objc
|
2023-04-08 23:10:34 +02:00
|
|
|
private func learnMore(_ sender: UIButton) {
|
|
|
|
let educationViewController = EducationViewController()
|
|
|
|
educationViewController.modalPresentationStyle = .pageSheet
|
|
|
|
|
|
|
|
if let sheetPresentationController = educationViewController.sheetPresentationController {
|
|
|
|
sheetPresentationController.detents = [.medium()]
|
|
|
|
sheetPresentationController.prefersGrabberVisible = true
|
|
|
|
}
|
|
|
|
|
|
|
|
present(educationViewController, animated: true)
|
2022-12-28 15:28:09 +01:00
|
|
|
}
|
2023-01-08 14:25:22 +01:00
|
|
|
|
|
|
|
@objc
|
2023-04-08 23:10:34 +02:00
|
|
|
private func dismissBarButtonItemDidPressed(_ sender: UIButton) {
|
|
|
|
dismiss(animated: true, completion: nil)
|
2023-01-08 14:25:22 +01:00
|
|
|
}
|
2021-02-23 15:14:10 +01:00
|
|
|
}
|
2021-02-26 09:43:59 +01:00
|
|
|
|
|
|
|
// MARK: - OnboardingViewControllerAppearance
|
2023-01-08 15:15:31 +01:00
|
|
|
extension WelcomeViewController: OnboardingViewControllerAppearance {}
|
2021-02-26 11:27:47 +01:00
|
|
|
|
|
|
|
// MARK: - UIAdaptivePresentationControllerDelegate
|
|
|
|
extension WelcomeViewController: UIAdaptivePresentationControllerDelegate {
|
2022-12-28 15:28:09 +01:00
|
|
|
|
|
|
|
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
|
|
|
|
|
|
|
|
// update button layout
|
|
|
|
updateButtonContainerLayoutMargins(traitCollection: traitCollection)
|
|
|
|
|
|
|
|
let navigationController = navigationController as? OnboardingNavigationController
|
|
|
|
|
|
|
|
switch traitCollection.userInterfaceIdiom {
|
|
|
|
case .phone:
|
2021-12-31 10:31:13 +01:00
|
|
|
navigationController?.gradientBorderView.isHidden = true
|
2022-12-28 15:28:09 +01:00
|
|
|
// make underneath view controller alive to fix layout issue due to view life cycle
|
2021-09-27 10:30:36 +02:00
|
|
|
return .fullScreen
|
2022-12-28 15:28:09 +01:00
|
|
|
default:
|
|
|
|
switch traitCollection.horizontalSizeClass {
|
|
|
|
case .compact:
|
|
|
|
navigationController?.gradientBorderView.isHidden = true
|
|
|
|
return .fullScreen
|
|
|
|
default:
|
|
|
|
navigationController?.gradientBorderView.isHidden = false
|
|
|
|
return .formSheet
|
|
|
|
}
|
2021-09-27 10:30:36 +02:00
|
|
|
}
|
|
|
|
}
|
2022-12-28 15:28:09 +01:00
|
|
|
|
|
|
|
func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
|
|
|
|
return false
|
|
|
|
}
|
2022-11-26 15:22:23 +01:00
|
|
|
}
|
|
|
|
|
2023-01-07 16:02:46 +01:00
|
|
|
//MARK: - UICollectionViewDelegate
|
|
|
|
extension WelcomeViewController: UICollectionViewDelegate { }
|