From 7aaafcdc102807a32baf9c1032c134705b318ce8 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 20 Jul 2021 19:59:09 +0800 Subject: [PATCH] fix: notification badge image color issue --- .../Section/Status/NotificationSection.swift | 28 +++++++++++++------ .../NotificationStatusTableViewCell.swift | 26 ++++++++++++----- .../TableViewCell/PickServerTitleCell.swift | 2 +- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Mastodon/Diffiable/Section/Status/NotificationSection.swift b/Mastodon/Diffiable/Section/Status/NotificationSection.swift index 63e88bdd..5769c912 100644 --- a/Mastodon/Diffiable/Section/Status/NotificationSection.swift +++ b/Mastodon/Diffiable/Section/Status/NotificationSection.swift @@ -44,14 +44,26 @@ extension NotificationSection { avatarImageURL: notification.account.avatarImageURL() ) ) - cell.actionImageView.image = UIImage( - systemName: notification.notificationType.actionImageName, - withConfiguration: UIImage.SymbolConfiguration( - pointSize: 12, weight: .semibold - ) - )? - .withRenderingMode(.alwaysTemplate) - .af.imageAspectScaled(toFit: CGSize(width: 14, height: 14)) + + func createActionImage() -> UIImage? { + return UIImage( + systemName: notification.notificationType.actionImageName, + withConfiguration: UIImage.SymbolConfiguration( + pointSize: 12, weight: .semibold + ) + )? + .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 diff --git a/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift b/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift index 9c3558ea..6042c0bb 100644 --- a/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift +++ b/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift @@ -50,17 +50,18 @@ final class NotificationStatusTableViewCell: UITableViewCell, StatusCell { let imageView = FLAnimatedImageView() return imageView }() + + + let traitCollectionDidChange = PassthroughSubject() 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 }) diff --git a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerTitleCell.swift b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerTitleCell.swift index 2cfd5ec3..682ebbf3 100644 --- a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerTitleCell.swift +++ b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerTitleCell.swift @@ -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([