fix: hashtag icon in search history record cell can not adaptive update appearance issue

This commit is contained in:
CMK 2021-10-25 17:24:44 +08:00
parent eaff363243
commit 829c3f4cd2
2 changed files with 43 additions and 30 deletions

View File

@ -32,24 +32,8 @@ extension SearchHistorySection {
} }
return cell return cell
case .status: case .status:
// Should not show status in the history list
return UITableViewCell() return UITableViewCell()
// let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell
// if let status = try? dependency.context.managedObjectContext.existingObject(with: statusObjectID) as? Status {
// let activeMastodonAuthenticationBox = dependency.context.authenticationService.activeMastodonAuthenticationBox.value
// let requestUserID = activeMastodonAuthenticationBox?.userID ?? ""
// StatusSection.configure(
// cell: cell,
// tableView: tableView,
// timelineContext: .search,
// dependency: dependency,
// readableLayoutFrame: tableView.readableContentGuide.layoutFrame,
// status: status,
// requestUserID: requestUserID,
// statusItemAttribute: attribute
// )
// }
// cell.delegate = statusTableViewCellDelegate
// return cell
} // end switch } // end switch
} // end UITableViewDiffableDataSource } // end UITableViewDiffableDataSource
} // end func } // end func

View File

@ -16,7 +16,7 @@ import MastodonMeta
final class SearchResultTableViewCell: UITableViewCell { final class SearchResultTableViewCell: UITableViewCell {
let _imageView: AvatarImageView = { let avatarImageView: AvatarImageView = {
let imageView = AvatarImageView() let imageView = AvatarImageView()
imageView.tintColor = Asset.Colors.Label.primary.color imageView.tintColor = Asset.Colors.Label.primary.color
imageView.layer.cornerRadius = 4 imageView.layer.cornerRadius = 4
@ -24,6 +24,13 @@ final class SearchResultTableViewCell: UITableViewCell {
return imageView return imageView
}() }()
let hashtagImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(systemName: "number.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 34, weight: .regular))!.withRenderingMode(.alwaysTemplate)
imageView.tintColor = Asset.Colors.Label.primary.color
return imageView
}()
let _titleLabel = MetaLabel(style: .statusName) let _titleLabel = MetaLabel(style: .statusName)
let _subTitleLabel: UILabel = { let _subTitleLabel: UILabel = {
@ -43,7 +50,8 @@ final class SearchResultTableViewCell: UITableViewCell {
override func prepareForReuse() { override func prepareForReuse() {
super.prepareForReuse() super.prepareForReuse()
_imageView.af.cancelImageRequest() avatarImageView.af.cancelImageRequest()
setDisplayAvatarImage()
} }
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
@ -74,11 +82,20 @@ extension SearchResultTableViewCell {
containerStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) containerStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
]) ])
_imageView.translatesAutoresizingMaskIntoConstraints = false avatarImageView.translatesAutoresizingMaskIntoConstraints = false
containerStackView.addArrangedSubview(_imageView) containerStackView.addArrangedSubview(avatarImageView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
_imageView.widthAnchor.constraint(equalToConstant: 42).priority(.required - 1), avatarImageView.widthAnchor.constraint(equalToConstant: 42).priority(.required - 1),
_imageView.heightAnchor.constraint(equalToConstant: 42).priority(.required - 1), avatarImageView.heightAnchor.constraint(equalToConstant: 42).priority(.required - 1),
])
hashtagImageView.translatesAutoresizingMaskIntoConstraints = false
containerStackView.addSubview(hashtagImageView)
NSLayoutConstraint.activate([
hashtagImageView.centerXAnchor.constraint(equalTo: avatarImageView.centerXAnchor),
hashtagImageView.centerYAnchor.constraint(equalTo: avatarImageView.centerYAnchor),
hashtagImageView.widthAnchor.constraint(equalToConstant: 42).priority(.required - 1),
hashtagImageView.heightAnchor.constraint(equalToConstant: 42).priority(.required - 1),
]) ])
let textStackView = UIStackView() let textStackView = UIStackView()
@ -107,7 +124,9 @@ extension SearchResultTableViewCell {
_titleLabel.isUserInteractionEnabled = false _titleLabel.isUserInteractionEnabled = false
_subTitleLabel.isUserInteractionEnabled = false _subTitleLabel.isUserInteractionEnabled = false
_imageView.isUserInteractionEnabled = false avatarImageView.isUserInteractionEnabled = false
setDisplayAvatarImage()
} }
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
@ -182,8 +201,7 @@ extension SearchResultTableViewCell {
func config(with tag: Mastodon.Entity.Tag) { func config(with tag: Mastodon.Entity.Tag) {
configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: nil)) configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: nil))
let image = UIImage(systemName: "number.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 34, weight: .regular))!.withRenderingMode(.alwaysTemplate) setDisplayHashtagImage()
_imageView.image = image
let metaContent = PlaintextMetaContent(string: "#" + tag.name) let metaContent = PlaintextMetaContent(string: "#" + tag.name)
_titleLabel.configure(content: metaContent) _titleLabel.configure(content: metaContent)
guard let histories = tag.history else { guard let histories = tag.history else {
@ -198,8 +216,7 @@ extension SearchResultTableViewCell {
func config(with tag: Tag) { func config(with tag: Tag) {
configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: nil)) configure(with: AvatarConfigurableViewConfiguration(avatarImageURL: nil))
let image = UIImage(systemName: "number.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 34, weight: .regular))!.withRenderingMode(.alwaysTemplate) setDisplayHashtagImage()
_imageView.image = image
let metaContent = PlaintextMetaContent(string: "#" + tag.name) let metaContent = PlaintextMetaContent(string: "#" + tag.name)
_titleLabel.configure(content: metaContent) _titleLabel.configure(content: metaContent)
guard let histories = tag.histories?.sorted(by: { guard let histories = tag.histories?.sorted(by: {
@ -215,11 +232,23 @@ extension SearchResultTableViewCell {
} }
} }
extension SearchResultTableViewCell {
func setDisplayAvatarImage() {
avatarImageView.alpha = 1
hashtagImageView.alpha = 0
}
func setDisplayHashtagImage() {
avatarImageView.alpha = 0
hashtagImageView.alpha = 1
}
}
// MARK: - AvatarStackedImageView // MARK: - AvatarStackedImageView
extension SearchResultTableViewCell: AvatarConfigurableView { extension SearchResultTableViewCell: AvatarConfigurableView {
static var configurableAvatarImageSize: CGSize { CGSize(width: 42, height: 42) } static var configurableAvatarImageSize: CGSize { CGSize(width: 42, height: 42) }
static var configurableAvatarImageCornerRadius: CGFloat { 4 } static var configurableAvatarImageCornerRadius: CGFloat { 4 }
var configurableAvatarImageView: FLAnimatedImageView? { _imageView } var configurableAvatarImageView: FLAnimatedImageView? { avatarImageView }
} }
#if canImport(SwiftUI) && DEBUG #if canImport(SwiftUI) && DEBUG
@ -231,7 +260,7 @@ struct SearchResultTableViewCell_Previews: PreviewProvider {
UIViewPreview { UIViewPreview {
let cell = SearchResultTableViewCell() let cell = SearchResultTableViewCell()
cell.backgroundColor = .white cell.backgroundColor = .white
cell._imageView.image = UIImage(systemName: "number.circle.fill") cell.setDisplayHashtagImage()
cell._titleLabel.text = "Electronic Frontier Foundation" cell._titleLabel.text = "Electronic Frontier Foundation"
cell._subTitleLabel.text = "@eff@mastodon.social" cell._subTitleLabel.text = "@eff@mastodon.social"
return cell return cell