Browse Source

improvements

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 year ago
parent
commit
6863ed35ce

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -1733,9 +1733,9 @@
 			isa = PBXGroup;
 			children = (
 				F76D3CF42428D0C0005DFA87 /* NCViewerPDF.storyboard */,
-				F76D3CF22428B94E005DFA87 /* NCViewerPDFSearchCell.xib */,
 				F710D1F42405770F00A6033D /* NCViewerPDF.swift */,
 				F76D3CF02428B40E005DFA87 /* NCViewerPDFSearch.swift */,
+				F76D3CF22428B94E005DFA87 /* NCViewerPDFSearchCell.xib */,
 			);
 			path = NCViewerPDF;
 			sourceTree = "<group>";

+ 4 - 9
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.storyboard

@@ -36,19 +36,14 @@
                         <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wnh-nF-AjD">
-                                <rect key="frame" x="0.0" y="21" width="414" height="715"/>
+                            <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wnh-nF-AjD">
+                                <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
+                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                             </view>
                         </subviews>
                         <viewLayoutGuide key="safeArea" id="QiL-bG-Ojl"/>
                         <color key="backgroundColor" systemColor="systemBackgroundColor"/>
-                        <constraints>
-                            <constraint firstItem="wnh-nF-AjD" firstAttribute="leading" secondItem="QiL-bG-Ojl" secondAttribute="leading" id="49g-1K-X2G"/>
-                            <constraint firstAttribute="bottom" secondItem="wnh-nF-AjD" secondAttribute="bottom" id="9yz-fc-kA9"/>
-                            <constraint firstItem="wnh-nF-AjD" firstAttribute="top" secondItem="QiL-bG-Ojl" secondAttribute="top" constant="1" id="Snr-Xx-Peu"/>
-                            <constraint firstItem="QiL-bG-Ojl" firstAttribute="trailing" secondItem="wnh-nF-AjD" secondAttribute="trailing" id="nvb-SR-s8x"/>
-                        </constraints>
                     </view>
                     <connections>
                         <outlet property="pdfContainer" destination="wnh-nF-AjD" id="gAz-vm-JVr"/>
@@ -56,7 +51,7 @@
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="2am-kV-AB1" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
             </objects>
-            <point key="canvasLocation" x="-716" y="779"/>
+            <point key="canvasLocation" x="-717.39130434782612" y="778.53260869565224"/>
         </scene>
         <!--Navigation Controller-->
         <scene sceneID="rmL-pT-QPn">

+ 86 - 51
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift

@@ -47,11 +47,11 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     private let thumbnailViewWidth: CGFloat = 80
     private let thumbnailPadding: CGFloat = 2
     private let animateDuration: TimeInterval = 0.3
-    private let pageViewtopAnchor: CGFloat = UIDevice.current.userInterfaceIdiom == .phone ? 10 : 30
     private let window = UIApplication.shared.connectedScenes.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }.first { $0.isKeyWindow }
 
     private var defaultBackgroundColor: UIColor = .clear
 
+    private var pdfContainerTopAnchor: NSLayoutConstraint?
     private var pdfThumbnailScrollViewTopAnchor: NSLayoutConstraint?
     private var pdfThumbnailScrollViewTrailingAnchor: NSLayoutConstraint?
     private var pdfThumbnailScrollViewWidthAnchor: NSLayoutConstraint?
@@ -74,19 +74,6 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: .label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore))
         navigationItem.title = metadata.fileNameView
 
-        NotificationCenter.default.addObserver(self, selector: #selector(favoriteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteFile), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(uploadStartFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadStartFile), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
-
-        NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(searchText), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuSearchTextPDF), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(goToPage), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
-
-        NotificationCenter.default.addObserver(self, selector: #selector(handlePageChange), name: Notification.Name.PDFViewPageChanged, object: nil)
-
         // Tip
         var preferences = EasyTipView.Preferences()
         preferences.drawing.foregroundColor = .white
@@ -104,35 +91,51 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         preferences.animating.dismissDuration = 1.5
 
         tipView = EasyTipView(text: NSLocalizedString("_tip_pdf_thumbnails_", comment: ""), preferences: preferences, delegate: self)
-    }
 
-    override func viewDidAppear(_ animated: Bool) {
-        super.viewDidAppear(animated)
+        // PDF CONTAINER
 
-        createview()
-        showTip()
-    }
+        pdfContainer.translatesAutoresizingMaskIntoConstraints = false
+        pdfContainerTopAnchor = pdfContainer.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
+        pdfContainerTopAnchor?.isActive = true
+        NSLayoutConstraint.activate([
+            pdfContainer.bottomAnchor.constraint(equalTo: view.bottomAnchor),
+            pdfContainer.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
+            pdfContainer.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)
+        ])
 
-    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
-        super.viewWillTransition(to: size, with: coordinator)
+        // NOTIFIFICATION
 
-        tipView?.dismiss()
+        NotificationCenter.default.addObserver(self, selector: #selector(favoriteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(uploadStartFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadStartFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
 
-        coordinator.animate(alongsideTransition: { context in
-            self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (self.window?.safeAreaInsets.right ?? 0)
-            self.pdfThumbnailScrollView.isHidden = true
-        }, completion: { context in
-            self.setConstraints()
-            self.showTip()
-        })
+        NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(searchText), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuSearchTextPDF), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(goToPage), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
+
+        NotificationCenter.default.addObserver(self, selector: #selector(handlePageChange), name: Notification.Name.PDFViewPageChanged, object: nil)
     }
 
-    @objc func viewUnload() {
+    deinit {
 
-        navigationController?.popViewController(animated: true)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteFile), object: nil)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
+
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuSearchTextPDF), object: nil)
+        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
+
+        NotificationCenter.default.removeObserver(self, name: Notification.Name.PDFViewPageChanged, object: nil)
     }
 
-    func createview() {
+    override func viewDidAppear(_ animated: Bool) {
+        super.viewDidAppear(animated)
 
         // PDF VIEW
 
@@ -154,7 +157,9 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         pdfThumbnailScrollView.showsVerticalScrollIndicator = false
         pdfContainer.addSubview(pdfThumbnailScrollView)
 
-        pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: pdfContainer.bottomAnchor).isActive = true
+        NSLayoutConstraint.activate([
+            pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: pdfContainer.bottomAnchor)
+        ])
         pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: pdfContainer.safeAreaLayoutGuide.topAnchor)
         pdfThumbnailScrollViewTopAnchor?.isActive = true
         pdfThumbnailScrollViewTrailingAnchor = pdfThumbnailScrollView.trailingAnchor.constraint(equalTo: pdfContainer.trailingAnchor)
@@ -198,7 +203,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         pdfContainer.addSubview(pageView)
 
         NSLayoutConstraint.activate([
-            pageView.topAnchor.constraint(equalTo: pdfContainer.safeAreaLayoutGuide.topAnchor, constant: pageViewtopAnchor),
+            pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 15),
             pageView.heightAnchor.constraint(equalToConstant: 30),
             pageView.leftAnchor.constraint(equalTo: pdfContainer.safeAreaLayoutGuide.leftAnchor, constant: 10)
         ])
@@ -242,23 +247,30 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         swipePdfThumbnailScrollView.direction = .right
         pdfThumbnailScrollView.addGestureRecognizer(swipePdfThumbnailScrollView)
 
-        setConstraints()
+        // FUNC
+
+        setThumbnailConstraints()
         handlePageChange()
+        showTip()
     }
 
-    deinit {
+    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
+        super.viewWillTransition(to: size, with: coordinator)
 
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteFile), object: nil)
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
+        tipView?.dismiss()
 
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuSearchTextPDF), object: nil)
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
+        coordinator.animate(alongsideTransition: { context in
+            self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (self.window?.safeAreaInsets.right ?? 0)
+            self.pdfThumbnailScrollView.isHidden = true
+        }, completion: { context in
+            self.setThumbnailConstraints()
+            self.showTip()
+        })
+    }
 
-        NotificationCenter.default.removeObserver(self, name: Notification.Name.PDFViewPageChanged, object: nil)
+    @objc func viewUnload() {
+
+        navigationController?.popViewController(animated: true)
     }
 
     // MARK: - Tip
@@ -399,16 +411,24 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     @objc func tapPdfView(_ recognizer: UITapGestureRecognizer) {
 
         if pdfThumbnailScrollView.isHidden {
-
             if navigationController?.isNavigationBarHidden ?? false {
                 navigationController?.setNavigationBarHidden(false, animated: true)
-                pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: pdfContainer.safeAreaLayoutGuide.topAnchor)
             } else {
                 navigationController?.setNavigationBarHidden(true, animated: true)
-                pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: pdfContainer.topAnchor)
             }
         }
 
+        UIView.animate(withDuration: animateDuration) {
+            self.pdfContainerTopAnchor?.isActive = false
+        } completion: { _ in
+            if let barHidden = self.navigationController?.isNavigationBarHidden, barHidden {
+                self.pdfContainerTopAnchor = self.pdfContainer.topAnchor.constraint(equalTo: self.view.topAnchor)
+            } else {
+                self.pdfContainerTopAnchor = self.pdfContainer.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor)
+            }
+            self.pdfContainerTopAnchor?.isActive = true
+        }
+
         handlePageChange()
         closePdfThumbnail()
     }
@@ -421,8 +441,8 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     }
 
     @objc func gestureOpenPdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) {
-        guard let pdfDocument = pdfView.document, !pdfDocument.isLocked else { return }
 
+        guard let pdfDocument = pdfView.document, !pdfDocument.isLocked else { return }
         OpenPdfThumbnail()
     }
 
@@ -436,28 +456,43 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
             NCManageDatabase.shared.addTip(NCGlobal.shared.tipNCViewerPDFThumbnail)
             self.tipView = nil
         }
+
         self.pdfThumbnailScrollView.isHidden = false
         self.pdfThumbnailScrollViewWidthAnchor?.constant = thumbnailViewWidth + (window?.safeAreaInsets.right ?? 0)
+
+        self.pdfThumbnailScrollViewTopAnchor?.isActive = false
+        if let barHidden = self.navigationController?.isNavigationBarHidden, barHidden {
+            self.pdfThumbnailScrollViewTopAnchor = self.pdfThumbnailScrollView.topAnchor.constraint(equalTo: self.view.topAnchor)
+        } else {
+            self.pdfThumbnailScrollViewTopAnchor = self.pdfThumbnailScrollView.topAnchor.constraint(equalTo: self.pdfContainer.safeAreaLayoutGuide.topAnchor)
+        }
+        self.pdfThumbnailScrollViewTopAnchor?.isActive = true
+
         UIView.animate(withDuration: animateDuration, animations: {
+
             self.pdfThumbnailScrollViewTrailingAnchor?.constant = 0
             self.pdfContainer.layoutIfNeeded()
         })
     }
 
     func closePdfThumbnail() {
+
         guard !self.pdfThumbnailScrollView.isHidden else { return }
 
         UIView.animate(withDuration: animateDuration) {
+
             self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (self.window?.safeAreaInsets.right ?? 0)
             self.pdfContainer.layoutIfNeeded()
+
         } completion: { _ in
+
             self.pdfThumbnailScrollView.isHidden = true
         }
     }
 
     // MARK: -
 
-    func setConstraints() {
+    func setThumbnailConstraints() {
 
         let widthThumbnail = thumbnailViewWidth + (window?.safeAreaInsets.right ?? 0)