fix: ProfileCardView layout initial setup failure issue
This commit is contained in:
parent
063119337d
commit
1d96609003
|
@ -109,7 +109,7 @@
|
||||||
<key>MastodonIntent.xcscheme_^#shared#^_</key>
|
<key>MastodonIntent.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>33</integer>
|
<integer>23</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>MastodonIntents.xcscheme_^#shared#^_</key>
|
<key>MastodonIntents.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
|
@ -124,12 +124,12 @@
|
||||||
<key>NotificationService.xcscheme_^#shared#^_</key>
|
<key>NotificationService.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>32</integer>
|
<integer>22</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
|
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>34</integer>
|
<integer>24</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
<key>SuppressBuildableAutocreation</key>
|
<key>SuppressBuildableAutocreation</key>
|
||||||
|
|
|
@ -52,13 +52,16 @@ extension DiscoverySection {
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ProfileCardTableViewCell.self), for: indexPath) as! ProfileCardTableViewCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ProfileCardTableViewCell.self), for: indexPath) as! ProfileCardTableViewCell
|
||||||
context.managedObjectContext.performAndWait {
|
context.managedObjectContext.performAndWait {
|
||||||
guard let user = record.object(in: context.managedObjectContext) else { return }
|
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
|
context.authenticationService.activeMastodonAuthentication
|
||||||
.map { $0?.user }
|
.map { $0?.user }
|
||||||
.assign(to: \.me, on: cell.profileCardView.viewModel.relationshipViewModel)
|
.assign(to: \.me, on: cell.profileCardView.viewModel.relationshipViewModel)
|
||||||
.store(in: &cell.disposeBag)
|
.store(in: &cell.disposeBag)
|
||||||
cell.delegate = configuration.profileCardTableViewCellDelegate
|
|
||||||
return cell
|
return cell
|
||||||
case .bottomLoader:
|
case .bottomLoader:
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
||||||
|
|
|
@ -46,6 +46,8 @@ public final class ProfileCardView: UIView {
|
||||||
// author username
|
// author username
|
||||||
public let authorUsernameLabel = MetaLabel(style: .profileCardUsername)
|
public let authorUsernameLabel = MetaLabel(style: .profileCardUsername)
|
||||||
|
|
||||||
|
// bio
|
||||||
|
let bioMetaTextAdaptiveMarginContainerView = AdaptiveMarginContainerView()
|
||||||
let bioMetaText: MetaText = {
|
let bioMetaText: MetaText = {
|
||||||
let metaText = MetaText()
|
let metaText = MetaText()
|
||||||
metaText.textView.backgroundColor = .clear
|
metaText.textView.backgroundColor = .clear
|
||||||
|
@ -78,6 +80,7 @@ public final class ProfileCardView: UIView {
|
||||||
return metaText
|
return metaText
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
let infoContainerAdaptiveMarginContainerView = AdaptiveMarginContainerView()
|
||||||
let infoContainer = UIStackView()
|
let infoContainer = UIStackView()
|
||||||
|
|
||||||
let statusDashboardView = ProfileStatusDashboardView()
|
let statusDashboardView = ProfileStatusDashboardView()
|
||||||
|
@ -194,34 +197,36 @@ extension ProfileCardView {
|
||||||
// authorInfoContainer: V - [ authorNameLabel | authorUsernameLabel ]
|
// authorInfoContainer: V - [ authorNameLabel | authorUsernameLabel ]
|
||||||
let authorInfoContainer = UIStackView()
|
let authorInfoContainer = UIStackView()
|
||||||
authorInfoContainer.axis = .vertical
|
authorInfoContainer.axis = .vertical
|
||||||
authorInfoContainer.spacing = 2
|
// authorInfoContainer.spacing = 2
|
||||||
authorContainer.addArrangedSubview(authorInfoContainer)
|
authorContainer.addArrangedSubview(authorInfoContainer)
|
||||||
|
|
||||||
authorInfoContainer.addArrangedSubview(authorNameLabel)
|
authorInfoContainer.addArrangedSubview(authorNameLabel)
|
||||||
authorInfoContainer.addArrangedSubview(authorUsernameLabel)
|
authorInfoContainer.addArrangedSubview(authorUsernameLabel)
|
||||||
|
|
||||||
// bioMetaText
|
// bioMetaText
|
||||||
let bioMetaTextAdaptiveMarginContainerView = AdaptiveMarginContainerView()
|
|
||||||
bioMetaTextAdaptiveMarginContainerView.contentView = bioMetaText.textView
|
bioMetaTextAdaptiveMarginContainerView.contentView = bioMetaText.textView
|
||||||
bioMetaTextAdaptiveMarginContainerView.margin = ProfileCardView.contentMargin
|
bioMetaTextAdaptiveMarginContainerView.margin = ProfileCardView.contentMargin
|
||||||
bioMetaText.textView.setContentHuggingPriority(.required - 1, for: .vertical)
|
bioMetaText.textView.setContentHuggingPriority(.required - 1, for: .vertical)
|
||||||
bioMetaText.textView.setContentCompressionResistancePriority(.required - 1, for: .vertical)
|
bioMetaText.textView.setContentCompressionResistancePriority(.required - 1, for: .vertical)
|
||||||
container.addArrangedSubview(bioMetaTextAdaptiveMarginContainerView)
|
container.addArrangedSubview(bioMetaTextAdaptiveMarginContainerView)
|
||||||
container.setCustomSpacing(16, after: bioMetaTextAdaptiveMarginContainerView)
|
container.setCustomSpacing(16, after: bioMetaTextAdaptiveMarginContainerView)
|
||||||
|
|
||||||
// infoContainer: H - [ statusDashboardView | (spacer) | relationshipActionButton ]
|
// infoContainer: H - [ statusDashboardView | (spacer) | relationshipActionButton ]
|
||||||
infoContainer.axis = .horizontal
|
infoContainer.axis = .horizontal
|
||||||
infoContainer.spacing = 8
|
infoContainer.spacing = 8
|
||||||
let infoContainerAdaptiveMarginContainerView = AdaptiveMarginContainerView()
|
|
||||||
infoContainerAdaptiveMarginContainerView.contentView = infoContainer
|
infoContainerAdaptiveMarginContainerView.contentView = infoContainer
|
||||||
infoContainerAdaptiveMarginContainerView.margin = ProfileCardView.contentMargin
|
infoContainerAdaptiveMarginContainerView.margin = ProfileCardView.contentMargin
|
||||||
container.addArrangedSubview(infoContainerAdaptiveMarginContainerView)
|
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
|
relationshipActionButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
relationshipActionButtonShadowContainer.addSubview(relationshipActionButton)
|
relationshipActionButtonShadowContainer.addSubview(relationshipActionButton)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
@ -229,15 +234,15 @@ extension ProfileCardView {
|
||||||
relationshipActionButton.leadingAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.leadingAnchor),
|
relationshipActionButton.leadingAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.leadingAnchor),
|
||||||
relationshipActionButton.trailingAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.trailingAnchor),
|
relationshipActionButton.trailingAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.trailingAnchor),
|
||||||
relationshipActionButton.bottomAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.bottomAnchor),
|
relationshipActionButton.bottomAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.bottomAnchor),
|
||||||
relationshipActionButton.widthAnchor.constraint(greaterThanOrEqualToConstant: ProfileCardView.friendshipActionButtonSize.width).priority(.required - 1),
|
relationshipActionButtonShadowContainer.widthAnchor.constraint(greaterThanOrEqualToConstant: ProfileCardView.friendshipActionButtonSize.width).priority(.required - 1),
|
||||||
relationshipActionButton.heightAnchor.constraint(equalToConstant: ProfileCardView.friendshipActionButtonSize.height).priority(.required - 2),
|
relationshipActionButtonShadowContainer.heightAnchor.constraint(equalToConstant: ProfileCardView.friendshipActionButtonSize.height).priority(.required - 1),
|
||||||
])
|
])
|
||||||
|
|
||||||
let bottomPadding = UIView()
|
let bottomPadding = UIView()
|
||||||
bottomPadding.translatesAutoresizingMaskIntoConstraints = false
|
bottomPadding.translatesAutoresizingMaskIntoConstraints = false
|
||||||
container.addArrangedSubview(bottomPadding)
|
container.addArrangedSubview(bottomPadding)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
bottomPadding.heightAnchor.constraint(equalToConstant: 16)
|
bottomPadding.heightAnchor.constraint(equalToConstant: 16).priority(.required - 10),
|
||||||
])
|
])
|
||||||
|
|
||||||
relationshipActionButton.addTarget(self, action: #selector(ProfileCardView.relationshipActionButtonDidPressed(_:)), for: .touchUpInside)
|
relationshipActionButton.addTarget(self, action: #selector(ProfileCardView.relationshipActionButtonDidPressed(_:)), for: .touchUpInside)
|
||||||
|
@ -257,6 +262,14 @@ extension ProfileCardView {
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
private func updateInfoContainerLayout() {
|
||||||
let isCompactAdaptive = bounds.width < 350
|
let isCompactAdaptive = bounds.width < 350
|
||||||
infoContainer.axis = isCompactAdaptive ? .vertical : .horizontal
|
infoContainer.axis = isCompactAdaptive ? .vertical : .horizontal
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
// Created by MainasuK on 2022-4-14.
|
// Created by MainasuK on 2022-4-14.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import os.log
|
||||||
import UIKit
|
import UIKit
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
|
@ -14,9 +15,13 @@ public protocol ProfileCardTableViewCellDelegate: AnyObject {
|
||||||
|
|
||||||
public final class ProfileCardTableViewCell: UITableViewCell {
|
public final class ProfileCardTableViewCell: UITableViewCell {
|
||||||
|
|
||||||
|
let logger = Logger(subsystem: "ProfileCardTableViewCell", category: "Cell")
|
||||||
|
|
||||||
public weak var delegate: ProfileCardTableViewCellDelegate?
|
public weak var delegate: ProfileCardTableViewCellDelegate?
|
||||||
public var disposeBag = Set<AnyCancellable>()
|
public var disposeBag = Set<AnyCancellable>()
|
||||||
|
|
||||||
|
public let shadowBackgroundContainer = ShadowBackgroundContainer()
|
||||||
|
|
||||||
public let profileCardView: ProfileCardView = {
|
public let profileCardView: ProfileCardView = {
|
||||||
let profileCardView = ProfileCardView()
|
let profileCardView = ProfileCardView()
|
||||||
profileCardView.layer.masksToBounds = true
|
profileCardView.layer.masksToBounds = true
|
||||||
|
@ -49,15 +54,14 @@ extension ProfileCardTableViewCell {
|
||||||
private func _init() {
|
private func _init() {
|
||||||
selectionStyle = .none
|
selectionStyle = .none
|
||||||
|
|
||||||
let shadowBackgroundContainer = ShadowBackgroundContainer()
|
|
||||||
shadowBackgroundContainer.cornerRadius = 6
|
shadowBackgroundContainer.cornerRadius = 6
|
||||||
shadowBackgroundContainer.translatesAutoresizingMaskIntoConstraints = false
|
shadowBackgroundContainer.translatesAutoresizingMaskIntoConstraints = false
|
||||||
contentView.addSubview(shadowBackgroundContainer)
|
contentView.addSubview(shadowBackgroundContainer)
|
||||||
NSLayoutConstraint.activate([
|
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.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor),
|
||||||
shadowBackgroundContainer.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor),
|
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
|
profileCardView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
Loading…
Reference in New Issue