MoreUserManagerView.swift 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // MoreUserManagerView.swift
  3. // TUIRoomKit
  4. //
  5. // Created by janejntang on 2024/10/15.
  6. //
  7. import Foundation
  8. import Factory
  9. import Combine
  10. class MoreUserManagerView: UIView {
  11. private var currentLandscape: Bool = isLandscape
  12. var cancellableSet = Set<AnyCancellable>()
  13. private lazy var selfRolePublisher = {
  14. operation.select(UserSelectors.getSelfRole)
  15. }()
  16. private lazy var menus = {
  17. MoreUserManagerDataCreator.generateMoreUserManagerItems(operation: operation)
  18. }()
  19. let contentView: UIView = {
  20. let view = UIView(frame: .zero)
  21. view.backgroundColor = UIColor(0x22262E)
  22. view.layer.cornerRadius = 12
  23. return view
  24. }()
  25. let dropArrowButton: UIButton = {
  26. let button = UIButton()
  27. button.setImage(UIImage(named: "room_drop_arrow", in: tuiRoomKitBundle(), compatibleWith: nil), for: .normal)
  28. button.contentEdgeInsets = UIEdgeInsets(top: 12.scale375Height(), left: 20.scale375(), bottom: 12.scale375Height(), right: 20.scale375())
  29. return button
  30. }()
  31. let rightArrowButton: UIButton = {
  32. let button = UIButton()
  33. button.setImage(UIImage(named: "room_right_arrow", in: tuiRoomKitBundle(), compatibleWith: nil), for: .normal)
  34. button.contentEdgeInsets = UIEdgeInsets(top: 20.scale375Height(), left: 12.scale375(), bottom: 20.scale375Height(), right: 12.scale375())
  35. return button
  36. }()
  37. let stackView: UIStackView = {
  38. let view = UIStackView()
  39. view.axis = .vertical
  40. view.alignment = .top
  41. view.spacing = 10
  42. return view
  43. }()
  44. let backBlockView: UIView = {
  45. let view = UIView()
  46. view.backgroundColor = UIColor(0x17181F)
  47. view.alpha = 0.9
  48. return view
  49. }()
  50. init() {
  51. super.init(frame: .zero)
  52. contentView.transform = CGAffineTransform(translationX: 0, y: kScreenHeight)
  53. alpha = 0
  54. }
  55. required init?(coder: NSCoder) {
  56. fatalError("init(coder:) has not been implemented")
  57. }
  58. private var isViewReady: Bool = false
  59. override func didMoveToWindow() {
  60. super.didMoveToWindow()
  61. guard !isViewReady else { return }
  62. constructViewHierarchy()
  63. activateConstraints()
  64. bindInteraction()
  65. isViewReady = true
  66. }
  67. override func layoutSubviews() {
  68. super.layoutSubviews()
  69. guard currentLandscape != isLandscape else { return }
  70. setupViewOrientation(isLandscape: isLandscape)
  71. currentLandscape = isLandscape
  72. }
  73. private func constructViewHierarchy() {
  74. addSubview(backBlockView)
  75. addSubview(contentView)
  76. contentView.addSubview(dropArrowButton)
  77. contentView.addSubview(rightArrowButton)
  78. contentView.addSubview(stackView)
  79. setupStackView()
  80. }
  81. private func activateConstraints() {
  82. setupViewOrientation(isLandscape: isLandscape)
  83. backBlockView.snp.makeConstraints { make in
  84. make.edges.equalToSuperview()
  85. }
  86. }
  87. private func bindInteraction() {
  88. let tap = UITapGestureRecognizer(target: self, action: #selector(dismiss))
  89. backBlockView.addGestureRecognizer(tap)
  90. dropArrowButton.addTarget(self, action: #selector(dismiss), for: .touchUpInside)
  91. rightArrowButton.addTarget(self, action: #selector(dismiss), for: .touchUpInside)
  92. subscribeSubject()
  93. }
  94. private func setupViewOrientation(isLandscape: Bool) {
  95. contentView.snp.remakeConstraints { make in
  96. if isLandscape {
  97. make.height.equalToSuperview()
  98. }
  99. make.bottom.leading.trailing.equalToSuperview()
  100. }
  101. dropArrowButton.snp.remakeConstraints { make in
  102. make.height.equalTo(isLandscape ? 0 : 43.scale375())
  103. make.top.centerX.equalToSuperview()
  104. }
  105. rightArrowButton.snp.remakeConstraints { make in
  106. make.width.equalTo(isLandscape ? 27.scale375() : 0)
  107. make.leading.centerY.equalToSuperview()
  108. }
  109. stackView.snp.remakeConstraints { make in
  110. make.top.equalTo(dropArrowButton.snp.bottom).offset(15.scale375Height())
  111. make.leading.equalTo(rightArrowButton.snp.trailing).offset(16.scale375())
  112. make.trailing.equalToSuperview()
  113. if !isLandscape {
  114. make.bottom.equalToSuperview().offset(-34.scale375Height())
  115. }
  116. }
  117. }
  118. private func setupStackView() {
  119. for item in menus {
  120. let view = ButtonItemView(itemData: item)
  121. stackView.addArrangedSubview(view)
  122. view.snp.makeConstraints { make in
  123. make.height.equalTo(53)
  124. make.width.equalToSuperview()
  125. }
  126. item.bindStateClosure?(view, &view.cancellableSet)
  127. }
  128. }
  129. func show(rootView: UIView) {
  130. rootView.addSubview(self)
  131. self.snp.makeConstraints { make in
  132. make.edges.equalToSuperview()
  133. }
  134. setupViewOrientation(isLandscape: isLandscape)
  135. UIView.animate(withDuration: 0.3) { [weak self] in
  136. guard let self = self else { return }
  137. self.alpha = 1
  138. self.contentView.transform = .identity
  139. }
  140. }
  141. @objc func dismiss() {
  142. UIView.animate(withDuration: 0.3) { [weak self] in
  143. guard let self = self else { return }
  144. self.alpha = 0
  145. self.contentView.transform = CGAffineTransform(translationX: 0, y: kScreenHeight)
  146. } completion: { [weak self] _ in
  147. guard let self = self else { return }
  148. self.removeFromSuperview()
  149. }
  150. }
  151. private func subscribeSubject() {
  152. selfRolePublisher
  153. .receive(on: DispatchQueue.mainQueue)
  154. .sink { [weak self] userRole in
  155. guard let self = self else { return }
  156. guard userRole == .generalUser else { return }
  157. self.dismiss()
  158. }
  159. .store(in: &cancellableSet)
  160. }
  161. deinit {
  162. debugPrint("deinit:\(self)")
  163. }
  164. // MARK: - private property.
  165. @Injected(\.conferenceStore) private var operation
  166. }