chore(onboarding): Decrease spacing between title and top of WelcomeViewController
This commit is contained in:
parent
9e1dbe1dff
commit
a935cd83bb
|
@ -9,20 +9,20 @@ import UIKit
|
||||||
|
|
||||||
class WelcomeContentViewController: UIViewController {
|
class WelcomeContentViewController: UIViewController {
|
||||||
|
|
||||||
let page: WelcomeContentPage
|
let page: WelcomeContentPage
|
||||||
var contentView: WelcomeContentPageView {
|
var contentView: WelcomeContentPageView {
|
||||||
view as! WelcomeContentPageView
|
view as! WelcomeContentPageView
|
||||||
}
|
}
|
||||||
|
|
||||||
init(page: WelcomeContentPage) {
|
init(page: WelcomeContentPage) {
|
||||||
self.page = page
|
self.page = page
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
let pageView = WelcomeContentPageView(page: page)
|
let pageView = WelcomeContentPageView(page: page)
|
||||||
self.view = pageView
|
self.view = pageView
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,221 +13,229 @@ import MastodonLocalization
|
||||||
|
|
||||||
final class WelcomeViewController: UIViewController, NeedsDependency {
|
final class WelcomeViewController: UIViewController, NeedsDependency {
|
||||||
|
|
||||||
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
private enum Constants {
|
||||||
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
static let topAnchorInset: CGFloat = 20
|
||||||
|
}
|
||||||
|
|
||||||
var disposeBag = Set<AnyCancellable>()
|
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
||||||
var observations = Set<NSKeyValueObservation>()
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
||||||
private(set) lazy var viewModel = WelcomeViewModel(context: context)
|
|
||||||
|
|
||||||
let welcomeIllustrationView = WelcomeIllustrationView()
|
var disposeBag = Set<AnyCancellable>()
|
||||||
|
var observations = Set<NSKeyValueObservation>()
|
||||||
|
private(set) lazy var viewModel = WelcomeViewModel(context: context)
|
||||||
|
|
||||||
private(set) lazy var dismissBarButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(WelcomeViewController.dismissBarButtonItemDidPressed(_:)))
|
let welcomeIllustrationView = WelcomeIllustrationView()
|
||||||
|
|
||||||
let buttonContainer = UIStackView()
|
private(set) lazy var dismissBarButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(WelcomeViewController.dismissBarButtonItemDidPressed(_:)))
|
||||||
|
|
||||||
private(set) lazy var signUpButton: PrimaryActionButton = {
|
let buttonContainer = UIStackView()
|
||||||
let button = PrimaryActionButton()
|
|
||||||
button.adjustsBackgroundImageWhenUserInterfaceStyleChanges = false
|
|
||||||
button.contentEdgeInsets = WelcomeViewController.actionButtonPadding
|
|
||||||
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
|
||||||
button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))
|
|
||||||
button.setTitle(L10n.Common.Controls.Actions.signUp, for: .normal)
|
|
||||||
let backgroundImageColor: UIColor = .white
|
|
||||||
let backgroundImageHighlightedColor: UIColor = UIColor(white: 0.8, alpha: 1.0)
|
|
||||||
button.setBackgroundImage(.placeholder(color: backgroundImageColor), for: .normal)
|
|
||||||
button.setBackgroundImage(.placeholder(color: backgroundImageHighlightedColor), for: .highlighted)
|
|
||||||
button.setTitleColor(.black, for: .normal)
|
|
||||||
return button
|
|
||||||
}()
|
|
||||||
let signUpButtonShadowView = UIView()
|
|
||||||
|
|
||||||
private(set) lazy var signInButton: UIButton = {
|
private(set) lazy var signUpButton: PrimaryActionButton = {
|
||||||
let button = UIButton()
|
let button = PrimaryActionButton()
|
||||||
button.contentEdgeInsets = WelcomeViewController.actionButtonPadding
|
button.adjustsBackgroundImageWhenUserInterfaceStyleChanges = false
|
||||||
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
button.contentEdgeInsets = WelcomeViewController.actionButtonPadding
|
||||||
button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))
|
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
||||||
button.setTitle(L10n.Scene.Welcome.logIn, for: .normal)
|
button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))
|
||||||
let titleColor: UIColor = UIColor.white.withAlphaComponent(0.9)
|
button.setTitle(L10n.Common.Controls.Actions.signUp, for: .normal)
|
||||||
button.setTitleColor(titleColor, for: .normal)
|
let backgroundImageColor: UIColor = .white
|
||||||
button.setTitleColor(titleColor.withAlphaComponent(0.3), for: .highlighted)
|
let backgroundImageHighlightedColor: UIColor = UIColor(white: 0.8, alpha: 1.0)
|
||||||
return button
|
button.setBackgroundImage(.placeholder(color: backgroundImageColor), for: .normal)
|
||||||
}()
|
button.setBackgroundImage(.placeholder(color: backgroundImageHighlightedColor), for: .highlighted)
|
||||||
|
button.setTitleColor(.black, for: .normal)
|
||||||
|
return button
|
||||||
|
}()
|
||||||
|
let signUpButtonShadowView = UIView()
|
||||||
|
|
||||||
private(set) lazy var pageViewController: UIPageViewController = {
|
private(set) lazy var signInButton: UIButton = {
|
||||||
let pageController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)
|
let button = UIButton()
|
||||||
pageController.setViewControllers([WelcomeContentViewController(page: .whatIsMastodon)], direction: .forward, animated: false)
|
button.contentEdgeInsets = WelcomeViewController.actionButtonPadding
|
||||||
return pageController
|
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
||||||
}()
|
button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold))
|
||||||
var currentPage: WelcomeContentPage = .whatIsMastodon
|
button.setTitle(L10n.Scene.Welcome.logIn, for: .normal)
|
||||||
var currentPageOffset = 0
|
let titleColor: UIColor = UIColor.white.withAlphaComponent(0.9)
|
||||||
|
button.setTitleColor(titleColor, for: .normal)
|
||||||
|
button.setTitleColor(titleColor.withAlphaComponent(0.3), for: .highlighted)
|
||||||
|
return button
|
||||||
|
}()
|
||||||
|
|
||||||
|
private(set) lazy var pageViewController: UIPageViewController = {
|
||||||
|
let pageController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)
|
||||||
|
pageController.setViewControllers([WelcomeContentViewController(page: .whatIsMastodon)], direction: .forward, animated: false)
|
||||||
|
return pageController
|
||||||
|
}()
|
||||||
|
var currentPage: WelcomeContentPage = .whatIsMastodon
|
||||||
|
var currentPageOffset = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
extension WelcomeViewController {
|
extension WelcomeViewController {
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
definesPresentationContext = true
|
definesPresentationContext = true
|
||||||
preferredContentSize = CGSize(width: 547, height: 678)
|
preferredContentSize = CGSize(width: 547, height: 678)
|
||||||
|
|
||||||
navigationController?.navigationBar.prefersLargeTitles = true
|
navigationController?.navigationBar.prefersLargeTitles = true
|
||||||
view.overrideUserInterfaceStyle = .light
|
view.overrideUserInterfaceStyle = .light
|
||||||
|
|
||||||
setupOnboardingAppearance()
|
setupOnboardingAppearance()
|
||||||
|
|
||||||
view.addSubview(welcomeIllustrationView)
|
view.addSubview(welcomeIllustrationView)
|
||||||
welcomeIllustrationView.translatesAutoresizingMaskIntoConstraints = false
|
welcomeIllustrationView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
welcomeIllustrationView.topAnchor.constraint(equalTo: view.topAnchor),
|
welcomeIllustrationView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||||
welcomeIllustrationView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
welcomeIllustrationView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||||
view.trailingAnchor.constraint(equalTo: welcomeIllustrationView.trailingAnchor),
|
view.trailingAnchor.constraint(equalTo: welcomeIllustrationView.trailingAnchor),
|
||||||
view.bottomAnchor.constraint(equalTo: welcomeIllustrationView.bottomAnchor)
|
view.bottomAnchor.constraint(equalTo: welcomeIllustrationView.bottomAnchor)
|
||||||
])
|
])
|
||||||
|
|
||||||
buttonContainer.axis = .vertical
|
buttonContainer.axis = .vertical
|
||||||
buttonContainer.spacing = 12
|
buttonContainer.spacing = 12
|
||||||
buttonContainer.isLayoutMarginsRelativeArrangement = true
|
buttonContainer.isLayoutMarginsRelativeArrangement = true
|
||||||
|
|
||||||
buttonContainer.translatesAutoresizingMaskIntoConstraints = false
|
buttonContainer.translatesAutoresizingMaskIntoConstraints = false
|
||||||
view.addSubview(buttonContainer)
|
view.addSubview(buttonContainer)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
buttonContainer.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
|
buttonContainer.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
|
||||||
buttonContainer.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
|
buttonContainer.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
|
||||||
view.layoutMarginsGuide.bottomAnchor.constraint(equalTo: buttonContainer.bottomAnchor),
|
view.layoutMarginsGuide.bottomAnchor.constraint(equalTo: buttonContainer.bottomAnchor),
|
||||||
])
|
])
|
||||||
|
|
||||||
signUpButton.translatesAutoresizingMaskIntoConstraints = false
|
signUpButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
buttonContainer.addArrangedSubview(signUpButton)
|
buttonContainer.addArrangedSubview(signUpButton)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
signUpButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1),
|
signUpButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1),
|
||||||
])
|
])
|
||||||
signInButton.translatesAutoresizingMaskIntoConstraints = false
|
signInButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
buttonContainer.addArrangedSubview(signInButton)
|
buttonContainer.addArrangedSubview(signInButton)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
signInButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1),
|
signInButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1),
|
||||||
])
|
])
|
||||||
|
|
||||||
signUpButtonShadowView.translatesAutoresizingMaskIntoConstraints = false
|
signUpButtonShadowView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
buttonContainer.addSubview(signUpButtonShadowView)
|
buttonContainer.addSubview(signUpButtonShadowView)
|
||||||
buttonContainer.sendSubviewToBack(signUpButtonShadowView)
|
buttonContainer.sendSubviewToBack(signUpButtonShadowView)
|
||||||
signUpButtonShadowView.pinTo(to: signUpButton)
|
signUpButtonShadowView.pinTo(to: signUpButton)
|
||||||
|
|
||||||
signUpButton.addTarget(self, action: #selector(signUpButtonDidClicked(_:)), for: .touchUpInside)
|
signUpButton.addTarget(self, action: #selector(signUpButtonDidClicked(_:)), for: .touchUpInside)
|
||||||
signInButton.addTarget(self, action: #selector(signInButtonDidClicked(_:)), for: .touchUpInside)
|
signInButton.addTarget(self, action: #selector(signInButtonDidClicked(_:)), for: .touchUpInside)
|
||||||
|
|
||||||
pageViewController.delegate = self
|
pageViewController.delegate = self
|
||||||
pageViewController.dataSource = self
|
pageViewController.dataSource = self
|
||||||
addChild(pageViewController)
|
addChild(pageViewController)
|
||||||
pageViewController.view.translatesAutoresizingMaskIntoConstraints = false
|
pageViewController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
view.addSubview(pageViewController.view)
|
view.addSubview(pageViewController.view)
|
||||||
pageViewController.didMove(toParent: self)
|
pageViewController.didMove(toParent: self)
|
||||||
|
|
||||||
let scrollviews = pageViewController.view.subviews.filter { type(of: $0).isSubclass(of: UIScrollView.self) }.compactMap { $0 as? UIScrollView }
|
let scrollviews = pageViewController.view.subviews.filter { type(of: $0).isSubclass(of: UIScrollView.self) }.compactMap { $0 as? UIScrollView }
|
||||||
|
|
||||||
for scrollView in scrollviews {
|
for scrollView in scrollviews {
|
||||||
scrollView.delegate = self
|
scrollView.delegate = self
|
||||||
|
}
|
||||||
|
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
pageViewController.view.topAnchor.constraint(equalTo: view.topAnchor, constant: computedTopAnchorInset),
|
||||||
|
pageViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||||
|
view.trailingAnchor.constraint(equalTo: pageViewController.view.trailingAnchor),
|
||||||
|
buttonContainer.topAnchor.constraint(equalTo: pageViewController.view.bottomAnchor, constant: 16),
|
||||||
|
])
|
||||||
|
|
||||||
|
viewModel.$needsShowDismissEntry
|
||||||
|
.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)
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
override func viewDidLayoutSubviews() {
|
||||||
pageViewController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
|
super.viewDidLayoutSubviews()
|
||||||
pageViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
||||||
view.trailingAnchor.constraint(equalTo: pageViewController.view.trailingAnchor),
|
|
||||||
buttonContainer.topAnchor.constraint(equalTo: pageViewController.view.bottomAnchor, constant: 16),
|
|
||||||
])
|
|
||||||
|
|
||||||
viewModel.$needsShowDismissEntry
|
setupButtonShadowView()
|
||||||
.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)
|
|
||||||
}
|
|
||||||
|
|
||||||
override func viewDidLayoutSubviews() {
|
|
||||||
super.viewDidLayoutSubviews()
|
|
||||||
|
|
||||||
setupButtonShadowView()
|
|
||||||
}
|
|
||||||
|
|
||||||
override func viewSafeAreaInsetsDidChange() {
|
|
||||||
super.viewSafeAreaInsetsDidChange()
|
|
||||||
|
|
||||||
var overlap: CGFloat = 5
|
|
||||||
// shift illustration down for non-notch phone
|
|
||||||
if view.safeAreaInsets.bottom == 0 {
|
|
||||||
overlap += 56
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
override func viewSafeAreaInsetsDidChange() {
|
||||||
super.traitCollectionDidChange(previousTraitCollection)
|
super.viewSafeAreaInsetsDidChange()
|
||||||
|
|
||||||
view.layoutIfNeeded()
|
var overlap: CGFloat = 5
|
||||||
|
// shift illustration down for non-notch phone
|
||||||
|
if view.safeAreaInsets.bottom == 0 {
|
||||||
|
overlap += 56
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setupIllustrationLayout()
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||||
setupButtonShadowView()
|
super.traitCollectionDidChange(previousTraitCollection)
|
||||||
}
|
|
||||||
|
view.layoutIfNeeded()
|
||||||
|
|
||||||
|
setupIllustrationLayout()
|
||||||
|
setupButtonShadowView()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var computedTopAnchorInset: CGFloat {
|
||||||
|
(navigationController?.navigationBar.bounds.height ?? UINavigationBar().bounds.height) + Constants.topAnchorInset
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension WelcomeViewController {
|
extension WelcomeViewController {
|
||||||
|
|
||||||
private func setupButtonShadowView() {
|
private func setupButtonShadowView() {
|
||||||
signUpButtonShadowView.layer.setupShadow(
|
signUpButtonShadowView.layer.setupShadow(
|
||||||
color: .black,
|
color: .black,
|
||||||
alpha: 0.25,
|
alpha: 0.25,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 1,
|
y: 1,
|
||||||
blur: 2,
|
blur: 2,
|
||||||
spread: 0,
|
spread: 0,
|
||||||
roundedRect: signUpButtonShadowView.bounds,
|
roundedRect: signUpButtonShadowView.bounds,
|
||||||
byRoundingCorners: .allCorners,
|
byRoundingCorners: .allCorners,
|
||||||
cornerRadii: CGSize(width: 10, height: 10)
|
cornerRadii: CGSize(width: 10, height: 10)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private func setupIllustrationLayout() {
|
private func updateButtonContainerLayoutMargins(traitCollection: UITraitCollection) {
|
||||||
welcomeIllustrationView.setup()
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupIllustrationLayout() {
|
||||||
|
welcomeIllustrationView.setup()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension WelcomeViewController {
|
extension WelcomeViewController {
|
||||||
@objc
|
@objc
|
||||||
private func signUpButtonDidClicked(_ sender: UIButton) {
|
private func signUpButtonDidClicked(_ sender: UIButton) {
|
||||||
_ = coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context)), from: self, transition: .show)
|
_ = coordinator.present(scene: .mastodonPickServer(viewMode: MastodonPickServerViewModel(context: context)), from: self, transition: .show)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
private func signInButtonDidClicked(_ sender: UIButton) {
|
private func signInButtonDidClicked(_ sender: UIButton) {
|
||||||
_ = coordinator.present(scene: .mastodonLogin, from: self, transition: .show)
|
_ = coordinator.present(scene: .mastodonLogin, from: self, transition: .show)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
private func dismissBarButtonItemDidPressed(_ sender: UIButton) {
|
private func dismissBarButtonItemDidPressed(_ sender: UIButton) {
|
||||||
dismiss(animated: true, completion: nil)
|
dismiss(animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - OnboardingViewControllerAppearance
|
// MARK: - OnboardingViewControllerAppearance
|
||||||
|
@ -246,103 +254,103 @@ extension WelcomeViewController: OnboardingViewControllerAppearance {
|
||||||
// MARK: - UIAdaptivePresentationControllerDelegate
|
// MARK: - UIAdaptivePresentationControllerDelegate
|
||||||
extension WelcomeViewController: UIAdaptivePresentationControllerDelegate {
|
extension WelcomeViewController: UIAdaptivePresentationControllerDelegate {
|
||||||
|
|
||||||
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
|
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
|
||||||
|
|
||||||
// update button layout
|
// update button layout
|
||||||
updateButtonContainerLayoutMargins(traitCollection: traitCollection)
|
updateButtonContainerLayoutMargins(traitCollection: traitCollection)
|
||||||
|
|
||||||
let navigationController = navigationController as? OnboardingNavigationController
|
let navigationController = navigationController as? OnboardingNavigationController
|
||||||
|
|
||||||
switch traitCollection.userInterfaceIdiom {
|
switch traitCollection.userInterfaceIdiom {
|
||||||
case .phone:
|
case .phone:
|
||||||
navigationController?.gradientBorderView.isHidden = true
|
|
||||||
// make underneath view controller alive to fix layout issue due to view life cycle
|
|
||||||
return .fullScreen
|
|
||||||
default:
|
|
||||||
switch traitCollection.horizontalSizeClass {
|
|
||||||
case .compact:
|
|
||||||
navigationController?.gradientBorderView.isHidden = true
|
navigationController?.gradientBorderView.isHidden = true
|
||||||
|
// make underneath view controller alive to fix layout issue due to view life cycle
|
||||||
return .fullScreen
|
return .fullScreen
|
||||||
default:
|
default:
|
||||||
navigationController?.gradientBorderView.isHidden = false
|
switch traitCollection.horizontalSizeClass {
|
||||||
return .formSheet
|
case .compact:
|
||||||
|
navigationController?.gradientBorderView.isHidden = true
|
||||||
|
return .fullScreen
|
||||||
|
default:
|
||||||
|
navigationController?.gradientBorderView.isHidden = false
|
||||||
|
return .formSheet
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
|
func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
|
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK: - UIPageViewControllerDelegate
|
//MARK: - UIPageViewControllerDelegate
|
||||||
|
|
||||||
extension WelcomeViewController: UIPageViewControllerDelegate {
|
extension WelcomeViewController: UIPageViewControllerDelegate {
|
||||||
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
|
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
|
||||||
guard let currentViewController = pageViewController.viewControllers?.first as? WelcomeContentViewController else { return }
|
guard let currentViewController = pageViewController.viewControllers?.first as? WelcomeContentViewController else { return }
|
||||||
|
|
||||||
currentPage = currentViewController.page
|
currentPage = currentViewController.page
|
||||||
|
|
||||||
if let pageIndex = WelcomeContentPage.allCases.firstIndex(of: currentPage) {
|
if let pageIndex = WelcomeContentPage.allCases.firstIndex(of: currentPage) {
|
||||||
let offset = Int(pageIndex) * Int(pageViewController.view.frame.width)
|
let offset = Int(pageIndex) * Int(pageViewController.view.frame.width)
|
||||||
currentPageOffset = offset
|
currentPageOffset = offset
|
||||||
welcomeIllustrationView.update(contentOffset: CGFloat(offset))
|
welcomeIllustrationView.update(contentOffset: CGFloat(offset))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK: - UIPageViewDataSource
|
//MARK: - UIPageViewDataSource
|
||||||
|
|
||||||
extension WelcomeViewController: UIPageViewControllerDataSource {
|
extension WelcomeViewController: UIPageViewControllerDataSource {
|
||||||
|
|
||||||
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
|
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
|
||||||
WelcomeContentPage.allCases.firstIndex(of: currentPage) ?? 0
|
WelcomeContentPage.allCases.firstIndex(of: currentPage) ?? 0
|
||||||
}
|
|
||||||
|
|
||||||
func presentationCount(for pageViewController: UIPageViewController) -> Int {
|
|
||||||
return WelcomeContentPage.allCases.count
|
|
||||||
}
|
|
||||||
|
|
||||||
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
|
|
||||||
guard let viewController = viewController as? WelcomeContentViewController else { return nil }
|
|
||||||
|
|
||||||
let currentPage = viewController.page
|
|
||||||
|
|
||||||
switch currentPage {
|
|
||||||
case .whatIsMastodon:
|
|
||||||
return nil
|
|
||||||
case .mastodonIsLikeThat:
|
|
||||||
return WelcomeContentViewController(page: .whatIsMastodon)
|
|
||||||
case .howDoIPickAServer:
|
|
||||||
return WelcomeContentViewController(page: .mastodonIsLikeThat)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
|
func presentationCount(for pageViewController: UIPageViewController) -> Int {
|
||||||
guard let viewController = viewController as? WelcomeContentViewController else { return nil }
|
return WelcomeContentPage.allCases.count
|
||||||
|
}
|
||||||
let currentPage = viewController.page
|
|
||||||
|
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
|
||||||
switch currentPage {
|
guard let viewController = viewController as? WelcomeContentViewController else { return nil }
|
||||||
case .whatIsMastodon:
|
|
||||||
return WelcomeContentViewController(page: .mastodonIsLikeThat)
|
let currentPage = viewController.page
|
||||||
case .mastodonIsLikeThat:
|
|
||||||
return WelcomeContentViewController(page: .howDoIPickAServer)
|
switch currentPage {
|
||||||
case .howDoIPickAServer:
|
case .whatIsMastodon:
|
||||||
return nil
|
return nil
|
||||||
|
case .mastodonIsLikeThat:
|
||||||
|
return WelcomeContentViewController(page: .whatIsMastodon)
|
||||||
|
case .howDoIPickAServer:
|
||||||
|
return WelcomeContentViewController(page: .mastodonIsLikeThat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
|
||||||
|
guard let viewController = viewController as? WelcomeContentViewController else { return nil }
|
||||||
|
|
||||||
|
let currentPage = viewController.page
|
||||||
|
|
||||||
|
switch currentPage {
|
||||||
|
case .whatIsMastodon:
|
||||||
|
return WelcomeContentViewController(page: .mastodonIsLikeThat)
|
||||||
|
case .mastodonIsLikeThat:
|
||||||
|
return WelcomeContentViewController(page: .howDoIPickAServer)
|
||||||
|
case .howDoIPickAServer:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension WelcomeViewController: UIScrollViewDelegate {
|
extension WelcomeViewController: UIScrollViewDelegate {
|
||||||
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||||
let weirdScrollViewJumpingCorrectionFactor = pageViewController.view.frame.width
|
let weirdScrollViewJumpingCorrectionFactor = pageViewController.view.frame.width
|
||||||
let contentOffset = CGFloat(currentPageOffset) + scrollView.contentOffset.x - weirdScrollViewJumpingCorrectionFactor
|
let contentOffset = CGFloat(currentPageOffset) + scrollView.contentOffset.x - weirdScrollViewJumpingCorrectionFactor
|
||||||
|
|
||||||
welcomeIllustrationView.update(contentOffset: contentOffset)
|
welcomeIllustrationView.update(contentOffset: contentOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue