LNFeedCommentView.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // LNFeedCommentView.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/5.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNFeedCommentView: UIView, LNFeedManagerNotify {
  11. let commentIc = UIImageView()
  12. let commentLabel = UILabel()
  13. var uiColor: UIColor = .text_4 {
  14. didSet {
  15. commentLabel.textColor = uiColor
  16. commentIc.image = .icProfileBio.withTintColor(uiColor, renderingMode: .alwaysOriginal)
  17. }
  18. }
  19. private var curId: String?
  20. override init(frame: CGRect) {
  21. super.init(frame: frame)
  22. commentIc.isUserInteractionEnabled = false
  23. commentIc.image = .icProfileBio.withTintColor(.text_4, renderingMode: .alwaysOriginal)
  24. addSubview(commentIc)
  25. commentIc.snp.makeConstraints { make in
  26. make.leading.equalToSuperview()
  27. make.verticalEdges.equalToSuperview()
  28. make.width.height.equalTo(24)
  29. }
  30. commentLabel.isUserInteractionEnabled = false
  31. commentLabel.font = .heading_h5
  32. commentLabel.textColor = .text_4
  33. addSubview(commentLabel)
  34. commentLabel.snp.makeConstraints { make in
  35. make.centerY.equalToSuperview()
  36. make.trailing.equalToSuperview()
  37. make.leading.equalTo(commentIc.snp.trailing).offset(2)
  38. }
  39. LNEventDeliver.addObserver(self)
  40. }
  41. func update(id: String, count: Int) {
  42. curId = id
  43. _updateUI(count: count)
  44. }
  45. func onFeedCommentCountChanged(id: String, count: Int) {
  46. guard id == curId else { return }
  47. _updateUI(count: count)
  48. }
  49. private func _updateUI(count: Int) {
  50. commentLabel.text = count == 0 ? .init(key: "A00302") : count.formattedAsShortNumber()
  51. }
  52. required init?(coder: NSCoder) {
  53. fatalError("init(coder:) has not been implemented")
  54. }
  55. }