1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import UIKit
- import NextcloudKit
- import SVGKit
- class NCShareNewUserAddComment: UIViewController, NCShareDetail {
- @IBOutlet weak var headerContainerView: UIView!
- @IBOutlet weak var sharingLabel: UILabel!
- @IBOutlet weak var noteTextField: UITextView!
- let contentInsets: CGFloat = 16
- var onDismiss: (() -> Void)?
- public var share: NCTableShareable!
- public var metadata: tableMetadata!
- override func viewDidLoad() {
- super.viewDidLoad()
- self.setNavigationTitle()
- NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
- sharingLabel.text = NSLocalizedString("_share_note_recipient_", comment: "")
- noteTextField.textContainerInset = UIEdgeInsets(top: contentInsets, left: contentInsets, bottom: contentInsets, right: contentInsets)
- noteTextField.text = share.note
- let toolbar = UIToolbar.toolbar {
- self.noteTextField.resignFirstResponder()
- self.noteTextField.text = ""
- self.share.note = ""
- } completion: {
- self.noteTextField.resignFirstResponder()
- self.share.note = self.noteTextField.text
- }
- noteTextField.inputAccessoryView = toolbar.wrappedSafeAreaContainer
- guard let headerView = (Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader) else { return }
- headerContainerView.addSubview(headerView)
- headerView.frame = headerContainerView.frame
- headerView.translatesAutoresizingMaskIntoConstraints = false
- headerView.topAnchor.constraint(equalTo: headerContainerView.topAnchor).isActive = true
- headerView.bottomAnchor.constraint(equalTo: headerContainerView.bottomAnchor).isActive = true
- headerView.leftAnchor.constraint(equalTo: headerContainerView.leftAnchor).isActive = true
- headerView.rightAnchor.constraint(equalTo: headerContainerView.rightAnchor).isActive = true
- headerView.setupUI(with: metadata)
- }
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- share.note = noteTextField.text
- onDismiss?()
- }
- @objc func adjustForKeyboard(notification: Notification) {
- guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue,
- let globalTextViewFrame = noteTextField.superview?.convert(noteTextField.frame, to: nil) else { return }
- let keyboardScreenEndFrame = keyboardValue.cgRectValue
- let portionCovoredByLeyboard = globalTextViewFrame.maxY - keyboardScreenEndFrame.minY
- if notification.name == UIResponder.keyboardWillHideNotification || portionCovoredByLeyboard < 0 {
- noteTextField.contentInset = .zero
- } else {
- noteTextField.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: portionCovoredByLeyboard, right: 0)
- }
- noteTextField.scrollIndicatorInsets = noteTextField.contentInset
- }
- }
|