Consider content height, not just char count, when collapsing posts

Closes #205
This commit is contained in:
Shadowfacts 2022-11-05 13:11:36 -04:00
parent 20986ba3f0
commit 7fe06d42ce
3 changed files with 7 additions and 5 deletions

View File

@ -11,11 +11,10 @@ import Pachyderm
extension StatusState {
func resolveFor(status: StatusMO, text: String?) {
func resolveFor(status: StatusMO, height: CGFloat) {
let longEnoughToCollapse: Bool
if Preferences.shared.collapseLongPosts,
let text = text,
text.count > 500 {
height > 500 {
longEnoughToCollapse = true
} else {
longEnoughToCollapse = false

View File

@ -182,7 +182,8 @@ class BaseStatusTableViewCell: UITableViewCell {
updateStatusIconsForPreferences(status)
if state.unknown {
state.resolveFor(status: status, text: contentTextView.text)
layoutIfNeeded()
state.resolveFor(status: status, height: contentTextView.bounds.height)
if state.collapsible! && showStatusAutomatically {
state.collapsed = false
}

View File

@ -104,7 +104,9 @@ extension StatusCollectionViewCell {
favoriteButton.isEnabled = mastodonController.loggedIn
if statusState.unknown {
statusState.resolveFor(status: status, text: contentContainer.contentTextView.text)
// layout so that we can take the content height into consideration when deciding whether to collapse
layoutIfNeeded()
statusState.resolveFor(status: status, height: contentContainer.contentTextView.bounds.height)
if statusState.collapsible! && showStatusAutomatically {
statusState.collapsed = false
}