2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00
shannon d2b4d7b6b4 Refactor: Filter and Content Warning display and management
A large amount of change primarily to the view model layer, to make reasoning about the content reveal/hide state easier.

To prevent terrible scrolling jags while allowing the cells to be shorter when hiding content, the layout changes for content display state now happen before the cell is returned by the datasource provider and the tableview is reloaded when a status’s display mode changes.
2024-11-28 13:08:01 -05:00

73 lines
2.3 KiB
Swift

//
// SpoilerOverlayView.swift
//
//
// Created by MainasuK on 2022-1-29.
//
import UIKit
import MastodonLocalization
import MastodonAsset
import MetaTextKit
public final class ContentConcealExplainView: UIView {
let containerStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.spacing = 8
stackView.alignment = .center
return stackView
}()
let spoilerMetaLabel = MetaLabel(style: .statusSpoilerOverlay)
let hintLabel: UILabel = {
let label = UILabel()
label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .regular))
label.textAlignment = .center
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 ContentConcealExplainView {
private func _init() {
containerStackView.translatesAutoresizingMaskIntoConstraints = false
addSubview(containerStackView)
containerStackView.pinToParent()
let topPaddingView = UIView()
topPaddingView.translatesAutoresizingMaskIntoConstraints = false
containerStackView.addArrangedSubview(topPaddingView)
containerStackView.addArrangedSubview(spoilerMetaLabel)
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)
spoilerMetaLabel.isUserInteractionEnabled = false
isAccessibilityElement = true
accessibilityTraits.insert(.button)
}
}