mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01:00 +00:00
Estimate more cell heights
This commit is contained in:
parent
33494b9f76
commit
6dd991f086
5 changed files with 78 additions and 2 deletions
|
@ -34,8 +34,21 @@ extension CollectionItem {
|
||||||
identification: identification,
|
identification: identification,
|
||||||
status: status,
|
status: status,
|
||||||
configuration: configuration)
|
configuration: configuration)
|
||||||
default:
|
case let .account(account):
|
||||||
return UITableView.automaticDimension
|
return AccountView.estimatedHeight(width: width, account: account)
|
||||||
|
case .loadMore:
|
||||||
|
return LoadMoreView.estimatedHeight
|
||||||
|
case let .notification(notification, configuration):
|
||||||
|
return NotificationView.estimatedHeight(
|
||||||
|
width: width,
|
||||||
|
identification: identification,
|
||||||
|
notification: notification,
|
||||||
|
configuration: configuration)
|
||||||
|
case let .conversation(conversation):
|
||||||
|
return ConversationView.estimatedHeight(
|
||||||
|
width: width,
|
||||||
|
identification: identification,
|
||||||
|
conversation: conversation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
import Kingfisher
|
import Kingfisher
|
||||||
|
import Mastodon
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
final class AccountView: UIView {
|
final class AccountView: UIView {
|
||||||
|
@ -26,6 +27,16 @@ final class AccountView: UIView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension AccountView {
|
||||||
|
static func estimatedHeight(width: CGFloat, account: Account) -> CGFloat {
|
||||||
|
.defaultSpacing * 2
|
||||||
|
+ .compactSpacing * 2
|
||||||
|
+ account.displayName.height(width: width, font: .preferredFont(forTextStyle: .headline))
|
||||||
|
+ account.acct.height(width: width, font: .preferredFont(forTextStyle: .subheadline))
|
||||||
|
+ account.note.attributed.string.height(width: width, font: .preferredFont(forTextStyle: .callout))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension AccountView: UIContentView {
|
extension AccountView: UIContentView {
|
||||||
var configuration: UIContentConfiguration {
|
var configuration: UIContentConfiguration {
|
||||||
get { accountConfiguration }
|
get { accountConfiguration }
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
|
import Mastodon
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import ViewModels
|
||||||
|
|
||||||
final class ConversationView: UIView {
|
final class ConversationView: UIView {
|
||||||
let avatarsView = ConversationAvatarsView()
|
let avatarsView = ConversationAvatarsView()
|
||||||
|
@ -24,6 +26,24 @@ final class ConversationView: UIView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension ConversationView {
|
||||||
|
static func estimatedHeight(width: CGFloat,
|
||||||
|
identification: Identification,
|
||||||
|
conversation: Conversation) -> CGFloat {
|
||||||
|
guard let status = conversation.lastStatus else { return UITableView.automaticDimension }
|
||||||
|
|
||||||
|
let bodyWidth = width - .defaultSpacing - .avatarDimension
|
||||||
|
|
||||||
|
return .defaultSpacing * 2
|
||||||
|
+ UIFont.preferredFont(forTextStyle: .headline).lineHeight
|
||||||
|
+ StatusBodyView.estimatedHeight(
|
||||||
|
width: bodyWidth,
|
||||||
|
identification: identification,
|
||||||
|
status: status,
|
||||||
|
configuration: .default)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension ConversationView: UIContentView {
|
extension ConversationView: UIContentView {
|
||||||
var configuration: UIContentConfiguration {
|
var configuration: UIContentConfiguration {
|
||||||
get { conversationConfiguration }
|
get { conversationConfiguration }
|
||||||
|
|
|
@ -28,6 +28,10 @@ final class LoadMoreView: UIView {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension LoadMoreView {
|
extension LoadMoreView {
|
||||||
|
static var estimatedHeight: CGFloat {
|
||||||
|
.defaultSpacing * 2 + UIFont.preferredFont(forTextStyle: .title2).lineHeight
|
||||||
|
}
|
||||||
|
|
||||||
func directionChanged(up: Bool) {
|
func directionChanged(up: Bool) {
|
||||||
guard !loadMoreConfiguration.viewModel.loading else { return }
|
guard !loadMoreConfiguration.viewModel.loading else { return }
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import Kingfisher
|
import Kingfisher
|
||||||
import Mastodon
|
import Mastodon
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import ViewModels
|
||||||
|
|
||||||
final class NotificationView: UIView {
|
final class NotificationView: UIView {
|
||||||
private let iconImageView = UIImageView()
|
private let iconImageView = UIImageView()
|
||||||
|
@ -29,6 +30,33 @@ final class NotificationView: UIView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension NotificationView {
|
||||||
|
static func estimatedHeight(width: CGFloat,
|
||||||
|
identification: Identification,
|
||||||
|
notification: MastodonNotification,
|
||||||
|
configuration: CollectionItem.StatusConfiguration?) -> CGFloat {
|
||||||
|
let bodyWidth = width - .defaultSpacing - .avatarDimension
|
||||||
|
|
||||||
|
var height = CGFloat.defaultSpacing * 2
|
||||||
|
+ UIFont.preferredFont(forTextStyle: .headline).lineHeight
|
||||||
|
+ .compactSpacing
|
||||||
|
|
||||||
|
if let status = notification.status {
|
||||||
|
height += StatusBodyView.estimatedHeight(
|
||||||
|
width: bodyWidth,
|
||||||
|
identification: identification,
|
||||||
|
status: status,
|
||||||
|
configuration: configuration ?? .default)
|
||||||
|
} else {
|
||||||
|
height += UIFont.preferredFont(forTextStyle: .headline).lineHeight
|
||||||
|
+ .compactSpacing
|
||||||
|
+ UIFont.preferredFont(forTextStyle: .subheadline).lineHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
return height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension NotificationView: UIContentView {
|
extension NotificationView: UIContentView {
|
||||||
var configuration: UIContentConfiguration {
|
var configuration: UIContentConfiguration {
|
||||||
get { notificationConfiguration }
|
get { notificationConfiguration }
|
||||||
|
|
Loading…
Reference in a new issue