MemberInviteView.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // MemberInviteView.swift
  3. // TUIRoomKit
  4. //
  5. // Created by krabyu on 2023/8/21.
  6. //
  7. import Foundation
  8. class MemberInviteView: UIView {
  9. let viewModel: MemberInviteViewModel
  10. private var isViewReady: Bool = false
  11. var viewArray: [UIView] = []
  12. let headView: UIView = {
  13. let view = UIView()
  14. view.backgroundColor = UIColor(0x1B1E26)
  15. return view
  16. }()
  17. lazy var titleLabel: UILabel = {
  18. let label = UILabel()
  19. label.text = viewModel.title
  20. label.textColor = UIColor(0xD5E0F2)
  21. label.font = UIFont(name: "PingFangSC-Regular", size: 18)
  22. label.textAlignment = .left
  23. return label
  24. }()
  25. let stackView: UIStackView = {
  26. let view = UIStackView()
  27. view.axis = .vertical
  28. view.alignment = .center
  29. view.distribution = .equalSpacing
  30. view.spacing = 3
  31. view.backgroundColor = UIColor(0x1B1E26)
  32. return view
  33. }()
  34. let copyButton: UIButton = {
  35. let button = UIButton()
  36. button.setTitle(.copyRoomInformation, for: .normal)
  37. button.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .regular)
  38. button.setTitleColor(UIColor(0xB2BBD1), for: .normal)
  39. button.titleLabel?.textAlignment = .center
  40. button.backgroundColor = UIColor(0x4F586B).withAlphaComponent(0.3)
  41. button.layer.cornerRadius = 6
  42. return button
  43. }()
  44. init(viewModel: MemberInviteViewModel) {
  45. self.viewModel = viewModel
  46. super.init(frame: .zero)
  47. }
  48. required init?(coder: NSCoder) {
  49. fatalError("init(coder:) has not been implemented")
  50. }
  51. override func didMoveToWindow() {
  52. super.didMoveToWindow()
  53. guard !isViewReady else { return }
  54. constructViewHierarchy()
  55. activateConstraints()
  56. bindInteraction()
  57. reportViewShow()
  58. isViewReady = true
  59. }
  60. override func draw(_ rect: CGRect) {
  61. super.draw(rect)
  62. self.layer.cornerRadius = 12
  63. }
  64. func constructViewHierarchy() {
  65. addSubview(stackView)
  66. addSubview(headView)
  67. headView.addSubview(titleLabel)
  68. addSubview(copyButton)
  69. }
  70. func activateConstraints() {
  71. headView.snp.makeConstraints { make in
  72. make.top.equalToSuperview().offset(20.scale375())
  73. make.leading.equalToSuperview().offset(16.scale375())
  74. make.trailing.equalToSuperview().offset(-16.scale375())
  75. make.height.equalTo(25.scale375())
  76. }
  77. titleLabel.snp.makeConstraints { make in
  78. make.top.equalToSuperview()
  79. make.leading.equalToSuperview()
  80. make.height.equalTo(25.scale375())
  81. make.width.equalTo(182.scale375())
  82. }
  83. stackView.snp.makeConstraints { make in
  84. make.top.equalTo(headView.snp.bottom).offset(20.scale375())
  85. make.leading.equalToSuperview().offset(16.scale375())
  86. make.trailing.equalToSuperview().offset(-16.scale375())
  87. }
  88. copyButton.snp.makeConstraints { make in
  89. make.leading.equalToSuperview().offset(16.scale375())
  90. make.trailing.equalToSuperview().offset(-16.scale375())
  91. make.height.equalTo(40.scale375Height())
  92. make.top.equalTo(stackView.snp.bottom).offset(20.scale375Height())
  93. }
  94. for item in viewModel.messageItems {
  95. let view = ListCellItemView(itemData: item)
  96. viewArray.append(view)
  97. stackView.addArrangedSubview(view)
  98. view.snp.makeConstraints { make in
  99. make.height.equalTo(24.scale375Height())
  100. make.width.equalToSuperview()
  101. }
  102. }
  103. }
  104. func bindInteraction() {
  105. backgroundColor = UIColor(0x1B1E26)
  106. viewModel.viewResponder = self
  107. copyButton.addTarget(self, action: #selector(copyAction(sender:)), for: .touchUpInside)
  108. }
  109. private func reportViewShow() {
  110. viewModel.reportMemberInvitePanelShow()
  111. }
  112. @objc func copyAction(sender: UIButton) {
  113. viewModel.copyAction()
  114. makeToast(.roomInformationCopiedSuccessfully)
  115. }
  116. deinit {
  117. debugPrint("deinit \(self)")
  118. }
  119. }
  120. extension MemberInviteView: MemberInviteResponder {
  121. func showCopyToast(copyType: CopyType?) {
  122. guard let copyType = copyType else { return }
  123. var test: String
  124. switch copyType {
  125. case .copyRoomPassword:
  126. test = .copyRoomPasswordSuccess
  127. case .copyRoomIdType:
  128. test = .copyRoomIdSuccess
  129. case .copyRoomLinkType:
  130. test = .copyRoomLinkSuccess
  131. }
  132. RoomRouter.makeToastInCenter(toast: test,duration: 0.5)
  133. }
  134. }
  135. private extension String {
  136. static var copyRoomIdSuccess: String {
  137. localized("Conference ID copied.")
  138. }
  139. static var copyRoomLinkSuccess: String {
  140. localized("Conference Link copied.")
  141. }
  142. static let conferencePasswordSuccess = localized("Conference password copied successfully.")
  143. static let copyRoomInformation = localized("Copy room information")
  144. static let roomInformationCopiedSuccessfully = localized("Room information copied successfully")
  145. static let copyRoomPasswordSuccess = localized("Conference password copied")
  146. }