Fix separator lines (IOS-226)

Well. Configurations don't work with custom UI-elements (or I'm just stupid), that's why I had to fall back to good ol UITableViewCell with UIKit-components
This commit is contained in:
Nathan Mattes 2024-04-30 18:28:01 +02:00
parent b0a28cc514
commit 2567fbd085
3 changed files with 64 additions and 18 deletions

View File

@ -1,12 +1,58 @@
//
// MastodonLoginServerTableViewCell.swift
// Mastodon
//
// Created by Nathan Mattes on 11.11.22.
//
// Copyright © 2024 Mastodon gGmbH. All rights reserved.
import UIKit
import MastodonAsset
class MastodonLoginServerTableViewCell: UITableViewCell {
static let reuseIdentifier = "MastodonLoginServerTableViewCell"
static let reuseIdentifier = "MastodonLoginServerTableViewCell"
let separator: UIView
let titleLabel: UILabel
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
separator = UIView.separatorLine
separator.translatesAutoresizingMaskIntoConstraints = false
titleLabel = UILabel()
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.textColor = Asset.Colors.Brand.blurple.color
super.init(style: style, reuseIdentifier: reuseIdentifier)
backgroundColor = Asset.Scene.Onboarding.textFieldBackground.color
contentView.addSubview(titleLabel)
contentView.addSubview(separator)
setupConstraints()
}
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
override func prepareForReuse() {
titleLabel.text = nil
}
private func setupConstraints() {
let separatorHeight = UIView.separatorLineHeight(of: contentView)
let constraints = [
separator.heightAnchor.constraint(equalToConstant: separatorHeight),
separator.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 18),
contentView.trailingAnchor.constraint(equalTo: separator.trailingAnchor),
contentView.bottomAnchor.constraint(equalTo: separator.bottomAnchor),
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 14),
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
contentView.trailingAnchor.constraint(equalTo: titleLabel.trailingAnchor),
separator.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 13),
]
NSLayoutConstraint.activate(constraints)
}
public func configure(domain: String, separatorHidden: Bool = false) {
titleLabel.text = domain
separator.isHidden = separatorHidden
}
}

View File

@ -61,6 +61,7 @@ class MastodonLoginView: UIView {
tableView.backgroundColor = Asset.Scene.Onboarding.textFieldBackground.color
tableView.keyboardDismissMode = .onDrag
tableView.layer.cornerRadius = 10
tableView.separatorStyle = .none
super.init(frame: frame)

View File

@ -23,10 +23,6 @@ enum MastodonLoginViewSection: Hashable {
class MastodonLoginViewController: UIViewController, NeedsDependency {
enum RightBarButtonState {
case normal, disabled, loading
}
weak var delegate: MastodonLoginViewControllerDelegate?
var dataSource: UITableViewDiffableDataSource<MastodonLoginViewSection, Mastodon.Entity.Server>?
let viewModel: MastodonLoginViewModel
@ -81,16 +77,19 @@ class MastodonLoginViewController: UIViewController, NeedsDependency {
}
let server = self.viewModel.filteredServers[indexPath.row]
var configuration = cell.defaultContentConfiguration()
configuration.text = server.domain
configuration.textProperties.color = Asset.Colors.Brand.blurple.color
let isLastServer: Bool
cell.contentConfiguration = configuration
cell.backgroundColor = Asset.Scene.Onboarding.textFieldBackground.color
if let lastServer = self.viewModel.filteredServers.last {
isLastServer = (lastServer == server)
} else {
isLastServer = false
}
cell.configure(domain: server.domain, separatorHidden: isLastServer)
return cell
}
contentView.tableView.dataSource = dataSource
self.dataSource = dataSource
@ -242,7 +241,7 @@ extension MastodonLoginViewController: MastodonLoginViewModelDelegate {
snapshot.appendItems(viewModel.filteredServers)
DispatchQueue.main.async {
self.dataSource?.apply(snapshot, animatingDifferences: false)
self.dataSource?.applySnapshotUsingReloadData(snapshot)
let numberOfResults = viewModel.filteredServers.count
self.contentView.updateCorners(numberOfResults: numberOfResults)
}