| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- //
- // LNRoomBottomMenuView.swift
- // Gami
- //
- // Created by OneeChan on 2026/3/9.
- //
- import Foundation
- import UIKit
- import SnapKit
- class LNRoomBottomMenuView: UIView {
- private let messageInput = LNRoomMessageInputView()
-
- private let micButton = LNRoomBottomMicView()
- private let giftButton = UIButton()
- private let menuButton = UIButton()
- private let joinButton = LNRoomJoinMenuView()
-
- private weak var roomSession: LNRoomViewModel?
-
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- setupViews()
- LNEventDeliver.addObserver(self)
- }
-
- func update(_ room: LNRoomViewModel?) {
- roomSession = room
-
- joinButton.update(room)
- messageInput.update(room)
- micButton.update(room)
- onRoomSeatsChanged()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
- extension LNRoomBottomMenuView: LNRoomViewModelNotify {
- func onRoomInfoChanged() {
- checkMenu()
- }
-
- func onRoomSeatsChanged() {
- checkMenu()
- }
-
- private func checkMenu() {
- menuButton.isHidden = roomSession?.mySeatInfo?.index != .host // 非主播
- && roomSession?.roomInfo.owner.isMyUid != true // 非房主
- }
- }
- extension LNRoomBottomMenuView {
- private func setupViews() {
- snp.makeConstraints { make in
- make.height.equalTo(50)
- }
-
- let menuView = buildMenuView()
- addSubview(menuView)
- menuView.snp.makeConstraints { make in
- make.trailing.equalToSuperview().offset(-10)
- make.centerY.equalToSuperview()
- }
-
- let input = buildMessageInput()
- addSubview(input)
- input.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.leading.equalToSuperview().offset(10)
- }
- }
-
- private func buildMenuView() -> UIView {
- let stackView = UIStackView()
- stackView.axis = .horizontal
- stackView.spacing = 8
- stackView.snp.makeConstraints { make in
- make.height.equalTo(32)
- }
-
- stackView.addArrangedSubview(micButton)
- micButton.snp.makeConstraints { make in
- make.width.height.equalTo(32)
- }
-
- giftButton.isHidden = false
- giftButton.setBackgroundImage(.icGift, for: .normal)
- giftButton.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- let panel = LNRoomGiftPanel()
- panel.update(roomSession)
- panel.popup(self)
- }), for: .touchUpInside)
- stackView.addArrangedSubview(giftButton)
- giftButton.snp.makeConstraints { make in
- make.width.height.equalTo(32)
- }
-
- menuButton.isHidden = true
- menuButton.setBackgroundImage(.icMoreWithBg, for: .normal)
- menuButton.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- let panel = LNRoomSettingMenuPanel()
- panel.update(roomSession)
- panel.popup(self)
- }), for: .touchUpInside)
- stackView.addArrangedSubview(menuButton)
- menuButton.snp.makeConstraints { make in
- make.width.height.equalTo(32)
- }
-
- stackView.addArrangedSubview(joinButton)
-
- return stackView
- }
-
- private func buildMessageInput() -> UIView {
- return messageInput
- }
- }
|