Show Rules (IOS-20)
This commit is contained in:
parent
f2bf822faa
commit
7cd5be1454
|
@ -10,7 +10,7 @@ import MastodonAsset
|
|||
import MastodonLocalization
|
||||
|
||||
final class ServerRulesTableViewCell: UITableViewCell {
|
||||
|
||||
static let reuseIdentifier = "ServerRulesTableViewCell"
|
||||
static let margin: CGFloat = 23
|
||||
|
||||
let indexImageView: UIImageView = {
|
||||
|
|
|
@ -15,10 +15,7 @@ extension MastodonServerRulesViewModel {
|
|||
|
||||
var snapshot = NSDiffableDataSourceSnapshot<ServerRuleSection, ServerRuleItem>()
|
||||
snapshot.appendSections([.rules])
|
||||
let ruleItems: [ServerRuleItem] = rules.enumerated().map { i, rule in
|
||||
let ruleContext = ServerRuleItem.RuleContext(index: i, rule: rule)
|
||||
return ServerRuleItem.rule(ruleContext)
|
||||
}
|
||||
let ruleItems: [ServerRuleItem] = rules.enumerated().map { index, rule in return ServerRuleItem.rule(index: index, rule: rule) }
|
||||
snapshot.appendItems(ruleItems, toSection: .rules)
|
||||
diffableDataSource?.apply(snapshot, animatingDifferences: false)
|
||||
}
|
||||
|
|
|
@ -9,12 +9,5 @@ import Foundation
|
|||
import MastodonSDK
|
||||
|
||||
enum ServerRuleItem: Hashable {
|
||||
case rule(RuleContext)
|
||||
}
|
||||
|
||||
extension ServerRuleItem {
|
||||
struct RuleContext: Hashable {
|
||||
let index: Int
|
||||
let rule: Mastodon.Entity.Instance.Rule
|
||||
}
|
||||
case rule(index: Int, rule: Mastodon.Entity.Instance.Rule)
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ extension ServerRuleSection {
|
|||
) -> UITableViewDiffableDataSource<ServerRuleSection, ServerRuleItem> {
|
||||
return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item in
|
||||
switch item {
|
||||
case .rule(let ruleContext):
|
||||
case .rule(let index, let rule):
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ServerRulesTableViewCell.self), for: indexPath) as! ServerRulesTableViewCell
|
||||
cell.indexImageView.image = UIImage(systemName: "\(ruleContext.index + 1).circle") ?? UIImage(systemName: "questionmark.circle")
|
||||
cell.indexImageView.image = UIImage(systemName: "\(index + 1).circle") ?? UIImage(systemName: "questionmark.circle")
|
||||
cell.indexImageView.tintColor = Asset.Colors.Brand.lightBlurple.color
|
||||
cell.ruleLabel.text = ruleContext.rule.text
|
||||
cell.ruleLabel.text = rule.text
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,17 +8,51 @@ protocol InstanceRulesViewControllerDelegate: AnyObject {
|
|||
}
|
||||
|
||||
class InstanceRulesViewController: UIViewController {
|
||||
|
||||
weak var delegate: InstanceRulesViewControllerDelegate?
|
||||
let tableView: UITableView
|
||||
var dataSource: UITableViewDiffableDataSource<ServerRuleSection, ServerRuleItem>?
|
||||
|
||||
var sections: [ServerRuleSection] = []
|
||||
|
||||
init() {
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
tableView = UITableView(frame: .zero, style: .insetGrouped)
|
||||
tableView.translatesAutoresizingMaskIntoConstraints = false
|
||||
tableView.register(ServerRulesTableViewCell.self, forCellReuseIdentifier: ServerRulesTableViewCell.reuseIdentifier)
|
||||
|
||||
view.backgroundColor = .blue
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
view.addSubview(tableView)
|
||||
|
||||
let dataSource = ServerRuleSection.tableViewDiffableDataSource(tableView: tableView)
|
||||
|
||||
tableView.dataSource = dataSource
|
||||
self.dataSource = dataSource
|
||||
|
||||
setupConstraints()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
private func setupConstraints() {
|
||||
let constraints = [
|
||||
tableView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
view.trailingAnchor.constraint(equalTo: tableView.trailingAnchor),
|
||||
view.bottomAnchor.constraint(equalTo: tableView.bottomAnchor),
|
||||
]
|
||||
|
||||
NSLayoutConstraint.activate(constraints)
|
||||
}
|
||||
|
||||
func update(with instance: Mastodon.Entity.V2.Instance) {
|
||||
//TODO: Implement
|
||||
guard let dataSource, let rules = instance.rules, rules.isNotEmpty else { return }
|
||||
|
||||
var snapshot = NSDiffableDataSourceSnapshot<ServerRuleSection, ServerRuleItem>()
|
||||
|
||||
snapshot.appendSections([.rules])
|
||||
let ruleItems = rules.enumerated().compactMap { index, rule in ServerRuleItem.rule(index: index, rule: rule) }
|
||||
snapshot.appendItems(ruleItems, toSection: .rules)
|
||||
|
||||
dataSource.apply(snapshot)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ class ServerDetailsViewController: UIViewController {
|
|||
|
||||
pageController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)
|
||||
pageController.setViewControllers([aboutInstanceViewController], direction: .forward, animated: false)
|
||||
pageController.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
||||
|
@ -93,6 +94,11 @@ class ServerDetailsViewController: UIViewController {
|
|||
segmentedControl.leadingAnchor.constraint(equalTo: segmentedControlWrapper.leadingAnchor, constant: 16),
|
||||
segmentedControlWrapper.trailingAnchor.constraint(equalTo: segmentedControl.trailingAnchor, constant: 16),
|
||||
segmentedControlWrapper.bottomAnchor.constraint(equalTo: segmentedControl.bottomAnchor, constant: 8),
|
||||
|
||||
pageController.view.topAnchor.constraint(equalTo: containerView.topAnchor),
|
||||
pageController.view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
|
||||
containerView.trailingAnchor.constraint(equalTo: pageController.view.trailingAnchor),
|
||||
containerView.bottomAnchor.constraint(equalTo: pageController.view.bottomAnchor),
|
||||
]
|
||||
|
||||
NSLayoutConstraint.activate(constraints)
|
||||
|
|
Loading…
Reference in New Issue