forked from zelo72/mastodon-ios
chore: update pan modal height dynamic
This commit is contained in:
parent
142bc91437
commit
b65e591a96
|
@ -33,6 +33,7 @@ final class AccountListViewController: UIViewController, NeedsDependency {
|
|||
|
||||
let dragIndicatorView = DragIndicatorView()
|
||||
|
||||
var hasLoaded = false
|
||||
private(set) lazy var tableView: UITableView = {
|
||||
let tableView = UITableView()
|
||||
tableView.register(AccountListTableViewCell.self, forCellReuseIdentifier: String(describing: AccountListTableViewCell.self))
|
||||
|
@ -51,11 +52,22 @@ extension AccountListViewController: PanModalPresentable {
|
|||
var showDragIndicator: Bool { false }
|
||||
|
||||
var shortFormHeight: PanModalHeight {
|
||||
return .contentHeight(300)
|
||||
func calculateHeight(of numberOfItems: Int) -> CGFloat {
|
||||
return CGFloat(numberOfItems * 60 + 64)
|
||||
}
|
||||
|
||||
if hasLoaded {
|
||||
let height = calculateHeight(of: viewModel.diffableDataSource.snapshot().numberOfItems)
|
||||
return .contentHeight(CGFloat(height))
|
||||
}
|
||||
|
||||
let count = viewModel.context.authenticationService.mastodonAuthentications.value.count + 1
|
||||
let height = calculateHeight(of: count)
|
||||
return .contentHeight(height)
|
||||
}
|
||||
|
||||
var longFormHeight: PanModalHeight {
|
||||
return .maxHeightWithTopInset(40)
|
||||
return .maxHeightWithTopInset(0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +113,9 @@ extension AccountListViewController {
|
|||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.hasLoaded = true
|
||||
self.panModalSetNeedsLayoutUpdate()
|
||||
self.panModalTransition(to: .shortForm)
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
|
|
|
@ -55,9 +55,9 @@ extension AddAccountTableViewCell {
|
|||
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
contentView.addSubview(titleLabel)
|
||||
NSLayoutConstraint.activate([
|
||||
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 19),
|
||||
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 15),
|
||||
titleLabel.leadingAnchor.constraint(equalTo: iconImageView.trailingAnchor, constant: 10),
|
||||
contentView.bottomAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 19),
|
||||
contentView.bottomAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 15),
|
||||
iconImageView.heightAnchor.constraint(equalTo: titleLabel.heightAnchor, multiplier: 1.0).priority(.required - 10),
|
||||
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
||||
])
|
||||
|
|
Loading…
Reference in New Issue