2022-01-29 10:02:30 +01:00
|
|
|
//
|
|
|
|
// SpoilerOverlayView.swift
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Created by MainasuK on 2022-1-29.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import MastodonLocalization
|
|
|
|
import MastodonAsset
|
|
|
|
import MetaTextKit
|
|
|
|
|
2022-02-08 12:50:18 +01:00
|
|
|
public final class SpoilerOverlayView: UIView {
|
2022-01-29 10:02:30 +01:00
|
|
|
|
|
|
|
let containerStackView: UIStackView = {
|
|
|
|
let stackView = UIStackView()
|
|
|
|
stackView.axis = .vertical
|
2022-02-08 12:50:18 +01:00
|
|
|
stackView.spacing = 8
|
2022-01-29 10:02:30 +01:00
|
|
|
stackView.alignment = .center
|
|
|
|
return stackView
|
|
|
|
}()
|
|
|
|
|
2022-02-08 12:50:18 +01:00
|
|
|
let spoilerMetaLabel = MetaLabel(style: .statusSpoilerOverlay)
|
|
|
|
|
|
|
|
let hintLabel: UILabel = {
|
2022-01-29 10:02:30 +01:00
|
|
|
let label = UILabel()
|
2022-02-08 12:50:18 +01:00
|
|
|
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .regular))
|
2022-01-29 10:02:30 +01:00
|
|
|
label.textAlignment = .center
|
2022-02-08 12:50:18 +01:00
|
|
|
label.textColor = Asset.Colors.Label.secondary.color
|
|
|
|
label.text = L10n.Common.Controls.Status.mediaContentWarning
|
2022-01-29 10:02:30 +01:00
|
|
|
return label
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension SpoilerOverlayView {
|
|
|
|
private func _init() {
|
|
|
|
containerStackView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
addSubview(containerStackView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
containerStackView.topAnchor.constraint(equalTo: topAnchor),
|
|
|
|
containerStackView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
|
containerStackView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
|
containerStackView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
|
|
])
|
|
|
|
|
|
|
|
let topPaddingView = UIView()
|
|
|
|
topPaddingView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
containerStackView.addArrangedSubview(topPaddingView)
|
|
|
|
containerStackView.addArrangedSubview(spoilerMetaLabel)
|
2022-02-08 12:50:18 +01:00
|
|
|
containerStackView.addArrangedSubview(hintLabel)
|
2022-01-29 10:02:30 +01:00
|
|
|
let bottomPaddingView = UIView()
|
|
|
|
bottomPaddingView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
containerStackView.addArrangedSubview(bottomPaddingView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
topPaddingView.heightAnchor.constraint(equalTo: bottomPaddingView.heightAnchor).priority(.required - 1),
|
|
|
|
])
|
|
|
|
topPaddingView.setContentCompressionResistancePriority(.defaultLow - 100, for: .vertical)
|
|
|
|
bottomPaddingView.setContentCompressionResistancePriority(.defaultLow - 100, for: .vertical)
|
2022-02-08 12:50:18 +01:00
|
|
|
|
|
|
|
spoilerMetaLabel.isUserInteractionEnabled = false
|
2022-02-14 12:34:22 +01:00
|
|
|
|
|
|
|
isAccessibilityElement = true
|
2022-01-29 10:02:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public func setComponentHidden(_ isHidden: Bool) {
|
|
|
|
containerStackView.arrangedSubviews.forEach { $0.isHidden = isHidden }
|
|
|
|
}
|
|
|
|
}
|