2022-01-04 11:30:21 +01:00
|
|
|
//
|
|
|
|
// NavigationActionView.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK on 2021-12-31.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2022-01-05 08:11:35 +01:00
|
|
|
import MastodonUI
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
|
|
|
import MastodonLocalization
|
2022-01-04 11:30:21 +01:00
|
|
|
|
|
|
|
final class NavigationActionView: UIView {
|
|
|
|
|
|
|
|
static let buttonHeight: CGFloat = 50
|
2022-11-13 05:22:57 +01:00
|
|
|
static let minimumBackButtonWidth: CGFloat = 100
|
2022-01-04 11:30:21 +01:00
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
private var observations = Set<NSKeyValueObservation>()
|
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
let buttonContainer: UIStackView = {
|
|
|
|
let stackView = UIStackView()
|
|
|
|
stackView.axis = .horizontal
|
|
|
|
stackView.spacing = 18
|
|
|
|
return stackView
|
|
|
|
}()
|
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
let backButtonShadowContainer = ShadowBackgroundContainer()
|
2022-01-04 11:30:21 +01:00
|
|
|
let backButton: PrimaryActionButton = {
|
|
|
|
let button = PrimaryActionButton()
|
|
|
|
button.action = .back
|
2022-11-13 05:22:57 +01:00
|
|
|
button.contentEdgeInsets = WelcomeViewController.actionButtonPadding
|
|
|
|
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
2022-01-04 11:30:21 +01:00
|
|
|
button.setTitle(L10n.Common.Controls.Actions.back, for: .normal)
|
|
|
|
return button
|
|
|
|
}()
|
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
let nextButtonShadowContainer = ShadowBackgroundContainer()
|
2022-01-04 11:30:21 +01:00
|
|
|
let nextButton: PrimaryActionButton = {
|
|
|
|
let button = PrimaryActionButton()
|
|
|
|
button.action = .next
|
2022-11-13 05:22:57 +01:00
|
|
|
button.contentEdgeInsets = WelcomeViewController.actionButtonPadding
|
|
|
|
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
2022-01-04 11:30:21 +01:00
|
|
|
button.setTitle(L10n.Common.Controls.Actions.next, for: .normal)
|
|
|
|
return button
|
|
|
|
}()
|
|
|
|
|
2022-02-08 05:36:06 +01:00
|
|
|
var hidesBackButton: Bool = false {
|
|
|
|
didSet { backButtonShadowContainer.isHidden = hidesBackButton }
|
|
|
|
}
|
|
|
|
|
|
|
|
var hidesNextButton: Bool = false {
|
|
|
|
didSet { nextButtonShadowContainer.isHidden = hidesNextButton }
|
|
|
|
}
|
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NavigationActionView {
|
2022-02-08 05:36:06 +01:00
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
private func _init() {
|
|
|
|
buttonContainer.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.preservesSuperviewLayoutMargins = true
|
|
|
|
addSubview(buttonContainer)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
buttonContainer.topAnchor.constraint(equalTo: topAnchor, constant: 16),
|
|
|
|
buttonContainer.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor),
|
|
|
|
buttonContainer.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor),
|
|
|
|
safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: buttonContainer.bottomAnchor, constant: 8),
|
|
|
|
])
|
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
backButtonShadowContainer.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.addArrangedSubview(backButtonShadowContainer)
|
|
|
|
nextButtonShadowContainer.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
buttonContainer.addArrangedSubview(nextButtonShadowContainer)
|
|
|
|
NSLayoutConstraint.activate([
|
2022-11-13 05:22:57 +01:00
|
|
|
backButtonShadowContainer.heightAnchor.constraint(greaterThanOrEqualToConstant: NavigationActionView.buttonHeight).priority(.required - 1),
|
|
|
|
nextButtonShadowContainer.heightAnchor.constraint(greaterThanOrEqualToConstant: NavigationActionView.buttonHeight).priority(.required - 1),
|
2022-01-05 08:11:35 +01:00
|
|
|
])
|
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
backButton.translatesAutoresizingMaskIntoConstraints = false
|
2022-01-05 08:11:35 +01:00
|
|
|
backButtonShadowContainer.addSubview(backButton)
|
2022-11-17 17:45:27 +01:00
|
|
|
backButton.pinToParent()
|
2022-01-05 08:11:35 +01:00
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
nextButton.translatesAutoresizingMaskIntoConstraints = false
|
2022-11-22 22:11:37 +01:00
|
|
|
nextButtonShadowContainer.addSubview(nextButton)
|
2022-11-17 17:45:27 +01:00
|
|
|
nextButton.pinToParent()
|
2022-11-13 05:22:57 +01:00
|
|
|
|
|
|
|
// We want the back button to be as small as possible, allowing the next button to take up
|
|
|
|
// any remaining space. .defaultLow is "the priority level at which a button hugs its
|
|
|
|
// contents horizontally". Setting this on backButton allows nextButton to eat up remaining
|
|
|
|
// space. Note that we have to set this on the backButton, not the container, because it's
|
|
|
|
// backButton's size that determines the compression amount.
|
|
|
|
backButton.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
|
|
// Ensure that the back button has a reasonable minimum tap area.
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
backButton.widthAnchor.constraint(greaterThanOrEqualToConstant: NavigationActionView.minimumBackButtonWidth).priority(.defaultLow - 1)
|
|
|
|
])
|
2022-01-04 11:30:21 +01:00
|
|
|
}
|
2022-01-05 08:11:35 +01:00
|
|
|
|
2022-01-04 11:30:21 +01:00
|
|
|
}
|