1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-22 22:28:35 +01:00

fix: ProfileCardView layout initial setup failure issue

This commit is contained in:
CMK 2022-04-19 20:57:21 +08:00
parent 063119337d
commit 1d96609003
5 changed files with 71 additions and 21 deletions

View File

@ -109,7 +109,7 @@
<key>MastodonIntent.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>33</integer>
<integer>23</integer>
</dict>
<key>MastodonIntents.xcscheme_^#shared#^_</key>
<dict>
@ -124,12 +124,12 @@
<key>NotificationService.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>32</integer>
<integer>22</integer>
</dict>
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>34</integer>
<integer>24</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>

View File

@ -52,13 +52,16 @@ extension DiscoverySection {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ProfileCardTableViewCell.self), for: indexPath) as! ProfileCardTableViewCell
context.managedObjectContext.performAndWait {
guard let user = record.object(in: context.managedObjectContext) else { return }
cell.profileCardView.configure(user: user)
cell.configure(
tableView: tableView,
user: user,
profileCardTableViewCellDelegate: configuration.profileCardTableViewCellDelegate
)
}
context.authenticationService.activeMastodonAuthentication
.map { $0?.user }
.assign(to: \.me, on: cell.profileCardView.viewModel.relationshipViewModel)
.store(in: &cell.disposeBag)
cell.delegate = configuration.profileCardTableViewCellDelegate
return cell
case .bottomLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell

View File

@ -46,6 +46,8 @@ public final class ProfileCardView: UIView {
// author username
public let authorUsernameLabel = MetaLabel(style: .profileCardUsername)
// bio
let bioMetaTextAdaptiveMarginContainerView = AdaptiveMarginContainerView()
let bioMetaText: MetaText = {
let metaText = MetaText()
metaText.textView.backgroundColor = .clear
@ -78,6 +80,7 @@ public final class ProfileCardView: UIView {
return metaText
}()
let infoContainerAdaptiveMarginContainerView = AdaptiveMarginContainerView()
let infoContainer = UIStackView()
let statusDashboardView = ProfileStatusDashboardView()
@ -194,34 +197,36 @@ extension ProfileCardView {
// authorInfoContainer: V - [ authorNameLabel | authorUsernameLabel ]
let authorInfoContainer = UIStackView()
authorInfoContainer.axis = .vertical
authorInfoContainer.spacing = 2
// authorInfoContainer.spacing = 2
authorContainer.addArrangedSubview(authorInfoContainer)
authorInfoContainer.addArrangedSubview(authorNameLabel)
authorInfoContainer.addArrangedSubview(authorUsernameLabel)
// bioMetaText
let bioMetaTextAdaptiveMarginContainerView = AdaptiveMarginContainerView()
bioMetaTextAdaptiveMarginContainerView.contentView = bioMetaText.textView
bioMetaTextAdaptiveMarginContainerView.margin = ProfileCardView.contentMargin
bioMetaText.textView.setContentHuggingPriority(.required - 1, for: .vertical)
bioMetaText.textView.setContentCompressionResistancePriority(.required - 1, for: .vertical)
container.addArrangedSubview(bioMetaTextAdaptiveMarginContainerView)
container.setCustomSpacing(16, after: bioMetaTextAdaptiveMarginContainerView)
// infoContainer: H - [ statusDashboardView | (spacer) | relationshipActionButton ]
infoContainer.axis = .horizontal
infoContainer.spacing = 8
let infoContainerAdaptiveMarginContainerView = AdaptiveMarginContainerView()
infoContainerAdaptiveMarginContainerView.contentView = infoContainer
infoContainerAdaptiveMarginContainerView.margin = ProfileCardView.contentMargin
container.addArrangedSubview(infoContainerAdaptiveMarginContainerView)
infoContainer.addArrangedSubview(statusDashboardView)
infoContainer.addArrangedSubview(UIView())
let relationshipActionButtonShadowContainer = ShadowBackgroundContainer()
infoContainer.addArrangedSubview(relationshipActionButtonShadowContainer)
updateInfoContainerLayout()
infoContainer.addArrangedSubview(statusDashboardView)
let infoContainerSpacer = UIView()
infoContainer.addArrangedSubview(UIView())
infoContainerSpacer.setContentHuggingPriority(.defaultLow - 100, for: .vertical)
infoContainerSpacer.setContentHuggingPriority(.defaultLow - 100, for: .horizontal)
let relationshipActionButtonShadowContainer = ShadowBackgroundContainer()
relationshipActionButtonShadowContainer.translatesAutoresizingMaskIntoConstraints = false
infoContainer.addArrangedSubview(relationshipActionButtonShadowContainer)
relationshipActionButton.translatesAutoresizingMaskIntoConstraints = false
relationshipActionButtonShadowContainer.addSubview(relationshipActionButton)
NSLayoutConstraint.activate([
@ -229,15 +234,15 @@ extension ProfileCardView {
relationshipActionButton.leadingAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.leadingAnchor),
relationshipActionButton.trailingAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.trailingAnchor),
relationshipActionButton.bottomAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.bottomAnchor),
relationshipActionButton.widthAnchor.constraint(greaterThanOrEqualToConstant: ProfileCardView.friendshipActionButtonSize.width).priority(.required - 1),
relationshipActionButton.heightAnchor.constraint(equalToConstant: ProfileCardView.friendshipActionButtonSize.height).priority(.required - 2),
relationshipActionButtonShadowContainer.widthAnchor.constraint(greaterThanOrEqualToConstant: ProfileCardView.friendshipActionButtonSize.width).priority(.required - 1),
relationshipActionButtonShadowContainer.heightAnchor.constraint(equalToConstant: ProfileCardView.friendshipActionButtonSize.height).priority(.required - 1),
])
let bottomPadding = UIView()
bottomPadding.translatesAutoresizingMaskIntoConstraints = false
container.addArrangedSubview(bottomPadding)
NSLayoutConstraint.activate([
bottomPadding.heightAnchor.constraint(equalToConstant: 16)
bottomPadding.heightAnchor.constraint(equalToConstant: 16).priority(.required - 10),
])
relationshipActionButton.addTarget(self, action: #selector(ProfileCardView.relationshipActionButtonDidPressed(_:)), for: .touchUpInside)
@ -257,6 +262,14 @@ extension ProfileCardView {
}
extension ProfileCardView {
public func setupLayoutFrame(_ rect: CGRect) {
frame.size.width = rect.width
bioMetaTextAdaptiveMarginContainerView.frame.size.width = frame.width
bioMetaTextAdaptiveMarginContainerView.contentView?.frame.size.width = frame.width - 2 * bioMetaTextAdaptiveMarginContainerView.margin
infoContainerAdaptiveMarginContainerView.frame.size.width = frame.width
infoContainerAdaptiveMarginContainerView.contentView?.frame.size.width = frame.width - 2 * infoContainerAdaptiveMarginContainerView.margin
}
private func updateInfoContainerLayout() {
let isCompactAdaptive = bounds.width < 350
infoContainer.axis = isCompactAdaptive ? .vertical : .horizontal

View File

@ -0,0 +1,30 @@
//
// ProfileCardTableViewCell+Configuration.swift
//
//
// Created by MainasuK on 2022-4-19.
//
import UIKit
import CoreDataStack
extension ProfileCardTableViewCell {
public func configure(
tableView: UITableView,
user: MastodonUser,
profileCardTableViewCellDelegate: ProfileCardTableViewCellDelegate?
) {
if profileCardView.frame == .zero {
// set content view width
assert(layoutMarginsGuide.layoutFrame.width > .zero)
shadowBackgroundContainer.frame.size.width = layoutMarginsGuide.layoutFrame.width
profileCardView.setupLayoutFrame(layoutMarginsGuide.layoutFrame)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): did layout for new cell")
}
profileCardView.configure(user: user)
delegate = profileCardTableViewCellDelegate
}
}

View File

@ -5,6 +5,7 @@
// Created by MainasuK on 2022-4-14.
//
import os.log
import UIKit
import Combine
@ -14,9 +15,13 @@ public protocol ProfileCardTableViewCellDelegate: AnyObject {
public final class ProfileCardTableViewCell: UITableViewCell {
let logger = Logger(subsystem: "ProfileCardTableViewCell", category: "Cell")
public weak var delegate: ProfileCardTableViewCellDelegate?
public var disposeBag = Set<AnyCancellable>()
public let shadowBackgroundContainer = ShadowBackgroundContainer()
public let profileCardView: ProfileCardView = {
let profileCardView = ProfileCardView()
profileCardView.layer.masksToBounds = true
@ -49,15 +54,14 @@ extension ProfileCardTableViewCell {
private func _init() {
selectionStyle = .none
let shadowBackgroundContainer = ShadowBackgroundContainer()
shadowBackgroundContainer.cornerRadius = 6
shadowBackgroundContainer.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(shadowBackgroundContainer)
NSLayoutConstraint.activate([
shadowBackgroundContainer.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10),
shadowBackgroundContainer.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10).priority(.required - 1),
shadowBackgroundContainer.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor),
shadowBackgroundContainer.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
contentView.bottomAnchor.constraint(equalTo: shadowBackgroundContainer.bottomAnchor, constant: 10),
contentView.bottomAnchor.constraint(equalTo: shadowBackgroundContainer.bottomAnchor, constant: 10).priority(.required - 1),
])
profileCardView.translatesAutoresizingMaskIntoConstraints = false