Browse Source

Fix share UI landscape, textfields

Can't push up content views, since paging view blocks on top of content VC. So, just move entire paging VC..

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
561473e2e2

+ 2 - 1
iOSClient/Activity/NCActivity.swift

@@ -26,7 +26,7 @@ import UIKit
 import SwiftRichString
 import SwiftRichString
 import NCCommunication
 import NCCommunication
 
 
-class NCActivity: UIViewController {
+class NCActivity: UIViewController, NCSharePagingContent {
 
 
     @IBOutlet weak var tableView: UITableView!
     @IBOutlet weak var tableView: UITableView!
 
 
@@ -34,6 +34,7 @@ class NCActivity: UIViewController {
     @IBOutlet weak var imageItem: UIImageView!
     @IBOutlet weak var imageItem: UIImageView!
     @IBOutlet weak var labelUser: UILabel!
     @IBOutlet weak var labelUser: UILabel!
     @IBOutlet weak var newCommentField: UITextField!
     @IBOutlet weak var newCommentField: UITextField!
+    var textField: UITextField { newCommentField }
 
 
     @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint!
     @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint!
     var height: CGFloat = 0
     var height: CGFloat = 0

+ 4 - 4
iOSClient/Share/NCShare.swift

@@ -28,7 +28,7 @@ import DropDown
 import NCCommunication
 import NCCommunication
 import MarqueeLabel
 import MarqueeLabel
 
 
-class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingDelegate {
+class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingDelegate, NCSharePagingContent {
 
 
     @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint!
     @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint!
     @IBOutlet weak var sharedWithYouByView: UIView!
     @IBOutlet weak var sharedWithYouByView: UIView!
@@ -38,6 +38,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
     @IBOutlet weak var sharedWithYouByNote: MarqueeLabel!
     @IBOutlet weak var sharedWithYouByNote: MarqueeLabel!
     @IBOutlet weak var searchFieldTopConstraint: NSLayoutConstraint!
     @IBOutlet weak var searchFieldTopConstraint: NSLayoutConstraint!
     @IBOutlet weak var searchField: UITextField!
     @IBOutlet weak var searchField: UITextField!
+    var textField: UITextField { searchField }
+
     @IBOutlet weak var tableView: UITableView!
     @IBOutlet weak var tableView: UITableView!
 
 
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
@@ -170,9 +172,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
     // MARK: - IBAction
     // MARK: - IBAction
 
 
     @IBAction func searchFieldDidEndOnExit(textField: UITextField) {
     @IBAction func searchFieldDidEndOnExit(textField: UITextField) {
-
-        guard let searchString = textField.text else { return }
-
+        guard let searchString = textField.text, !searchString.isEmpty else { return }
         networking?.getSharees(searchString: searchString)
         networking?.getSharees(searchString: searchString)
     }
     }
 
 

+ 44 - 7
iOSClient/Share/NCSharePaging.swift

@@ -27,6 +27,10 @@ import Parchment
 import NCCommunication
 import NCCommunication
 import MarqueeLabel
 import MarqueeLabel
 
 
+protocol NCSharePagingContent {
+    var textField: UITextField { get }
+}
+
 class NCSharePaging: UIViewController {
 class NCSharePaging: UIViewController {
 
 
     private let pagingViewController = NCShareHeaderViewController()
     private let pagingViewController = NCShareHeaderViewController()
@@ -35,6 +39,7 @@ class NCSharePaging: UIViewController {
     private var activityEnabled = true
     private var activityEnabled = true
     private var commentsEnabled = true
     private var commentsEnabled = true
     private var sharingEnabled = true
     private var sharingEnabled = true
+    private var currentVC: NCSharePagingContent?
 
 
     @objc var metadata = tableMetadata()
     @objc var metadata = tableMetadata()
     var indexPage = NCGlobal.NCSharePagingIndex.activity
     var indexPage = NCGlobal.NCSharePagingIndex.activity
@@ -47,6 +52,8 @@ class NCSharePaging: UIViewController {
         view.backgroundColor = NCBrandColor.shared.systemBackground
         view.backgroundColor = NCBrandColor.shared.systemBackground
 
 
         navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_close_", comment: ""), style: .done, target: self, action: #selector(exitTapped))
         navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_close_", comment: ""), style: .done, target: self, action: #selector(exitTapped))
+        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
+         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
 
 
         // Verify Comments & Sharing enabled
         // Verify Comments & Sharing enabled
         let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
         let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
@@ -114,6 +121,11 @@ class NCSharePaging: UIViewController {
         changeTheming()
         changeTheming()
     }
     }
 
 
+    override func viewDidAppear(_ animated: Bool) {
+        super.viewDidAppear(animated)
+        currentVC = pagingViewController.pageViewController.selectedViewController as? NCSharePagingContent
+    }
+
     override func viewWillAppear(_ animated: Bool) {
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
         super.viewWillAppear(animated)
 
 
@@ -133,20 +145,18 @@ class NCSharePaging: UIViewController {
     }
     }
 
 
     deinit {
     deinit {
-       NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
-    }
-
-    @objc func exitTapped() {
-        self.dismiss(animated: true, completion: nil)
+        NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
+        NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidShowNotification, object: nil)
+        NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
     }
     }
 
 
     //MARK: - NotificationCenter
     //MARK: - NotificationCenter
 
 
     @objc func orientationDidChange() {
     @objc func orientationDidChange() {
-        print(#function, self.view.bounds.width, view.frame.width)
         pagingViewController.menuItemSize = .fixed(
         pagingViewController.menuItemSize = .fixed(
             width: self.view.bounds.width / CGFloat(NCGlobal.NCSharePagingIndex.allCases.count),
             width: self.view.bounds.width / CGFloat(NCGlobal.NCSharePagingIndex.allCases.count),
             height: 40)
             height: 40)
+        currentVC?.textField.resignFirstResponder()
     }
     }
 
 
     @objc func changeTheming() {
     @objc func changeTheming() {
@@ -154,6 +164,30 @@ class NCSharePaging: UIViewController {
         (pagingViewController.view as! NCSharePagingView).setupConstraints()
         (pagingViewController.view as! NCSharePagingView).setupConstraints()
         pagingViewController.reloadMenu()
         pagingViewController.reloadMenu()
     }
     }
+
+    // MARK: - Keyboard & TextField
+    @objc func keyboardWillShow(notification: Notification) {
+         let frameEndUserInfoKey = UIResponder.keyboardFrameEndUserInfoKey
+
+         guard let info = notification.userInfo,
+               let textField = currentVC?.textField,
+               let centerObject = textField.superview?.convert(textField.center, to: nil),
+               let keyboardFrame = info[frameEndUserInfoKey] as? CGRect
+         else { return }
+
+        let diff = keyboardFrame.origin.y - centerObject.y - textField.frame.height
+         if diff < 0 {
+             view.frame.origin.y = diff
+         }
+     }
+
+     @objc func keyboardWillHide(notification: NSNotification) {
+         view.frame.origin.y = 0
+     }
+
+    @objc func exitTapped() {
+        self.dismiss(animated: true, completion: nil)
+    }
 }
 }
 
 
 // MARK: - PagingViewController Delegate
 // MARK: - PagingViewController Delegate
@@ -174,6 +208,9 @@ extension NCSharePaging: PagingViewControllerDelegate {
         } else {
         } else {
             self.title = item.title
             self.title = item.title
         }
         }
+
+        currentVC?.textField.resignFirstResponder()
+        self.currentVC = destinationViewController as? NCSharePagingContent
     }
     }
 }
 }
 
 
@@ -182,7 +219,7 @@ extension NCSharePaging: PagingViewControllerDelegate {
 extension NCSharePaging: PagingViewControllerDataSource {
 extension NCSharePaging: PagingViewControllerDataSource {
 
 
     func pagingViewController(_: PagingViewController, viewControllerAt index: Int) -> UIViewController {
     func pagingViewController(_: PagingViewController, viewControllerAt index: Int) -> UIViewController {
-    
+
         let height = pagingViewController.options.menuHeight + NCSharePagingView.headerHeight
         let height = pagingViewController.options.menuHeight + NCSharePagingView.headerHeight
 
 
         switch NCGlobal.NCSharePagingIndex(rawValue: index) {
         switch NCGlobal.NCSharePagingIndex(rawValue: index) {