NCShareNewUserAddComment.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // NCShareNewUserAddComment.swift
  3. // Nextcloud
  4. //
  5. // Created by TSI-mc on 21/06/21.
  6. // Copyright © 2022 Henrik Storch. All rights reserved.
  7. //
  8. // Author Henrik Storch <henrik.storch@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. import NextcloudKit
  25. import SVGKit
  26. class NCShareNewUserAddComment: UIViewController, NCShareDetail {
  27. @IBOutlet weak var headerContainerView: UIView!
  28. @IBOutlet weak var sharingLabel: UILabel!
  29. @IBOutlet weak var noteTextField: UITextView!
  30. let contentInsets: CGFloat = 16
  31. var onDismiss: (() -> Void)?
  32. public var share: NCTableShareable!
  33. public var metadata: tableMetadata!
  34. override func viewDidLoad() {
  35. super.viewDidLoad()
  36. self.setNavigationTitle()
  37. NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil)
  38. NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
  39. sharingLabel.text = NSLocalizedString("_share_note_recipient_", comment: "")
  40. noteTextField.textContainerInset = UIEdgeInsets(top: contentInsets, left: contentInsets, bottom: contentInsets, right: contentInsets)
  41. noteTextField.text = share.note
  42. let toolbar = UIToolbar.toolbar {
  43. self.noteTextField.resignFirstResponder()
  44. self.noteTextField.text = ""
  45. self.share.note = ""
  46. } onDone: {
  47. self.noteTextField.resignFirstResponder()
  48. self.share.note = self.noteTextField.text
  49. self.navigationController?.popViewController(animated: true)
  50. }
  51. noteTextField.inputAccessoryView = toolbar.wrappedSafeAreaContainer
  52. guard let headerView = (Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader) else { return }
  53. headerContainerView.addSubview(headerView)
  54. headerView.frame = headerContainerView.frame
  55. headerView.translatesAutoresizingMaskIntoConstraints = false
  56. headerView.topAnchor.constraint(equalTo: headerContainerView.topAnchor).isActive = true
  57. headerView.bottomAnchor.constraint(equalTo: headerContainerView.bottomAnchor).isActive = true
  58. headerView.leftAnchor.constraint(equalTo: headerContainerView.leftAnchor).isActive = true
  59. headerView.rightAnchor.constraint(equalTo: headerContainerView.rightAnchor).isActive = true
  60. headerView.setupUI(with: metadata)
  61. }
  62. override func viewWillDisappear(_ animated: Bool) {
  63. super.viewWillDisappear(animated)
  64. share.note = noteTextField.text
  65. onDismiss?()
  66. }
  67. @objc func adjustForKeyboard(notification: Notification) {
  68. guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue,
  69. let globalTextViewFrame = noteTextField.superview?.convert(noteTextField.frame, to: nil) else { return }
  70. let keyboardScreenEndFrame = keyboardValue.cgRectValue
  71. let portionCovoredByLeyboard = globalTextViewFrame.maxY - keyboardScreenEndFrame.minY
  72. if notification.name == UIResponder.keyboardWillHideNotification || portionCovoredByLeyboard < 0 {
  73. noteTextField.contentInset = .zero
  74. } else {
  75. noteTextField.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: portionCovoredByLeyboard, right: 0)
  76. }
  77. noteTextField.scrollIndicatorInsets = noteTextField.contentInset
  78. }
  79. }