LNRoomApplySeatPanel.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // LNRoomApplySeatPanel.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/11.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNRoomApplySeatPanel: LNPopupView {
  11. private let titleLabel = UILabel()
  12. private let avatarView = UIImageView()
  13. private let nameLabel = UILabel()
  14. private let applyButton = UIButton()
  15. private weak var roomSession: LNRoomViewModel?
  16. override init(frame: CGRect) {
  17. super.init(frame: frame)
  18. setupViews()
  19. }
  20. func update(_ room: LNRoomViewModel?) {
  21. roomSession = room
  22. }
  23. required init?(coder: NSCoder) {
  24. fatalError("init(coder:) has not been implemented")
  25. }
  26. }
  27. extension LNRoomApplySeatPanel {
  28. private func setupViews() {
  29. container.backgroundColor = .fill_7
  30. let header = buildHeader()
  31. container.addSubview(header)
  32. header.snp.makeConstraints { make in
  33. make.top.horizontalEdges.equalToSuperview()
  34. make.height.equalTo(52)
  35. }
  36. avatarView.sd_setImage(with: URL(string: myUserInfo.avatar))
  37. avatarView.clipsToBounds = true
  38. avatarView.contentMode = .scaleAspectFill
  39. avatarView.layer.cornerRadius = 38
  40. avatarView.layer.borderWidth = 1
  41. avatarView.layer.borderColor = .fill
  42. container.addSubview(avatarView)
  43. avatarView.snp.makeConstraints { make in
  44. make.top.equalTo(header.snp.bottom).offset(20)
  45. make.centerX.equalToSuperview()
  46. make.width.height.equalTo(76)
  47. }
  48. nameLabel.text = myUserInfo.nickname
  49. nameLabel.font = .heading_h2
  50. nameLabel.textColor = .text_1
  51. nameLabel.textAlignment = .center
  52. container.addSubview(nameLabel)
  53. nameLabel.snp.makeConstraints { make in
  54. make.horizontalEdges.equalToSuperview()
  55. make.top.equalTo(avatarView.snp.bottom).offset(13)
  56. }
  57. applyButton.setTitle(.init(key: "A00322"), for: .normal)
  58. applyButton.setTitleColor(.text_1, for: .normal)
  59. applyButton.titleLabel?.font = .heading_h3
  60. applyButton.setBackgroundImage(.primary_8, for: .normal)
  61. applyButton.layer.cornerRadius = 23.5
  62. applyButton.clipsToBounds = true
  63. applyButton.addAction(UIAction(handler: { [weak self] _ in
  64. guard let self else { return }
  65. guard let roomSession else { return }
  66. roomSession.applySeat { [weak self] success in
  67. guard let self else { return }
  68. guard success else { return }
  69. dismiss()
  70. }
  71. }), for: .touchUpInside)
  72. container.addSubview(applyButton)
  73. applyButton.snp.makeConstraints { make in
  74. make.horizontalEdges.equalToSuperview().inset(16)
  75. make.top.equalTo(nameLabel.snp.bottom).offset(46)
  76. make.height.equalTo(47)
  77. make.bottom.equalToSuperview().offset(commonBottomInset)
  78. }
  79. }
  80. private func buildHeader() -> UIView {
  81. let header = UIView()
  82. titleLabel.font = .heading_h3
  83. titleLabel.textColor = .text_1
  84. titleLabel.text = .init(key: "A00330")
  85. header.addSubview(titleLabel)
  86. titleLabel.snp.makeConstraints { make in
  87. make.center.equalToSuperview()
  88. }
  89. return header
  90. }
  91. }