fix: notification badge image color issue

This commit is contained in:
CMK 2021-07-20 19:59:09 +08:00
parent 7b8500e120
commit 7aaafcdc10
3 changed files with 40 additions and 16 deletions

View File

@ -44,14 +44,26 @@ extension NotificationSection {
avatarImageURL: notification.account.avatarImageURL()
)
)
cell.actionImageView.image = UIImage(
func createActionImage() -> UIImage? {
return UIImage(
systemName: notification.notificationType.actionImageName,
withConfiguration: UIImage.SymbolConfiguration(
pointSize: 12, weight: .semibold
)
)?
.withRenderingMode(.alwaysTemplate)
.withTintColor(.systemBackground)
.af.imageAspectScaled(toFit: CGSize(width: 14, height: 14))
}
cell.actionImageView.image = createActionImage()
cell.traitCollectionDidChange
.receive(on: DispatchQueue.main)
.sink { [weak cell] in
guard let cell = cell else { return }
cell.actionImageView.image = createActionImage()
}
.store(in: &cell.disposeBag)
cell.actionImageView.backgroundColor = notification.notificationType.color

View File

@ -51,16 +51,17 @@ final class NotificationStatusTableViewCell: UITableViewCell, StatusCell {
return imageView
}()
let traitCollectionDidChange = PassthroughSubject<Void, Never>()
let actionImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .center
imageView.tintColor = Asset.Theme.Mastodon.systemBackground.color
imageView.isOpaque = true
imageView.layer.masksToBounds = true
imageView.layer.cornerRadius = NotificationStatusTableViewCell.actionImageViewSize.width * 0.5
imageView.layer.cornerCurve = .circular
imageView.layer.borderWidth = NotificationStatusTableViewCell.actionImageBorderWidth
imageView.layer.borderColor = Asset.Theme.Mastodon.systemBackground.color.cgColor
imageView.layer.shouldRasterize = true
imageView.layer.rasterizationScale = UIScreen.main.scale
return imageView
@ -197,8 +198,8 @@ extension NotificationStatusTableViewCell {
NSLayoutConstraint.activate([
actionImageView.centerYAnchor.constraint(equalTo: avatarContainer.bottomAnchor),
actionImageView.centerXAnchor.constraint(equalTo: avatarContainer.trailingAnchor),
actionImageView.widthAnchor.constraint(equalToConstant: NotificationStatusTableViewCell.actionImageViewSize.width),
actionImageView.heightAnchor.constraint(equalToConstant: NotificationStatusTableViewCell.actionImageViewSize.height),
actionImageView.widthAnchor.constraint(equalToConstant: NotificationStatusTableViewCell.actionImageViewSize.width).priority(.required - 1),
actionImageView.heightAnchor.constraint(equalTo: actionImageView.widthAnchor, multiplier: 1.0),
])
containerStackView.addArrangedSubview(contentStackView)
@ -282,14 +283,23 @@ extension NotificationStatusTableViewCell {
nameLabel.addGestureRecognizer(authorNameLabelTapGestureRecognizer)
resetSeparatorLineLayout()
setupBackgroundColor(theme: ThemeService.shared.currentTheme.value)
ThemeService.shared.currentTheme
.receive(on: DispatchQueue.main)
.sink { [weak self] theme in
guard let self = self else { return }
self.setupBackgroundColor(theme: theme)
}
.store(in: &disposeBag)
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
resetSeparatorLineLayout()
avatarImageView.layer.borderColor = Asset.Theme.Mastodon.systemBackground.color.cgColor
statusContainerView.layer.borderColor = Asset.Colors.Border.notificationStatus.color.cgColor
setupBackgroundColor(theme: ThemeService.shared.currentTheme.value)
traitCollectionDidChange.send()
}
private func configure(isFiltered: Bool) {
@ -297,12 +307,14 @@ extension NotificationStatusTableViewCell {
filteredLabel.isHidden = !isFiltered
isUserInteractionEnabled = !isFiltered
}
}
extension NotificationStatusTableViewCell {
private func setupBackgroundColor(theme: Theme) {
actionImageView.layer.borderColor = theme.systemBackgroundColor.cgColor
avatarImageView.layer.borderColor = Asset.Theme.Mastodon.systemBackground.color.cgColor
statusContainerView.layer.borderColor = Asset.Colors.Border.notificationStatus.color.cgColor
statusContainerView.backgroundColor = UIColor(dynamicProvider: { traitCollection in
return traitCollection.userInterfaceStyle == .light ? theme.systemBackgroundColor : theme.tertiarySystemGroupedBackgroundColor
})

View File

@ -35,7 +35,7 @@ extension PickServerTitleCell {
private func _init() {
selectionStyle = .none
backgroundColor = Asset.Theme.Mastodon.systemBackground.color
backgroundColor = Asset.Theme.Mastodon.systemGroupedBackground.color
contentView.addSubview(titleLabel)
NSLayoutConstraint.activate([