LNRoomBottomMenuView.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // LNRoomBottomMenuView.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/9.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNRoomBottomMenuView: UIView {
  11. private let messageInput = LNRoomMessageInputView()
  12. private let micButton = LNRoomBottomMicView()
  13. private let giftButton = UIButton()
  14. private let menuButton = UIButton()
  15. private let joinButton = LNRoomJoinMenuView()
  16. private weak var roomSession: LNRoomViewModel?
  17. override init(frame: CGRect) {
  18. super.init(frame: frame)
  19. setupViews()
  20. LNEventDeliver.addObserver(self)
  21. }
  22. func update(_ room: LNRoomViewModel?) {
  23. roomSession = room
  24. joinButton.update(room)
  25. messageInput.update(room)
  26. micButton.update(room)
  27. onRoomSeatsChanged()
  28. }
  29. required init?(coder: NSCoder) {
  30. fatalError("init(coder:) has not been implemented")
  31. }
  32. }
  33. extension LNRoomBottomMenuView: LNRoomViewModelNotify {
  34. func onRoomInfoChanged() {
  35. checkMenu()
  36. }
  37. func onRoomSeatsChanged() {
  38. checkMenu()
  39. }
  40. private func checkMenu() {
  41. menuButton.isHidden = roomSession?.mySeatInfo?.index != .host // 非主播
  42. && roomSession?.roomInfo.owner.isMyUid != true // 非房主
  43. }
  44. }
  45. extension LNRoomBottomMenuView {
  46. private func setupViews() {
  47. snp.makeConstraints { make in
  48. make.height.equalTo(50)
  49. }
  50. let menuView = buildMenuView()
  51. addSubview(menuView)
  52. menuView.snp.makeConstraints { make in
  53. make.trailing.equalToSuperview().offset(-10)
  54. make.centerY.equalToSuperview()
  55. }
  56. let input = buildMessageInput()
  57. addSubview(input)
  58. input.snp.makeConstraints { make in
  59. make.centerY.equalToSuperview()
  60. make.leading.equalToSuperview().offset(10)
  61. }
  62. }
  63. private func buildMenuView() -> UIView {
  64. let stackView = UIStackView()
  65. stackView.axis = .horizontal
  66. stackView.spacing = 8
  67. stackView.snp.makeConstraints { make in
  68. make.height.equalTo(32)
  69. }
  70. stackView.addArrangedSubview(micButton)
  71. micButton.snp.makeConstraints { make in
  72. make.width.height.equalTo(32)
  73. }
  74. giftButton.isHidden = false
  75. giftButton.setBackgroundImage(.icGift, for: .normal)
  76. giftButton.addAction(UIAction(handler: { [weak self] _ in
  77. guard let self else { return }
  78. let panel = LNRoomGiftPanel()
  79. panel.update(roomSession)
  80. panel.popup(self)
  81. }), for: .touchUpInside)
  82. stackView.addArrangedSubview(giftButton)
  83. giftButton.snp.makeConstraints { make in
  84. make.width.height.equalTo(32)
  85. }
  86. menuButton.isHidden = true
  87. menuButton.setBackgroundImage(.icMoreWithBg, for: .normal)
  88. menuButton.addAction(UIAction(handler: { [weak self] _ in
  89. guard let self else { return }
  90. let panel = LNRoomSettingMenuPanel()
  91. panel.update(roomSession)
  92. panel.popup(self)
  93. }), for: .touchUpInside)
  94. stackView.addArrangedSubview(menuButton)
  95. menuButton.snp.makeConstraints { make in
  96. make.width.height.equalTo(32)
  97. }
  98. stackView.addArrangedSubview(joinButton)
  99. return stackView
  100. }
  101. private func buildMessageInput() -> UIView {
  102. return messageInput
  103. }
  104. }