LNEditBioPanel.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // LNEditBioPanel.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/12/19.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNEditBioPanel: LNPopupView {
  11. private let inputTextView = LNCommonTextView()
  12. private let confirmButton = UIButton()
  13. var handler: ((String) -> Void)?
  14. override init(frame: CGRect) {
  15. super.init(frame: frame)
  16. setupViews()
  17. }
  18. func update(_ bio: String) {
  19. inputTextView.setText(bio)
  20. }
  21. required init?(coder: NSCoder) {
  22. fatalError("init(coder:) has not been implemented")
  23. }
  24. }
  25. extension LNEditBioPanel: UITextViewDelegate {
  26. func textViewDidChange(_ textView: UITextView) {
  27. if textView.text.isEmpty, confirmButton.isEnabled {
  28. confirmButton.isEnabled = false
  29. confirmButton.setBackgroundImage(nil, for: .normal)
  30. } else if confirmButton.backgroundImage(for: .normal) == nil {
  31. confirmButton.isEnabled = true
  32. confirmButton.setBackgroundImage(.primary_8, for: .normal)
  33. }
  34. }
  35. }
  36. extension LNEditBioPanel {
  37. private func setupViews() {
  38. let titleLabel = UILabel()
  39. titleLabel.font = .heading_h3
  40. titleLabel.textColor = .text_5
  41. titleLabel.text = .init(key: "A00184")
  42. container.addSubview(titleLabel)
  43. titleLabel.snp.makeConstraints { make in
  44. make.centerX.equalToSuperview()
  45. make.top.equalToSuperview().offset(16)
  46. }
  47. inputTextView.maxInput = LNProfileManager.bioMaxInput
  48. container.addSubview(inputTextView)
  49. inputTextView.snp.makeConstraints { make in
  50. make.horizontalEdges.equalToSuperview().inset(16)
  51. make.top.equalTo(titleLabel.snp.bottom).offset(16)
  52. make.height.equalTo(119)
  53. }
  54. confirmButton.setTitle(.init(key: "A00185"), for: .normal)
  55. confirmButton.setTitleColor(.text_1, for: .normal)
  56. confirmButton.titleLabel?.font = .heading_h3
  57. confirmButton.setBackgroundImage(.primary_8, for: .normal)
  58. confirmButton.layer.cornerRadius = 23.5
  59. confirmButton.clipsToBounds = true
  60. confirmButton.backgroundColor = .fill_4
  61. confirmButton.addAction(UIAction(handler: { [weak self] _ in
  62. guard let self else { return }
  63. endEditing(true)
  64. dismiss()
  65. handler?(inputTextView.text)
  66. }), for: .touchUpInside)
  67. container.addSubview(confirmButton)
  68. confirmButton.snp.makeConstraints { make in
  69. make.horizontalEdges.equalToSuperview().inset(12)
  70. make.top.equalTo(inputTextView.snp.bottom).offset(16)
  71. make.bottom.equalToSuperview().offset(commonBottomInset)
  72. make.height.equalTo(47)
  73. }
  74. }
  75. }
  76. #if DEBUG
  77. import SwiftUI
  78. struct LNEditBioPanelPreview: UIViewRepresentable {
  79. func makeUIView(context: Context) -> some UIView {
  80. let container = UIView()
  81. container.backgroundColor = .lightGray
  82. let view = LNEditBioPanel()
  83. view.popup(container)
  84. return container
  85. }
  86. func updateUIView(_ uiView: UIViewType, context: Context) { }
  87. }
  88. #Preview(body: {
  89. LNEditBioPanelPreview()
  90. })
  91. #endif // DEBUG