From f5c7780ff24e70467000b4dc69fa63bdd98ec965 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Fri, 29 Apr 2022 11:41:50 +0200 Subject: Improved GUI Signed-off-by: marinofaggiana --- iOSClient/Menu/NCViewer+Menu.swift | 25 --- iOSClient/NCGlobal.swift | 1 - iOSClient/Utility/CCUtility.h | 3 - iOSClient/Utility/CCUtility.m | 17 -- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 298 ++++++++++++++++++------- 5 files changed, 214 insertions(+), 130 deletions(-) diff --git a/iOSClient/Menu/NCViewer+Menu.swift b/iOSClient/Menu/NCViewer+Menu.swift index e85354bce..fb49825fe 100644 --- a/iOSClient/Menu/NCViewer+Menu.swift +++ b/iOSClient/Menu/NCViewer+Menu.swift @@ -226,31 +226,6 @@ extension NCViewer { ) ) - var title = "" - var icon = UIImage() - - if CCUtility.getPDFDisplayDirection() == .horizontal { - title = NSLocalizedString("_pdf_vertical_", comment: "") - icon = UIImage(named: "pdf-vertical")!.image(color: NCBrandColor.shared.gray, size: 50) - } else { - title = NSLocalizedString("_pdf_horizontal_", comment: "") - icon = UIImage(named: "pdf-horizontal")!.image(color: NCBrandColor.shared.gray, size: 50) - } - - actions.append( - NCMenuAction( - title: title, - icon: icon, - action: { _ in - if CCUtility.getPDFDisplayDirection() == .horizontal { - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuPDFDisplayDirection, userInfo: ["direction": PDFDisplayDirection.vertical]) - } else { - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuPDFDisplayDirection, userInfo: ["direction": PDFDisplayDirection.horizontal]) - } - } - ) - ) - actions.append( NCMenuAction( title: NSLocalizedString("_go_to_page_", comment: ""), diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index b70b1559e..892f004bc 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -344,7 +344,6 @@ class NCGlobal: NSObject { let notificationCenterFavoriteFile = "favoriteFile" // userInfo: ocId let notificationCenterMenuSearchTextPDF = "menuSearchTextPDF" - let notificationCenterMenuPDFDisplayDirection = "menuPDFDisplayDirection" // userInfo: direction let notificationCenterMenuGotToPageInPDF = "menuGotToPageInPDF" let notificationCenterMenuDetailClose = "menuDetailClose" diff --git a/iOSClient/Utility/CCUtility.h b/iOSClient/Utility/CCUtility.h index e2aee0e86..3d5eee7e8 100644 --- a/iOSClient/Utility/CCUtility.h +++ b/iOSClient/Utility/CCUtility.h @@ -180,9 +180,6 @@ + (NSInteger)getCleanUpDay; + (void)setCleanUpDay:(NSInteger)days; -+ (PDFDisplayDirection)getPDFDisplayDirection; -+ (void)setPDFDisplayDirection:(PDFDisplayDirection)direction; - + (BOOL)getPrivacyScreenEnabled; + (void)setPrivacyScreenEnabled:(BOOL)set; diff --git a/iOSClient/Utility/CCUtility.m b/iOSClient/Utility/CCUtility.m index 0a2a97a6f..df4325707 100644 --- a/iOSClient/Utility/CCUtility.m +++ b/iOSClient/Utility/CCUtility.m @@ -715,23 +715,6 @@ [UICKeyChainStore setString:daysString forKey:@"cleanUpDay" service:NCGlobal.shared.serviceShareKeyChain]; } -+ (PDFDisplayDirection)getPDFDisplayDirection -{ - NSString *direction = [UICKeyChainStore stringForKey:@"PDFDisplayDirection" service:NCGlobal.shared.serviceShareKeyChain]; - - if (direction == nil) { - return kPDFDisplayDirectionVertical; - } else { - return [direction integerValue]; - } -} - -+ (void)setPDFDisplayDirection:(PDFDisplayDirection)direction -{ - NSString *directionString = [@(direction) stringValue]; - [UICKeyChainStore setString:directionString forKey:@"PDFDisplayDirection" service:NCGlobal.shared.serviceShareKeyChain]; -} - + (BOOL)getPrivacyScreenEnabled { NSString *valueString = [UICKeyChainStore stringForKey:@"privacyScreen" service:NCGlobal.shared.serviceShareKeyChain]; diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index f00dabc1e..86a1be4eb 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -23,21 +23,35 @@ import UIKit import PDFKit +import SwiftUI -class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate { +class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecognizerDelegate { - let appDelegate = UIApplication.shared.delegate as! AppDelegate var metadata = tableMetadata() var imageIcon: UIImage? + private let appDelegate = UIApplication.shared.delegate as! AppDelegate + private var filePath = "" + private var pdfView = PDFView() - private var thumbnailViewHeight: CGFloat = 40 + private var pdfThumbnailScrollView = UIScrollView() private var pdfThumbnailView = PDFThumbnailView() private var pdfDocument: PDFDocument? private let pageView = UIView() private let pageViewLabel = UILabel() + + private let thumbnailViewHeight: CGFloat = 70 + private let thumbnailViewWidth: CGFloat = 80 + private let thumbnailPadding: CGFloat = 2 + private let animateDuration: TimeInterval = 0.3 + + private var defaultBackgroundColor: UIColor = .clear + + private var pdfThumbnailScrollViewleadingAnchor: NSLayoutConstraint? + private var pdfThumbnailScrollViewWidthAnchor: NSLayoutConstraint? + private var pdfThumbnailViewleadingAnchor: NSLayoutConstraint? + private var pageViewLeftAnchor: NSLayoutConstraint? private var pageViewWidthAnchor: NSLayoutConstraint? - private var filePath = "" // MARK: - View Life Cycle @@ -48,80 +62,129 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate { override func viewDidLoad() { filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)! - - pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) pdfDocument = PDFDocument(url: URL(fileURLWithPath: filePath)) + let pageCount = CGFloat(pdfDocument?.pageCount ?? 0) + defaultBackgroundColor = pdfView.backgroundColor + view.backgroundColor = defaultBackgroundColor + + navigationController?.interactivePopGestureRecognizer?.isEnabled = false + navigationController?.navigationBar.prefersLargeTitles = false + + navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: NCBrandColor.shared.label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore)) + navigationItem.title = metadata.fileNameView + // PDF VIEW + + if UIDevice.current.userInterfaceIdiom == .pad { + pdfView = PDFView(frame: CGRect(x: thumbnailViewWidth, y: 0, width: view.frame.width - thumbnailViewWidth, height: view.frame.height)) + } else { + pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) + } + pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleBottomMargin] pdfView.document = pdfDocument - pdfView.backgroundColor = NCBrandColor.shared.systemBackground pdfView.displayMode = .singlePageContinuous pdfView.autoScales = true - pdfView.displayDirection = CCUtility.getPDFDisplayDirection() - pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleBottomMargin] - pdfView.usePageViewController(true, withViewOptions: nil) - + pdfView.displayDirection = .vertical + pdfView.maxScaleFactor = 4.0 + pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit view.addSubview(pdfView) + // PDF THUMBNAIL + + pdfThumbnailScrollView.translatesAutoresizingMaskIntoConstraints = false + pdfThumbnailScrollView.backgroundColor = defaultBackgroundColor + pdfThumbnailScrollView.showsVerticalScrollIndicator = false + view.addSubview(pdfThumbnailScrollView) + + NSLayoutConstraint.activate([ + pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.topAnchor), + pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor) + ]) + pdfThumbnailScrollViewleadingAnchor = pdfThumbnailScrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor) + pdfThumbnailScrollViewleadingAnchor?.isActive = true + pdfThumbnailScrollViewWidthAnchor = pdfThumbnailScrollView.widthAnchor.constraint(equalToConstant: 0) + pdfThumbnailScrollViewWidthAnchor?.isActive = true + pdfThumbnailView.translatesAutoresizingMaskIntoConstraints = false pdfThumbnailView.pdfView = pdfView - pdfThumbnailView.layoutMode = .horizontal - pdfThumbnailView.thumbnailSize = CGSize(width: 40, height: thumbnailViewHeight) + pdfThumbnailView.layoutMode = .vertical + pdfThumbnailView.thumbnailSize = CGSize(width: thumbnailViewHeight, height: thumbnailViewHeight) pdfThumbnailView.backgroundColor = .clear - // pdfThumbnailView.layer.shadowOffset.height = -5 - // pdfThumbnailView.layer.shadowOpacity = 0.25 - - view.addSubview(pdfThumbnailView) - - pdfThumbnailView.heightAnchor.constraint(equalToConstant: thumbnailViewHeight).isActive = true - pdfThumbnailView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true - pdfThumbnailView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true - pdfThumbnailView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true + if UIDevice.current.userInterfaceIdiom == .pad { + self.pdfThumbnailScrollView.isHidden = false + } else { + self.pdfThumbnailScrollView.isHidden = true + } + pdfThumbnailScrollView.addSubview(pdfThumbnailView) + + NSLayoutConstraint.activate([ + pdfThumbnailView.topAnchor.constraint(equalTo: pdfThumbnailScrollView.topAnchor), + pdfThumbnailView.bottomAnchor.constraint(equalTo: pdfThumbnailScrollView.bottomAnchor), + pdfThumbnailView.trailingAnchor.constraint(equalTo: pdfThumbnailScrollView.trailingAnchor), + pdfThumbnailView.widthAnchor.constraint(equalToConstant: thumbnailViewWidth) + ]) + pdfThumbnailViewleadingAnchor = pdfThumbnailView.leadingAnchor.constraint(equalTo: pdfThumbnailScrollView.leadingAnchor) + pdfThumbnailViewleadingAnchor?.isActive = true + let contentViewCenterY = pdfThumbnailView.centerYAnchor.constraint(equalTo: pdfThumbnailScrollView.centerYAnchor) + contentViewCenterY.priority = .defaultLow + let contentViewHeight = pdfThumbnailView.heightAnchor.constraint(equalToConstant: CGFloat(pageCount * thumbnailViewHeight) + CGFloat(pageCount * thumbnailPadding) + (thumbnailPadding * 2)) + contentViewHeight.priority = .defaultLow + NSLayoutConstraint.activate([ + contentViewCenterY, + contentViewHeight + ]) + + // COUNTER PDF PAGE VIEW pageView.translatesAutoresizingMaskIntoConstraints = false pageView.layer.cornerRadius = 10 - pageView.backgroundColor = NCBrandColor.shared.systemBackground.withAlphaComponent( - UIAccessibility.isReduceTransparencyEnabled ? 1 : 0.5 - ) - + pageView.backgroundColor = UIColor.gray.withAlphaComponent(0.3) view.addSubview(pageView) - pageView.heightAnchor.constraint(equalToConstant: 30).isActive = true + NSLayoutConstraint.activate([ + pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 10), + pageView.heightAnchor.constraint(equalToConstant: 30) + ]) + pageViewLeftAnchor = pageView.leftAnchor.constraint(equalTo: view.leftAnchor) + pageViewLeftAnchor?.isActive = true pageViewWidthAnchor = pageView.widthAnchor.constraint(equalToConstant: 10) pageViewWidthAnchor?.isActive = true - pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 4).isActive = true - pageView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 7).isActive = true pageViewLabel.translatesAutoresizingMaskIntoConstraints = false pageViewLabel.textAlignment = .center - pageViewLabel.textColor = NCBrandColor.shared.label - + pageViewLabel.textColor = .gray pageView.addSubview(pageViewLabel) - pageViewLabel.leftAnchor.constraint(equalTo: pageView.leftAnchor).isActive = true - pageViewLabel.rightAnchor.constraint(equalTo: pageView.rightAnchor).isActive = true - pageViewLabel.topAnchor.constraint(equalTo: pageView.topAnchor).isActive = true - pageViewLabel.bottomAnchor.constraint(equalTo: pageView.bottomAnchor).isActive = true + NSLayoutConstraint.activate([ + pageViewLabel.topAnchor.constraint(equalTo: pageView.topAnchor), + pageViewLabel.leftAnchor.constraint(equalTo: pageView.leftAnchor), + pageViewLabel.rightAnchor.constraint(equalTo: pageView.rightAnchor), + pageViewLabel.bottomAnchor.constraint(equalTo: pageView.bottomAnchor) + ]) - pdfView.backgroundColor = NCBrandColor.shared.systemBackground - pdfView.layoutIfNeeded() - handlePageChange() + // GESTURE - let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTap(_:))) - tapGesture.numberOfTapsRequired = 1 - pdfView.addGestureRecognizer(tapGesture) + let tapPdfView = UITapGestureRecognizer(target: self, action: #selector(tapPdfView)) + tapPdfView.numberOfTapsRequired = 1 + pdfView.addGestureRecognizer(tapPdfView) // recognize single / double tap for gesture in pdfView.gestureRecognizers! { - tapGesture.require(toFail: gesture) + tapPdfView.require(toFail: gesture) } - } - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) + let swipeLeftPdfView = UISwipeGestureRecognizer(target: self, action: #selector(gestureClosePdfThumbnail)) + swipeLeftPdfView.direction = .left + pdfView.addGestureRecognizer(swipeLeftPdfView) - appDelegate.activeViewController = self + let swipeLeftpdfThumbnailScrollView = UISwipeGestureRecognizer(target: self, action: #selector(gestureClosePdfThumbnail)) + swipeLeftpdfThumbnailScrollView.direction = .left + pdfThumbnailScrollView.addGestureRecognizer(swipeLeftpdfThumbnailScrollView) + + let edgeLeftPdfView = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(gestureOpenPdfThumbnail)) + edgeLeftPdfView.edges = .left + pdfView.addGestureRecognizer(edgeLeftPdfView) - // 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) @@ -130,19 +193,34 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate { 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(direction(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuPDFDisplayDirection), 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) - // - navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: NCBrandColor.shared.label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore)) + setConstraints() + handlePageChange() + } - navigationController?.navigationBar.prefersLargeTitles = true - navigationItem.title = metadata.fileNameView + @objc func viewUnload() { + + navigationController?.popViewController(animated: true) + } + + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) + + coordinator.animate(alongsideTransition: { context in + if UIDevice.current.userInterfaceIdiom == .phone { + self.pdfThumbnailScrollViewleadingAnchor?.constant = -self.thumbnailViewWidth + self.pageViewLeftAnchor?.constant = 10 + self.pdfThumbnailScrollView.isHidden = true + } + }, completion: { context in + self.setConstraints() + }) } - override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) + deinit { 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) @@ -152,17 +230,11 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate { 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.notificationCenterMenuPDFDisplayDirection), 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) } - @objc func viewUnload() { - - navigationController?.popViewController(animated: true) - } - // MARK: - NotificationCenter @objc func uploadedFile(_ notification: NSNotification) { @@ -236,17 +308,6 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate { self.present(navigaionController, animated: true) } - @objc func direction(_ notification: NSNotification) { - - if let userInfo = notification.userInfo as NSDictionary? { - if let direction = userInfo["direction"] as? PDFDisplayDirection { - pdfView.displayDirection = direction - CCUtility.setPDFDisplayDirection(direction) - handlePageChange() - } - } - } - @objc func goToPage() { guard let pdfDocument = pdfView.document else { return } @@ -278,39 +339,108 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate { // MARK: - Gesture Recognizer - @objc func didTap(_ recognizer: UITapGestureRecognizer) { + @objc func tapPdfView(_ recognizer: UITapGestureRecognizer) { if navigationController?.isNavigationBarHidden ?? false { - navigationController?.setNavigationBarHidden(false, animated: false) - pdfThumbnailView.isHidden = false - pdfView.backgroundColor = NCBrandColor.shared.systemBackground - } else { - - let point = recognizer.location(in: pdfView) - if point.y > pdfView.frame.height - thumbnailViewHeight { return } - navigationController?.setNavigationBarHidden(true, animated: false) - pdfThumbnailView.isHidden = true - pdfView.backgroundColor = .black } + } - handlePageChange() + @objc func gestureOpenPdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) { + + openPdfThumbnail() + } + + @objc func gestureClosePdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) { + + if recognizer.state == .recognized { + closePdfThumbnail() + } } // MARK: - + func setConstraints() { + + let widthThumbnail = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) + + UIView.animate(withDuration: animateDuration, animations: { + if UIDevice.current.userInterfaceIdiom == .phone { + self.pdfThumbnailScrollView.isHidden = true + self.pdfThumbnailScrollViewleadingAnchor?.constant = -widthThumbnail + self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail + self.pageViewLeftAnchor?.constant = 10 + } else { + self.pdfThumbnailScrollViewleadingAnchor?.constant = 0 + self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail + self.pageViewLeftAnchor?.constant = widthThumbnail + 10 + } + self.pdfThumbnailViewleadingAnchor?.constant = (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) + self.view.layoutIfNeeded() + self.pdfView.autoScales = true + }) + } + + func openPdfThumbnail() { + + let widthThumbnail = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) + + if UIDevice.current.userInterfaceIdiom == .phone && self.pdfThumbnailScrollView.isHidden { + self.pdfThumbnailScrollView.isHidden = false + self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail + UIView.animate(withDuration: animateDuration, animations: { + self.pdfThumbnailScrollViewleadingAnchor?.constant = 0 + self.pageViewLeftAnchor?.constant = widthThumbnail + 10 + self.view.layoutIfNeeded() + }) + } + } + + func closePdfThumbnail() { + + let widthThumbnail = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) + + if UIDevice.current.userInterfaceIdiom == .phone && !self.pdfThumbnailScrollView.isHidden { + UIView.animate(withDuration: animateDuration) { + self.pdfThumbnailScrollViewleadingAnchor?.constant = -widthThumbnail + self.pageViewLeftAnchor?.constant = 10 + self.view.layoutIfNeeded() + } completion: { _ in + self.pdfThumbnailScrollView.isHidden = true + } + } + } + @objc func handlePageChange() { guard let curPage = pdfView.currentPage?.pageRef?.pageNumber else { pageView.alpha = 0; return } guard let totalPages = pdfView.document?.pageCount else { return } + let visibleRect = CGRect(x: pdfThumbnailScrollView.contentOffset.x, y: pdfThumbnailScrollView.contentOffset.y, width: pdfThumbnailScrollView.bounds.size.width, height: pdfThumbnailScrollView.bounds.size.height) + let centerPoint = CGPoint(x: visibleRect.size.width/2, y: visibleRect.size.height/2) + let currentPageY = CGFloat(curPage) * thumbnailViewHeight + CGFloat(curPage) * thumbnailPadding + var gotoY = currentPageY - centerPoint.y + + let startY = visibleRect.origin.y < 0 ? 0 : (visibleRect.origin.y + thumbnailViewHeight) + let endY = visibleRect.origin.y + visibleRect.height + thumbnailViewHeight + + if currentPageY < startY { + if gotoY < 0 { gotoY = -UIApplication.shared.statusBarFrame.height } + pdfThumbnailScrollView.setContentOffset(CGPoint(x: 0, y: gotoY), animated: true) + } else if currentPageY > endY { + if gotoY > pdfThumbnailView.frame.height - visibleRect.height { gotoY = pdfThumbnailView.frame.height - visibleRect.height} + pdfThumbnailScrollView.setContentOffset(CGPoint(x: 0, y: gotoY), animated: true) + } else { + print("visible") + } + pageView.alpha = 1 pageViewLabel.text = String(curPage) + " " + NSLocalizedString("_of_", comment: "") + " " + String(totalPages) pageViewWidthAnchor?.constant = pageViewLabel.intrinsicContentSize.width + 10 - UIView.animate(withDuration: 1.0, delay: 3.0, animations: { + UIView.animate(withDuration: 1.0, delay: 2.5, animations: { self.pageView.alpha = 0 }) } -- cgit v1.2.3 From 10d47a73af01ff09701d5353f346f913ee7967b9 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Fri, 29 Apr 2022 12:23:38 +0200 Subject: Improved algorithm scroll Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index 86a1be4eb..f076fbd2d 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -427,7 +427,13 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni let endY = visibleRect.origin.y + visibleRect.height + thumbnailViewHeight if currentPageY < startY { - if gotoY < 0 { gotoY = -UIApplication.shared.statusBarFrame.height } + if gotoY < 0 { + if navigationController?.isNavigationBarHidden ?? true { + gotoY = -UIApplication.shared.statusBarFrame.height + } else { + gotoY = (UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0) == 0 ? -UIApplication.shared.statusBarFrame.height : -((UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0) + UIApplication.shared.statusBarFrame.height) + } + } pdfThumbnailScrollView.setContentOffset(CGPoint(x: 0, y: gotoY), animated: true) } else if currentPageY > endY { if gotoY > pdfThumbnailView.frame.height - visibleRect.height { gotoY = pdfThumbnailView.frame.height - visibleRect.height} -- cgit v1.2.3 From 3def6e153028046045c13c6d205fb43b80760bdf Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Fri, 29 Apr 2022 12:31:39 +0200 Subject: Clear Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index f076fbd2d..c72af9d07 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -428,15 +428,19 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni if currentPageY < startY { if gotoY < 0 { + let safeAreaInsetsTop = UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0 + let statusBarFrameHeight = UIApplication.shared.statusBarFrame.height if navigationController?.isNavigationBarHidden ?? true { - gotoY = -UIApplication.shared.statusBarFrame.height + gotoY = -statusBarFrameHeight } else { - gotoY = (UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0) == 0 ? -UIApplication.shared.statusBarFrame.height : -((UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0) + UIApplication.shared.statusBarFrame.height) + gotoY = safeAreaInsetsTop == 0 ? -statusBarFrameHeight : -(safeAreaInsetsTop + statusBarFrameHeight) } } pdfThumbnailScrollView.setContentOffset(CGPoint(x: 0, y: gotoY), animated: true) } else if currentPageY > endY { - if gotoY > pdfThumbnailView.frame.height - visibleRect.height { gotoY = pdfThumbnailView.frame.height - visibleRect.height} + if gotoY > pdfThumbnailView.frame.height - visibleRect.height { + gotoY = pdfThumbnailView.frame.height - visibleRect.height + } pdfThumbnailScrollView.setContentOffset(CGPoint(x: 0, y: gotoY), animated: true) } else { print("visible") -- cgit v1.2.3 From c7bbe7b433ff6900b3d16d1515a6c4eb99c969bb Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Sat, 30 Apr 2022 12:49:48 +0200 Subject: Improveds Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index c72af9d07..355ba4b33 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -97,7 +97,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni view.addSubview(pdfThumbnailScrollView) NSLayoutConstraint.activate([ - pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.topAnchor), + pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) pdfThumbnailScrollViewleadingAnchor = pdfThumbnailScrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor) @@ -342,9 +342,9 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni @objc func tapPdfView(_ recognizer: UITapGestureRecognizer) { if navigationController?.isNavigationBarHidden ?? false { - navigationController?.setNavigationBarHidden(false, animated: false) + navigationController?.setNavigationBarHidden(false, animated: true) } else { - navigationController?.setNavigationBarHidden(true, animated: false) + navigationController?.setNavigationBarHidden(true, animated: true) } } @@ -427,15 +427,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni let endY = visibleRect.origin.y + visibleRect.height + thumbnailViewHeight if currentPageY < startY { - if gotoY < 0 { - let safeAreaInsetsTop = UIApplication.shared.keyWindow?.safeAreaInsets.top ?? 0 - let statusBarFrameHeight = UIApplication.shared.statusBarFrame.height - if navigationController?.isNavigationBarHidden ?? true { - gotoY = -statusBarFrameHeight - } else { - gotoY = safeAreaInsetsTop == 0 ? -statusBarFrameHeight : -(safeAreaInsetsTop + statusBarFrameHeight) - } - } + if gotoY < 0 { gotoY = 0 } pdfThumbnailScrollView.setContentOffset(CGPoint(x: 0, y: gotoY), animated: true) } else if currentPageY > endY { if gotoY > pdfThumbnailView.frame.height - visibleRect.height { -- cgit v1.2.3 From d1a15fb22609fa32e3e3733e2d829e2946f0d085 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Sat, 30 Apr 2022 12:50:37 +0200 Subject: Improveds Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index 355ba4b33..d46d17c1b 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -333,6 +333,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni // MARK: - Action @objc func openMenuMore() { + if imageIcon == nil { imageIcon = UIImage(named: "file_pdf") } NCViewer.shared.toggleMenu(viewController: self, metadata: metadata, webView: false, imageIcon: imageIcon) } -- cgit v1.2.3 From 0e9b4cec36bc901be4776344f872070cad253e5a Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Sat, 30 Apr 2022 18:02:37 +0200 Subject: Improveds Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index d46d17c1b..6846daf0d 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -75,20 +75,26 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni // PDF VIEW - if UIDevice.current.userInterfaceIdiom == .pad { - pdfView = PDFView(frame: CGRect(x: thumbnailViewWidth, y: 0, width: view.frame.width - thumbnailViewWidth, height: view.frame.height)) - } else { - pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) - } - pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleBottomMargin] + pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) + pdfView.translatesAutoresizingMaskIntoConstraints = false pdfView.document = pdfDocument pdfView.displayMode = .singlePageContinuous - pdfView.autoScales = true pdfView.displayDirection = .vertical pdfView.maxScaleFactor = 4.0 pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit view.addSubview(pdfView) + NSLayoutConstraint.activate([ + pdfView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), + pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), + pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor) + ]) + if UIDevice.current.userInterfaceIdiom == .pad { + pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: thumbnailViewWidth).isActive = true + } else { + pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true + } + // PDF THUMBNAIL pdfThumbnailScrollView.translatesAutoresizingMaskIntoConstraints = false @@ -98,7 +104,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni NSLayoutConstraint.activate([ pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), - pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor) + pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) ]) pdfThumbnailScrollViewleadingAnchor = pdfThumbnailScrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor) pdfThumbnailScrollViewleadingAnchor?.isActive = true @@ -127,7 +133,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni pdfThumbnailViewleadingAnchor?.isActive = true let contentViewCenterY = pdfThumbnailView.centerYAnchor.constraint(equalTo: pdfThumbnailScrollView.centerYAnchor) contentViewCenterY.priority = .defaultLow - let contentViewHeight = pdfThumbnailView.heightAnchor.constraint(equalToConstant: CGFloat(pageCount * thumbnailViewHeight) + CGFloat(pageCount * thumbnailPadding) + (thumbnailPadding * 2)) + let contentViewHeight = pdfThumbnailView.heightAnchor.constraint(equalToConstant: CGFloat(pageCount * thumbnailViewHeight) + CGFloat(pageCount * thumbnailPadding) + 30) contentViewHeight.priority = .defaultLow NSLayoutConstraint.activate([ contentViewCenterY, @@ -185,6 +191,10 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni edgeLeftPdfView.edges = .left pdfView.addGestureRecognizer(edgeLeftPdfView) + let edgeLeftView = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(gestureOpenPdfThumbnail)) + edgeLeftView.edges = .left + view.addGestureRecognizer(edgeLeftView) + 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) @@ -333,7 +343,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni // MARK: - Action @objc func openMenuMore() { - + if imageIcon == nil { imageIcon = UIImage(named: "file_pdf") } NCViewer.shared.toggleMenu(viewController: self, metadata: metadata, webView: false, imageIcon: imageIcon) } -- cgit v1.2.3 From ed9a94115d9c2c625550cd827ca6d29a3a759527 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Sat, 30 Apr 2022 18:05:55 +0200 Subject: Improvements Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index 6846daf0d..86f44401d 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -78,6 +78,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) pdfView.translatesAutoresizingMaskIntoConstraints = false pdfView.document = pdfDocument + pdfView.autoScales = true pdfView.displayMode = .singlePageContinuous pdfView.displayDirection = .vertical pdfView.maxScaleFactor = 4.0 -- cgit v1.2.3 From d289cfd65e41e368d2fc7e859a9fbe25f6c6257d Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Mon, 2 May 2022 10:03:05 +0200 Subject: Move thumbnail to right Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 114 ++++++++++--------------- 1 file changed, 44 insertions(+), 70 deletions(-) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index 86f44401d..af1941564 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -47,10 +47,8 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni private var defaultBackgroundColor: UIColor = .clear - private var pdfThumbnailScrollViewleadingAnchor: NSLayoutConstraint? + private var pdfThumbnailScrollViewTrailingAnchor: NSLayoutConstraint? private var pdfThumbnailScrollViewWidthAnchor: NSLayoutConstraint? - private var pdfThumbnailViewleadingAnchor: NSLayoutConstraint? - private var pageViewLeftAnchor: NSLayoutConstraint? private var pageViewWidthAnchor: NSLayoutConstraint? // MARK: - View Life Cycle @@ -67,9 +65,6 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni defaultBackgroundColor = pdfView.backgroundColor view.backgroundColor = defaultBackgroundColor - navigationController?.interactivePopGestureRecognizer?.isEnabled = false - navigationController?.navigationBar.prefersLargeTitles = false - navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: NCBrandColor.shared.label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore)) navigationItem.title = metadata.fileNameView @@ -88,12 +83,12 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni NSLayoutConstraint.activate([ pdfView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), - pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor) + pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor) ]) if UIDevice.current.userInterfaceIdiom == .pad { - pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: thumbnailViewWidth).isActive = true + pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -thumbnailViewWidth).isActive = true } else { - pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true + pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true } // PDF THUMBNAIL @@ -107,9 +102,9 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) ]) - pdfThumbnailScrollViewleadingAnchor = pdfThumbnailScrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor) - pdfThumbnailScrollViewleadingAnchor?.isActive = true - pdfThumbnailScrollViewWidthAnchor = pdfThumbnailScrollView.widthAnchor.constraint(equalToConstant: 0) + pdfThumbnailScrollViewTrailingAnchor = pdfThumbnailScrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor) + pdfThumbnailScrollViewTrailingAnchor?.isActive = true + pdfThumbnailScrollViewWidthAnchor = pdfThumbnailScrollView.widthAnchor.constraint(equalToConstant: thumbnailViewWidth) pdfThumbnailScrollViewWidthAnchor?.isActive = true pdfThumbnailView.translatesAutoresizingMaskIntoConstraints = false @@ -127,11 +122,10 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni NSLayoutConstraint.activate([ pdfThumbnailView.topAnchor.constraint(equalTo: pdfThumbnailScrollView.topAnchor), pdfThumbnailView.bottomAnchor.constraint(equalTo: pdfThumbnailScrollView.bottomAnchor), - pdfThumbnailView.trailingAnchor.constraint(equalTo: pdfThumbnailScrollView.trailingAnchor), + pdfThumbnailView.leadingAnchor.constraint(equalTo: pdfThumbnailScrollView.leadingAnchor), + pdfThumbnailView.leadingAnchor.constraint(equalTo: pdfThumbnailScrollView.trailingAnchor, constant: (UIApplication.shared.keyWindow?.safeAreaInsets.left ?? 0)), pdfThumbnailView.widthAnchor.constraint(equalToConstant: thumbnailViewWidth) ]) - pdfThumbnailViewleadingAnchor = pdfThumbnailView.leadingAnchor.constraint(equalTo: pdfThumbnailScrollView.leadingAnchor) - pdfThumbnailViewleadingAnchor?.isActive = true let contentViewCenterY = pdfThumbnailView.centerYAnchor.constraint(equalTo: pdfThumbnailScrollView.centerYAnchor) contentViewCenterY.priority = .defaultLow let contentViewHeight = pdfThumbnailView.heightAnchor.constraint(equalToConstant: CGFloat(pageCount * thumbnailViewHeight) + CGFloat(pageCount * thumbnailPadding) + 30) @@ -150,10 +144,9 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni NSLayoutConstraint.activate([ pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 10), - pageView.heightAnchor.constraint(equalToConstant: 30) + pageView.heightAnchor.constraint(equalToConstant: 30), + pageView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 10) ]) - pageViewLeftAnchor = pageView.leftAnchor.constraint(equalTo: view.leftAnchor) - pageViewLeftAnchor?.isActive = true pageViewWidthAnchor = pageView.widthAnchor.constraint(equalToConstant: 10) pageViewWidthAnchor?.isActive = true @@ -180,21 +173,21 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni tapPdfView.require(toFail: gesture) } - let swipeLeftPdfView = UISwipeGestureRecognizer(target: self, action: #selector(gestureClosePdfThumbnail)) - swipeLeftPdfView.direction = .left - pdfView.addGestureRecognizer(swipeLeftPdfView) + let swipePdfView = UISwipeGestureRecognizer(target: self, action: #selector(gestureClosePdfThumbnail)) + swipePdfView.direction = .right + pdfView.addGestureRecognizer(swipePdfView) - let swipeLeftpdfThumbnailScrollView = UISwipeGestureRecognizer(target: self, action: #selector(gestureClosePdfThumbnail)) - swipeLeftpdfThumbnailScrollView.direction = .left - pdfThumbnailScrollView.addGestureRecognizer(swipeLeftpdfThumbnailScrollView) + let swipePdfThumbnailScrollView = UISwipeGestureRecognizer(target: self, action: #selector(gestureClosePdfThumbnail)) + swipePdfThumbnailScrollView.direction = .right + pdfThumbnailScrollView.addGestureRecognizer(swipePdfThumbnailScrollView) - let edgeLeftPdfView = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(gestureOpenPdfThumbnail)) - edgeLeftPdfView.edges = .left - pdfView.addGestureRecognizer(edgeLeftPdfView) + let edgePdfView = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(gestureOpenPdfThumbnail)) + edgePdfView.edges = .right + pdfView.addGestureRecognizer(edgePdfView) - let edgeLeftView = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(gestureOpenPdfThumbnail)) - edgeLeftView.edges = .left - view.addGestureRecognizer(edgeLeftView) + let edgeView = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(gestureOpenPdfThumbnail)) + edgeView.edges = .right + view.addGestureRecognizer(edgeView) 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) @@ -222,8 +215,8 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni coordinator.animate(alongsideTransition: { context in if UIDevice.current.userInterfaceIdiom == .phone { - self.pdfThumbnailScrollViewleadingAnchor?.constant = -self.thumbnailViewWidth - self.pageViewLeftAnchor?.constant = 10 + // Close + self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) self.pdfThumbnailScrollView.isHidden = true } }, completion: { context in @@ -362,13 +355,25 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni @objc func gestureOpenPdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) { - openPdfThumbnail() + if UIDevice.current.userInterfaceIdiom == .phone && self.pdfThumbnailScrollView.isHidden { + self.pdfThumbnailScrollView.isHidden = false + self.pdfThumbnailScrollViewWidthAnchor?.constant = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) + UIView.animate(withDuration: animateDuration, animations: { + self.pdfThumbnailScrollViewTrailingAnchor?.constant = 0 + self.view.layoutIfNeeded() + }) + } } @objc func gestureClosePdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) { - if recognizer.state == .recognized { - closePdfThumbnail() + if recognizer.state == .recognized && UIDevice.current.userInterfaceIdiom == .phone && !self.pdfThumbnailScrollView.isHidden { + UIView.animate(withDuration: animateDuration) { + self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) + self.view.layoutIfNeeded() + } completion: { _ in + self.pdfThumbnailScrollView.isHidden = true + } } } @@ -380,51 +385,20 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni UIView.animate(withDuration: animateDuration, animations: { if UIDevice.current.userInterfaceIdiom == .phone { + // Close self.pdfThumbnailScrollView.isHidden = true - self.pdfThumbnailScrollViewleadingAnchor?.constant = -widthThumbnail + self.pdfThumbnailScrollViewTrailingAnchor?.constant = widthThumbnail self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail - self.pageViewLeftAnchor?.constant = 10 } else { - self.pdfThumbnailScrollViewleadingAnchor?.constant = 0 + // Open + self.pdfThumbnailScrollViewTrailingAnchor?.constant = 0 self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail - self.pageViewLeftAnchor?.constant = widthThumbnail + 10 } - self.pdfThumbnailViewleadingAnchor?.constant = (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) self.view.layoutIfNeeded() self.pdfView.autoScales = true }) } - func openPdfThumbnail() { - - let widthThumbnail = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) - - if UIDevice.current.userInterfaceIdiom == .phone && self.pdfThumbnailScrollView.isHidden { - self.pdfThumbnailScrollView.isHidden = false - self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail - UIView.animate(withDuration: animateDuration, animations: { - self.pdfThumbnailScrollViewleadingAnchor?.constant = 0 - self.pageViewLeftAnchor?.constant = widthThumbnail + 10 - self.view.layoutIfNeeded() - }) - } - } - - func closePdfThumbnail() { - - let widthThumbnail = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) - - if UIDevice.current.userInterfaceIdiom == .phone && !self.pdfThumbnailScrollView.isHidden { - UIView.animate(withDuration: animateDuration) { - self.pdfThumbnailScrollViewleadingAnchor?.constant = -widthThumbnail - self.pageViewLeftAnchor?.constant = 10 - self.view.layoutIfNeeded() - } completion: { _ in - self.pdfThumbnailScrollView.isHidden = true - } - } - } - @objc func handlePageChange() { guard let curPage = pdfView.currentPage?.pageRef?.pageNumber else { pageView.alpha = 0; return } -- cgit v1.2.3 From d2c854d3b10b32530b330fa192e55b5480165929 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Mon, 2 May 2022 10:12:06 +0200 Subject: fix Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index af1941564..884fa3b16 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -410,7 +410,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni var gotoY = currentPageY - centerPoint.y let startY = visibleRect.origin.y < 0 ? 0 : (visibleRect.origin.y + thumbnailViewHeight) - let endY = visibleRect.origin.y + visibleRect.height + thumbnailViewHeight + let endY = visibleRect.origin.y + visibleRect.height if currentPageY < startY { if gotoY < 0 { gotoY = 0 } -- cgit v1.2.3 From efc100e82af56340787b8dbada9ac3fc3314a32d Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Mon, 2 May 2022 14:37:36 +0200 Subject: Add Tip Signed-off-by: marinofaggiana --- Nextcloud.xcodeproj/project.pbxproj | 17 +++++++++ iOSClient/Data/NCDatabase.swift | 5 +++ iOSClient/Data/NCManageDatabase.swift | 32 ++++++++++++++++ iOSClient/NCGlobal.swift | 6 ++- .../Supporting Files/en.lproj/Localizable.strings | 3 +- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 43 ++++++++++++++++++++++ 6 files changed, 104 insertions(+), 2 deletions(-) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 96e659f81..558554528 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -191,6 +191,7 @@ F74E7720277A2EF40013B958 /* XLForm in Frameworks */ = {isa = PBXBuildFile; productRef = F74E771F277A2EF40013B958 /* XLForm */; }; F7501C322212E57500FB1415 /* NCMedia.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7501C302212E57400FB1415 /* NCMedia.storyboard */; }; F7501C332212E57500FB1415 /* NCMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7501C312212E57400FB1415 /* NCMedia.swift */; }; + F753BA93281FD8020015BFB6 /* EasyTipView in Frameworks */ = {isa = PBXBuildFile; productRef = F753BA92281FD8020015BFB6 /* EasyTipView */; }; F755BD9B20594AC7008C5FBB /* NCService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F755BD9A20594AC7008C5FBB /* NCService.swift */; }; F7581D1A25EFDA61004DC699 /* NCLoginWeb+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7581D1925EFDA60004DC699 /* NCLoginWeb+Menu.swift */; }; F7581D2425EFDDDF004DC699 /* NCMedia+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7581D2325EFDDDF004DC699 /* NCMedia+Menu.swift */; }; @@ -1000,6 +1001,7 @@ F758A01227A7F03E0069468B /* JGProgressHUD in Frameworks */, F76DA96F277B78AE0082465B /* TLPhotoPicker in Frameworks */, F76DA966277B76F30082465B /* UICKeyChainStore in Frameworks */, + F753BA93281FD8020015BFB6 /* EasyTipView in Frameworks */, F76DA95B277B75A90082465B /* TOPasscodeViewController.xcframework in Frameworks */, F76DA963277B760E0082465B /* Queuer in Frameworks */, F75E57BD25BF0EC1002B72C2 /* SVGKit in Frameworks */, @@ -2053,6 +2055,7 @@ F7233B3927835FA400F40A43 /* ChromaColorPicker */, F7BB7E4627A18C56009B9F29 /* Parchment */, F758A01127A7F03E0069468B /* JGProgressHUD */, + F753BA92281FD8020015BFB6 /* EasyTipView */, ); productName = "Crypto Cloud"; productReference = F7CE8AFA1DC1F8D8009CAE48 /* Nextcloud.app */; @@ -2180,6 +2183,7 @@ F7233B3827835FA300F40A43 /* XCRemoteSwiftPackageReference "ChromaColorPicker" */, F7BB7E4527A18C56009B9F29 /* XCRemoteSwiftPackageReference "Parchment" */, F72CD01027A7E92400E59476 /* XCRemoteSwiftPackageReference "JGProgressHUD" */, + F753BA91281FD8010015BFB6 /* XCRemoteSwiftPackageReference "EasyTipView" */, ); productRefGroup = F7F67B9F1A24D27800EE80DA; projectDirPath = ""; @@ -3169,6 +3173,14 @@ minimumVersion = 4.0.0; }; }; + F753BA91281FD8010015BFB6 /* XCRemoteSwiftPackageReference "EasyTipView" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/marinofaggiana/EasyTipView"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.0.0; + }; + }; F75E57A725BF0D61002B72C2 /* XCRemoteSwiftPackageReference "SVGKit" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/SVGKit/SVGKit.git"; @@ -3353,6 +3365,11 @@ package = F74E771E277A2EF40013B958 /* XCRemoteSwiftPackageReference "XLForm" */; productName = XLForm; }; + F753BA92281FD8020015BFB6 /* EasyTipView */ = { + isa = XCSwiftPackageProductDependency; + package = F753BA91281FD8010015BFB6 /* XCRemoteSwiftPackageReference "EasyTipView" */; + productName = EasyTipView; + }; F758A01127A7F03E0069468B /* JGProgressHUD */ = { isa = XCSwiftPackageProductDependency; package = F72CD01027A7E92400E59476 /* XCRemoteSwiftPackageReference "JGProgressHUD" */; diff --git a/iOSClient/Data/NCDatabase.swift b/iOSClient/Data/NCDatabase.swift index 948cb78c7..d2cd149ac 100644 --- a/iOSClient/Data/NCDatabase.swift +++ b/iOSClient/Data/NCDatabase.swift @@ -493,6 +493,11 @@ class tableTag: Object { } } +class tableTip: Object { + + @Persisted(primaryKey: true) var tipName = "" +} + class tableTrash: Object { @objc dynamic var account = "" diff --git a/iOSClient/Data/NCManageDatabase.swift b/iOSClient/Data/NCManageDatabase.swift index 1cc04ca60..39033459a 100644 --- a/iOSClient/Data/NCManageDatabase.swift +++ b/iOSClient/Data/NCManageDatabase.swift @@ -245,6 +245,7 @@ class NCManageDatabase: NSObject { self.clearTable(tablePhotoLibrary.self, account: account) self.clearTable(tableShare.self, account: account) self.clearTable(tableTag.self, account: account) + self.clearTable(tableTip.self) self.clearTable(tableTrash.self, account: account) self.clearTable(tableUserStatus.self, account: account) self.clearTable(tableVideo.self, account: account) @@ -1546,6 +1547,37 @@ class NCManageDatabase: NSObject { return tableTag.init(value: result) } + // MARK: - + // MARK: Table Tip + + @objc func tipExists(_ tipName: String) -> Bool { + + let realm = try! Realm() + + guard (realm.objects(tableTip.self).where { + $0.tipName == tipName + }.first) == nil else { + return true + } + + return false + } + + @objc func addTip(_ tipName: String) { + + let realm = try! Realm() + + do { + try realm.safeWrite { + let addObject = tableTip() + addObject.tipName = tipName + realm.add(addObject, update: .all) + } + } catch let error { + NCCommunicationCommon.shared.writeLog("Could not write to database: \(error)") + } + } + // MARK: - // MARK: Table Trash diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 892f004bc..8eea92a2e 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -112,7 +112,7 @@ class NCGlobal: NSObject { // Database Realm // let databaseDefault = "nextcloud.realm" - let databaseSchemaVersion: UInt64 = 217 + let databaseSchemaVersion: UInt64 = 218 // Intro selector // @@ -361,4 +361,8 @@ class NCGlobal: NSObject { let notificationCenterReloadMediaPage = "reloadMediaPage" let notificationCenterPlayMedia = "playMedia" let notificationCenterPauseMedia = "pauseMedia" + + // Tip + // + let tipNCViewerPDFThumbnail = "tipncviewerpdfthumbnail" } diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index 239868356..09565ace4 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -849,4 +849,5 @@ "_subtitle_not_found_" = "Subtitle not found"; "_disable_" = "Disable"; "_subtitle_not_dowloaded_" = "There are subtitles not downloaded locally"; - +// Tip +"_tip_pdf_thumbnails_" = "Swipe on left to open the thumbnails."; diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index 884fa3b16..faeef4ff0 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -24,6 +24,7 @@ import UIKit import PDFKit import SwiftUI +import EasyTipView class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecognizerDelegate { @@ -39,6 +40,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni private var pdfDocument: PDFDocument? private let pageView = UIView() private let pageViewLabel = UILabel() + private var tipView: EasyTipView? private let thumbnailViewHeight: CGFloat = 70 private let thumbnailViewWidth: CGFloat = 80 @@ -201,10 +203,36 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni NotificationCenter.default.addObserver(self, selector: #selector(handlePageChange), name: Notification.Name.PDFViewPageChanged, object: nil) + // Tip + if UIDevice.current.userInterfaceIdiom == .phone && !NCManageDatabase.shared.tipExists(NCGlobal.shared.tipNCViewerPDFThumbnail){ + + var preferences = EasyTipView.Preferences() + preferences.drawing.foregroundColor = NCBrandColor.shared.brandText + preferences.drawing.backgroundColor = NCBrandColor.shared.customer + preferences.drawing.textAlignment = .left + preferences.drawing.arrowPosition = .right + + preferences.positioning.bubbleInsets.right = UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0 + + preferences.animating.dismissTransform = CGAffineTransform(translationX: 0, y: 100) + preferences.animating.showInitialTransform = CGAffineTransform(translationX: 0, y: -100) + preferences.animating.showInitialAlpha = 0 + preferences.animating.showDuration = 1.5 + preferences.animating.dismissDuration = 1.5 + + tipView = EasyTipView(text: NSLocalizedString("_tip_pdf_thumbnails_", comment: ""), preferences: preferences, delegate: self) + } + setConstraints() handlePageChange() } + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + + self.tipView?.show(forView: self.pdfThumbnailScrollView, withinSuperview: self.view) + } + @objc func viewUnload() { navigationController?.popViewController(animated: true) @@ -216,6 +244,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni coordinator.animate(alongsideTransition: { context in if UIDevice.current.userInterfaceIdiom == .phone { // Close + self.tipView?.dismiss() self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) self.pdfThumbnailScrollView.isHidden = true } @@ -356,6 +385,11 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni @objc func gestureOpenPdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) { if UIDevice.current.userInterfaceIdiom == .phone && self.pdfThumbnailScrollView.isHidden { + if let tipView = self.tipView { + tipView.dismiss() + NCManageDatabase.shared.addTip(NCGlobal.shared.tipNCViewerPDFThumbnail) + self.tipView = nil + } self.pdfThumbnailScrollView.isHidden = false self.pdfThumbnailScrollViewWidthAnchor?.constant = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0) UIView.animate(withDuration: animateDuration, animations: { @@ -459,3 +493,12 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni } } } + +extension NCViewerPDF: EasyTipViewDelegate { + + func easyTipViewDidTap(_ tipView: EasyTipView) { + NCManageDatabase.shared.addTip(NCGlobal.shared.tipNCViewerPDFThumbnail) + } + + func easyTipViewDidDismiss(_ tipView: EasyTipView) { } +} -- cgit v1.2.3 From c0a66426c943fd59cb51b4b062001898b6a76468 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Mon, 2 May 2022 19:20:20 +0200 Subject: Fix & Improvements Signed-off-by: marinofaggiana --- .../Supporting Files/en.lproj/Localizable.strings | 2 +- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 28 ++++++++-------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index 09565ace4..70f0c802e 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -850,4 +850,4 @@ "_disable_" = "Disable"; "_subtitle_not_dowloaded_" = "There are subtitles not downloaded locally"; // Tip -"_tip_pdf_thumbnails_" = "Swipe on left to open the thumbnails."; +"_tip_pdf_thumbnails_" = "Swipe left from the right edge of the screen to show the thumbnails."; diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index faeef4ff0..9db3bf554 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -23,7 +23,6 @@ import UIKit import PDFKit -import SwiftUI import EasyTipView class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecognizerDelegate { @@ -31,7 +30,6 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni var metadata = tableMetadata() var imageIcon: UIImage? - private let appDelegate = UIApplication.shared.delegate as! AppDelegate private var filePath = "" private var pdfView = PDFView() @@ -72,8 +70,12 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni // PDF VIEW - pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) - pdfView.translatesAutoresizingMaskIntoConstraints = false + if UIDevice.current.userInterfaceIdiom == .phone { + pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) + } else { + pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width-thumbnailViewWidth, height: view.frame.height)) + } + pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleLeftMargin] pdfView.document = pdfDocument pdfView.autoScales = true pdfView.displayMode = .singlePageContinuous @@ -82,17 +84,6 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit view.addSubview(pdfView) - NSLayoutConstraint.activate([ - pdfView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), - pdfView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), - pdfView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor) - ]) - if UIDevice.current.userInterfaceIdiom == .pad { - pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -thumbnailViewWidth).isActive = true - } else { - pdfView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true - } - // PDF THUMBNAIL pdfThumbnailScrollView.translatesAutoresizingMaskIntoConstraints = false @@ -114,10 +105,10 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni pdfThumbnailView.layoutMode = .vertical pdfThumbnailView.thumbnailSize = CGSize(width: thumbnailViewHeight, height: thumbnailViewHeight) pdfThumbnailView.backgroundColor = .clear - if UIDevice.current.userInterfaceIdiom == .pad { - self.pdfThumbnailScrollView.isHidden = false - } else { + if UIDevice.current.userInterfaceIdiom == .phone { self.pdfThumbnailScrollView.isHidden = true + } else { + self.pdfThumbnailScrollView.isHidden = false } pdfThumbnailScrollView.addSubview(pdfThumbnailView) @@ -380,6 +371,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni } else { navigationController?.setNavigationBarHidden(true, animated: true) } + handlePageChange() } @objc func gestureOpenPdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) { -- cgit v1.2.3 From 3fde494df252f1a1538e086a3fe4e039351078d3 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Tue, 3 May 2022 08:09:54 +0200 Subject: Fix & Improvements Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index 9db3bf554..54578785f 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -47,6 +47,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni private var defaultBackgroundColor: UIColor = .clear + private var pdfThumbnailScrollViewTopAnchor: NSLayoutConstraint? private var pdfThumbnailScrollViewTrailingAnchor: NSLayoutConstraint? private var pdfThumbnailScrollViewWidthAnchor: NSLayoutConstraint? private var pageViewWidthAnchor: NSLayoutConstraint? @@ -91,10 +92,9 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni pdfThumbnailScrollView.showsVerticalScrollIndicator = false view.addSubview(pdfThumbnailScrollView) - NSLayoutConstraint.activate([ - pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), - pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor) - ]) + pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor) + pdfThumbnailScrollViewTopAnchor?.isActive = true pdfThumbnailScrollViewTrailingAnchor = pdfThumbnailScrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor) pdfThumbnailScrollViewTrailingAnchor?.isActive = true pdfThumbnailScrollViewWidthAnchor = pdfThumbnailScrollView.widthAnchor.constraint(equalToConstant: thumbnailViewWidth) @@ -366,11 +366,19 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni @objc func tapPdfView(_ recognizer: UITapGestureRecognizer) { + pdfThumbnailScrollViewTopAnchor?.isActive = false + if navigationController?.isNavigationBarHidden ?? false { navigationController?.setNavigationBarHidden(false, animated: true) + pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor) + } else { navigationController?.setNavigationBarHidden(true, animated: true) + pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.topAnchor) } + + pdfThumbnailScrollViewTopAnchor?.isActive = true + handlePageChange() } -- cgit v1.2.3 From 943fbdb1e68f056d6099772f0d82f4b578030c68 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Tue, 3 May 2022 10:09:34 +0200 Subject: Revert color Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index 54578785f..0869b90df 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -132,7 +132,9 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni pageView.translatesAutoresizingMaskIntoConstraints = false pageView.layer.cornerRadius = 10 - pageView.backgroundColor = UIColor.gray.withAlphaComponent(0.3) + pageView.backgroundColor = NCBrandColor.shared.systemBackground.withAlphaComponent( + UIAccessibility.isReduceTransparencyEnabled ? 1 : 0.5 + ) view.addSubview(pageView) NSLayoutConstraint.activate([ @@ -145,7 +147,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni pageViewLabel.translatesAutoresizingMaskIntoConstraints = false pageViewLabel.textAlignment = .center - pageViewLabel.textColor = .gray + pageViewLabel.textColor = NCBrandColor.shared.label pageView.addSubview(pageViewLabel) NSLayoutConstraint.activate([ -- cgit v1.2.3 From b0d1644c4c9ef87f18327ebd2206c07dd17af9e2 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Tue, 3 May 2022 10:21:00 +0200 Subject: + Corner radius Signed-off-by: marinofaggiana --- iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift index 0869b90df..3e77c598f 100644 --- a/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift +++ b/iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift @@ -204,6 +204,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecogni preferences.drawing.backgroundColor = NCBrandColor.shared.customer preferences.drawing.textAlignment = .left preferences.drawing.arrowPosition = .right + preferences.drawing.cornerRadius = 10 preferences.positioning.bubbleInsets.right = UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0 -- cgit v1.2.3