mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-06 04:07:54 +00:00
88 lines
3.0 KiB
Swift
88 lines
3.0 KiB
Swift
//
|
|
// MainTimelineNextUnreadFooterView.swift
|
|
// NetNewsWire-iOS
|
|
//
|
|
// Created by Brent Simmons on 12/5/26.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
/// After the last row of the timeline: a button that goes to the next feed or folder with unread articles.
|
|
/// When marking read on scroll, the footer is also the empty space that lets every row scroll under the navigation bar.
|
|
final class MainTimelineNextUnreadFooterView: UICollectionReusableView {
|
|
|
|
var action: (() -> Void)?
|
|
|
|
/// The footer is always tall enough for the button, and at least this tall.
|
|
var minimumHeight: CGFloat {
|
|
get {
|
|
minimumHeightConstraint.constant
|
|
}
|
|
set {
|
|
minimumHeightConstraint.constant = newValue
|
|
}
|
|
}
|
|
|
|
private let button = UIButton()
|
|
private lazy var minimumHeightConstraint = heightAnchor.constraint(greaterThanOrEqualToConstant: 0)
|
|
private static let placeholderText = " "
|
|
private static let verticalPadding: CGFloat = 24.0
|
|
private static let horizontalPadding: CGFloat = 20.0
|
|
private static let buttonContentInsets = NSDirectionalEdgeInsets(top: 14.0, leading: 20.0, bottom: 14.0, trailing: 20.0)
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
commonInit()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
commonInit()
|
|
}
|
|
|
|
func configure(title: String, subtitle: String?) {
|
|
button.configuration?.title = title
|
|
button.configuration?.subtitle = subtitle
|
|
button.isHidden = false
|
|
}
|
|
|
|
/// The hidden button keeps placeholder text, so the footer is the same height with or without it.
|
|
func configureHidden(showSubtitle: Bool) {
|
|
button.configuration?.title = Self.placeholderText
|
|
button.configuration?.subtitle = showSubtitle ? Self.placeholderText : nil
|
|
button.isHidden = true
|
|
}
|
|
}
|
|
|
|
private extension MainTimelineNextUnreadFooterView {
|
|
|
|
func commonInit() {
|
|
// Flat, not glass — the button is part of the list, not the toolbar layer above it.
|
|
var configuration = UIButton.Configuration.gray()
|
|
configuration.baseForegroundColor = .label
|
|
configuration.cornerStyle = .large
|
|
configuration.contentInsets = Self.buttonContentInsets
|
|
configuration.titleAlignment = .center
|
|
configuration.titleLineBreakMode = .byTruncatingTail
|
|
configuration.subtitleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
|
var attributes = attributes
|
|
attributes.foregroundColor = .secondaryLabel
|
|
return attributes
|
|
}
|
|
button.configuration = configuration
|
|
button.addAction(UIAction { [weak self] _ in
|
|
self?.action?()
|
|
}, for: .primaryActionTriggered)
|
|
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
addSubview(button)
|
|
NSLayoutConstraint.activate([
|
|
button.leadingAnchor.constraint(equalTo: leadingAnchor, constant: Self.horizontalPadding),
|
|
button.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -Self.horizontalPadding),
|
|
button.topAnchor.constraint(equalTo: topAnchor, constant: Self.verticalPadding),
|
|
button.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor, constant: -Self.verticalPadding)
|
|
])
|
|
minimumHeightConstraint.isActive = true
|
|
}
|
|
}
|