|
| 1 | +// |
| 2 | +// PickServerCategoriesCell.swift |
| 3 | +// Mastodon |
| 4 | +// |
| 5 | +// Created by BradGao on 2021/2/23. |
| 6 | +// |
| 7 | + |
| 8 | +//import os.log |
| 9 | +//import UIKit |
| 10 | +//import MastodonSDK |
| 11 | +// |
| 12 | +//protocol PickServerCategoriesCellDelegate: AnyObject { |
| 13 | +// func pickServerCategoriesCell(_ cell: PickServerCategoriesCell, collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) |
| 14 | +//} |
| 15 | +// |
| 16 | +//final class PickServerCategoriesCell: UITableViewCell { |
| 17 | +// |
| 18 | +// weak var delegate: PickServerCategoriesCellDelegate? |
| 19 | +// |
| 20 | +// var diffableDataSource: UICollectionViewDiffableDataSource<CategoryPickerSection, CategoryPickerItem>? |
| 21 | +// |
| 22 | +// let metricView = UIView() |
| 23 | +// |
| 24 | +// let collectionView: UICollectionView = { |
| 25 | +// let flowLayout = UICollectionViewFlowLayout() |
| 26 | +// flowLayout.scrollDirection = .horizontal |
| 27 | +// let view = ControlContainableCollectionView(frame: .zero, collectionViewLayout: flowLayout) |
| 28 | +// view.register(PickServerCategoryCollectionViewCell.self, forCellWithReuseIdentifier: String(describing: PickServerCategoryCollectionViewCell.self)) |
| 29 | +// view.backgroundColor = .clear |
| 30 | +// view.showsHorizontalScrollIndicator = false |
| 31 | +// view.showsVerticalScrollIndicator = false |
| 32 | +// view.layer.masksToBounds = false |
| 33 | +// view.translatesAutoresizingMaskIntoConstraints = false |
| 34 | +// return view |
| 35 | +// }() |
| 36 | +// |
| 37 | +// override func prepareForReuse() { |
| 38 | +// super.prepareForReuse() |
| 39 | +// |
| 40 | +// delegate = nil |
| 41 | +// } |
| 42 | +// |
| 43 | +// override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { |
| 44 | +// super.init(style: style, reuseIdentifier: reuseIdentifier) |
| 45 | +// _init() |
| 46 | +// } |
| 47 | +// |
| 48 | +// required init?(coder: NSCoder) { |
| 49 | +// super.init(coder: coder) |
| 50 | +// _init() |
| 51 | +// } |
| 52 | +//} |
| 53 | +// |
| 54 | +//extension PickServerCategoriesCell { |
| 55 | +// |
| 56 | +// private func _init() { |
| 57 | +// selectionStyle = .none |
| 58 | +// backgroundColor = Asset.Theme.Mastodon.systemGroupedBackground.color |
| 59 | +// configureMargin() |
| 60 | +// |
| 61 | +// metricView.translatesAutoresizingMaskIntoConstraints = false |
| 62 | +// contentView.addSubview(metricView) |
| 63 | +// NSLayoutConstraint.activate([ |
| 64 | +// metricView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor), |
| 65 | +// metricView.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor), |
| 66 | +// metricView.topAnchor.constraint(equalTo: contentView.topAnchor), |
| 67 | +// metricView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), |
| 68 | +// metricView.heightAnchor.constraint(equalToConstant: 80).priority(.defaultHigh), |
| 69 | +// ]) |
| 70 | +// |
| 71 | +// contentView.addSubview(collectionView) |
| 72 | +// NSLayoutConstraint.activate([ |
| 73 | +// collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), |
| 74 | +// collectionView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), |
| 75 | +// collectionView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10), |
| 76 | +// contentView.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor, constant: 20), |
| 77 | +// collectionView.heightAnchor.constraint(equalToConstant: 80).priority(.defaultHigh), |
| 78 | +// ]) |
| 79 | +// |
| 80 | +// collectionView.delegate = self |
| 81 | +// } |
| 82 | +// |
| 83 | +// override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { |
| 84 | +// super.traitCollectionDidChange(previousTraitCollection) |
| 85 | +// |
| 86 | +// configureMargin() |
| 87 | +// } |
| 88 | +// |
| 89 | +// override func layoutSubviews() { |
| 90 | +// super.layoutSubviews() |
| 91 | +// |
| 92 | +// collectionView.collectionViewLayout.invalidateLayout() |
| 93 | +// } |
| 94 | +// |
| 95 | +//} |
| 96 | +// |
| 97 | +//extension PickServerCategoriesCell { |
| 98 | +// private func configureMargin() { |
| 99 | +// switch traitCollection.horizontalSizeClass { |
| 100 | +// case .regular: |
| 101 | +// let margin = MastodonPickServerViewController.viewEdgeMargin |
| 102 | +// contentView.layoutMargins = UIEdgeInsets(top: 0, left: margin, bottom: 0, right: margin) |
| 103 | +// default: |
| 104 | +// contentView.layoutMargins = .zero |
| 105 | +// } |
| 106 | +// } |
| 107 | +//} |
| 108 | +// |
| 109 | +//// MARK: - UICollectionViewDelegateFlowLayout |
| 110 | +//extension PickServerCategoriesCell: UICollectionViewDelegateFlowLayout { |
| 111 | +// |
| 112 | +// func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| 113 | +// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: indexPath: %s", ((#file as NSString).lastPathComponent), #line, #function, indexPath.debugDescription) |
| 114 | +// collectionView.selectItem(at: indexPath, animated: true, scrollPosition: .centeredHorizontally) |
| 115 | +// delegate?.pickServerCategoriesCell(self, collectionView: collectionView, didSelectItemAt: indexPath) |
| 116 | +// } |
| 117 | +// |
| 118 | +// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { |
| 119 | +// layoutIfNeeded() |
| 120 | +// return UIEdgeInsets(top: 0, left: metricView.frame.minX - collectionView.frame.minX, bottom: 0, right: collectionView.frame.maxX - metricView.frame.maxX) |
| 121 | +// } |
| 122 | +// |
| 123 | +// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { |
| 124 | +// return 16 |
| 125 | +// } |
| 126 | +// |
| 127 | +// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { |
| 128 | +// return CGSize(width: 60, height: 80) |
| 129 | +// } |
| 130 | +// |
| 131 | +//} |
| 132 | +// |
| 133 | +//extension PickServerCategoriesCell { |
| 134 | +// |
| 135 | +// override func accessibilityElementCount() -> Int { |
| 136 | +// guard let diffableDataSource = diffableDataSource else { return 0 } |
| 137 | +// return diffableDataSource.snapshot().itemIdentifiers.count |
| 138 | +// } |
| 139 | +// |
| 140 | +// override func accessibilityElement(at index: Int) -> Any? { |
| 141 | +// guard let item = collectionView.cellForItem(at: IndexPath(item: index, section: 0)) else { return nil } |
| 142 | +// return item |
| 143 | +// } |
| 144 | +// |
| 145 | +//} |
0 commit comments