mastodon-ios/Mastodon/Scene/Onboarding/Share/NavigationActionView.swift

96 lines
3.8 KiB
Swift
Raw Normal View History

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
import MastodonAsset
import MastodonLocalization
2022-01-04 11:30:21 +01:00
final class NavigationActionView: UIView {
static let buttonHeight: CGFloat = 50
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
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
button.setTitle(L10n.Common.Controls.Actions.next, for: .normal)
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
_init()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
_init()
}
}
extension NavigationActionView {
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([
backButtonShadowContainer.heightAnchor.constraint(equalToConstant: NavigationActionView.buttonHeight).priority(.required - 1),
nextButtonShadowContainer.heightAnchor.constraint(equalToConstant: NavigationActionView.buttonHeight).priority(.required - 1),
nextButtonShadowContainer.widthAnchor.constraint(equalTo: backButtonShadowContainer.widthAnchor, multiplier: 2).priority(.required - 1),
])
2022-01-04 11:30:21 +01:00
backButton.translatesAutoresizingMaskIntoConstraints = false
2022-01-05 08:11:35 +01:00
backButtonShadowContainer.addSubview(backButton)
NSLayoutConstraint.activate([
backButton.topAnchor.constraint(equalTo: backButtonShadowContainer.topAnchor),
backButton.leadingAnchor.constraint(equalTo: backButtonShadowContainer.leadingAnchor),
backButton.trailingAnchor.constraint(equalTo: backButtonShadowContainer.trailingAnchor),
backButton.bottomAnchor.constraint(equalTo: backButtonShadowContainer.bottomAnchor),
])
2022-01-04 11:30:21 +01:00
nextButton.translatesAutoresizingMaskIntoConstraints = false
2022-01-05 08:11:35 +01:00
nextButtonShadowContainer.addSubview(nextButton)
2022-01-04 11:30:21 +01:00
NSLayoutConstraint.activate([
2022-01-05 08:11:35 +01:00
nextButton.topAnchor.constraint(equalTo: nextButtonShadowContainer.topAnchor),
nextButton.leadingAnchor.constraint(equalTo: nextButtonShadowContainer.leadingAnchor),
nextButton.trailingAnchor.constraint(equalTo: nextButtonShadowContainer.trailingAnchor),
nextButton.bottomAnchor.constraint(equalTo: nextButtonShadowContainer.bottomAnchor),
2022-01-04 11:30:21 +01:00
])
}
2022-01-05 08:11:35 +01:00
2022-01-04 11:30:21 +01:00
}