NCShareNewUserAddComment.swift 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 NCCommunication
  25. import SVGKit
  26. class NCShareNewUserAddComment: UIViewController, NCShareDetail {
  27. @IBOutlet weak var headerContainerView: UIView!
  28. @IBOutlet weak var sharingLabel: UILabel!
  29. @IBOutlet weak var sharingNote: UILabel!
  30. @IBOutlet weak var noteTextField: UITextView!
  31. let contentInsets: CGFloat = 16
  32. var onDismiss: (() -> Void)?
  33. public var share: NCTableShareable!
  34. public var metadata: tableMetadata!
  35. override func viewDidLoad() {
  36. super.viewDidLoad()
  37. self.setNavigationTitle()
  38. NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil)
  39. NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
  40. sharingLabel.text = NSLocalizedString("_sharing_", comment: "")
  41. sharingNote.text = NSLocalizedString("_share_note_recipient_", comment: "")
  42. noteTextField.textContainerInset = UIEdgeInsets(top: contentInsets, left: contentInsets, bottom: contentInsets, right: contentInsets)
  43. noteTextField.text = share.note
  44. let toolbar = UIToolbar.toolbar {
  45. self.noteTextField.resignFirstResponder()
  46. self.noteTextField.text = ""
  47. self.share.note = ""
  48. } completion: {
  49. self.noteTextField.resignFirstResponder()
  50. self.share.note = self.noteTextField.text
  51. }
  52. noteTextField.inputAccessoryView = toolbar
  53. guard let headerView = (Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader) else { return }
  54. headerContainerView.addSubview(headerView)
  55. headerView.frame = headerContainerView.frame
  56. headerView.translatesAutoresizingMaskIntoConstraints = false
  57. headerView.topAnchor.constraint(equalTo: headerContainerView.topAnchor).isActive = true
  58. headerView.bottomAnchor.constraint(equalTo: headerContainerView.bottomAnchor).isActive = true
  59. headerView.leftAnchor.constraint(equalTo: headerContainerView.leftAnchor).isActive = true
  60. headerView.rightAnchor.constraint(equalTo: headerContainerView.rightAnchor).isActive = true
  61. headerView.setupUI(with: metadata)
  62. }
  63. override func viewWillDisappear(_ animated: Bool) {
  64. super.viewWillDisappear(animated)
  65. share.note = noteTextField.text
  66. onDismiss?()
  67. }
  68. @objc func adjustForKeyboard(notification: Notification) {
  69. guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue,
  70. let globalTextViewFrame = noteTextField.superview?.convert(noteTextField.frame, to: nil) else { return }
  71. let keyboardScreenEndFrame = keyboardValue.cgRectValue
  72. let portionCovoredByLeyboard = globalTextViewFrame.maxY - keyboardScreenEndFrame.minY
  73. if notification.name == UIResponder.keyboardWillHideNotification || portionCovoredByLeyboard < 0 {
  74. noteTextField.contentInset = .zero
  75. } else {
  76. noteTextField.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: portionCovoredByLeyboard, right: 0)
  77. }
  78. noteTextField.scrollIndicatorInsets = noteTextField.contentInset
  79. }
  80. }