Kurdtvs-Live-Kurdish-TV-Kur.../MastodonSDK/Sources/MastodonUI/View/Control/SpoilerOverlayView.swift

81 lines
2.7 KiB
Swift
Raw Normal View History

//
// 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 {
let containerStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
2022-02-08 12:50:18 +01:00
stackView.spacing = 8
stackView.alignment = .center
return stackView
}()
2022-02-08 12:50:18 +01:00
let spoilerMetaLabel = MetaLabel(style: .statusSpoilerOverlay)
let hintLabel: UILabel = {
let label = UILabel()
2022-02-08 12:50:18 +01:00
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .regular))
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
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)
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
}
public func setComponentHidden(_ isHidden: Bool) {
containerStackView.arrangedSubviews.forEach { $0.isHidden = isHidden }
}
}