NCShareNewUserAddComment.swift 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 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. } completion: {
  47. self.noteTextField.resignFirstResponder()
  48. self.share.note = self.noteTextField.text
  49. }
  50. noteTextField.inputAccessoryView = toolbar.wrappedSafeAreaContainer
  51. guard let headerView = (Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader) else { return }
  52. headerContainerView.addSubview(headerView)
  53. headerView.frame = headerContainerView.frame
  54. headerView.translatesAutoresizingMaskIntoConstraints = false
  55. headerView.topAnchor.constraint(equalTo: headerContainerView.topAnchor).isActive = true
  56. headerView.bottomAnchor.constraint(equalTo: headerContainerView.bottomAnchor).isActive = true
  57. headerView.leftAnchor.constraint(equalTo: headerContainerView.leftAnchor).isActive = true
  58. headerView.rightAnchor.constraint(equalTo: headerContainerView.rightAnchor).isActive = true
  59. headerView.setupUI(with: metadata)
  60. }
  61. override func viewWillDisappear(_ animated: Bool) {
  62. super.viewWillDisappear(animated)
  63. share.note = noteTextField.text
  64. onDismiss?()
  65. }
  66. @objc func adjustForKeyboard(notification: Notification) {
  67. guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue,
  68. let globalTextViewFrame = noteTextField.superview?.convert(noteTextField.frame, to: nil) else { return }
  69. let keyboardScreenEndFrame = keyboardValue.cgRectValue
  70. let portionCovoredByLeyboard = globalTextViewFrame.maxY - keyboardScreenEndFrame.minY
  71. if notification.name == UIResponder.keyboardWillHideNotification || portionCovoredByLeyboard < 0 {
  72. noteTextField.contentInset = .zero
  73. } else {
  74. noteTextField.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: portionCovoredByLeyboard, right: 0)
  75. }
  76. noteTextField.scrollIndicatorInsets = noteTextField.contentInset
  77. }
  78. }