marinofaggiana 5 years ago
parent
commit
27719391cf

+ 4 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -367,7 +367,7 @@
 		F76FA86D2406B9F90003D339 /* NCViewerPhotoTileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76FA8692406B9F90003D339 /* NCViewerPhotoTileManager.swift */; };
 		F76FA86E2406B9F90003D339 /* NCViewerPhotoTilingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76FA86A2406B9F90003D339 /* NCViewerPhotoTilingView.swift */; };
 		F76FA86F2406B9F90003D339 /* NCViewerPhotoImageScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76FA86B2406B9F90003D339 /* NCViewerPhotoImageScrollView.swift */; };
-		F76FA8712406BE910003D339 /* NCViewerPhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76FA8702406BE910003D339 /* NCViewerPhotoViewController.swift */; };
+		F76FA8712406BE910003D339 /* NCViewerPhotoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76FA8702406BE910003D339 /* NCViewerPhotoView.swift */; };
 		F771E3D320E2392D00AFB62D /* FileProviderExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F771E3D220E2392D00AFB62D /* FileProviderExtension.swift */; };
 		F771E3D520E2392D00AFB62D /* FileProviderItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F771E3D420E2392D00AFB62D /* FileProviderItem.swift */; };
 		F771E3D720E2392D00AFB62D /* FileProviderEnumerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F771E3D620E2392D00AFB62D /* FileProviderEnumerator.swift */; };
@@ -1071,7 +1071,7 @@
 		F76FA8692406B9F90003D339 /* NCViewerPhotoTileManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerPhotoTileManager.swift; sourceTree = "<group>"; };
 		F76FA86A2406B9F90003D339 /* NCViewerPhotoTilingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerPhotoTilingView.swift; sourceTree = "<group>"; };
 		F76FA86B2406B9F90003D339 /* NCViewerPhotoImageScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerPhotoImageScrollView.swift; sourceTree = "<group>"; };
-		F76FA8702406BE910003D339 /* NCViewerPhotoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerPhotoViewController.swift; sourceTree = "<group>"; };
+		F76FA8702406BE910003D339 /* NCViewerPhotoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerPhotoView.swift; sourceTree = "<group>"; };
 		F771E3D020E2392D00AFB62D /* File Provider Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "File Provider Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
 		F771E3D220E2392D00AFB62D /* FileProviderExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderExtension.swift; sourceTree = "<group>"; };
 		F771E3D420E2392D00AFB62D /* FileProviderItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderItem.swift; sourceTree = "<group>"; };
@@ -2100,7 +2100,7 @@
 		F76FA8672406B9F90003D339 /* NCViewerPhoto */ = {
 			isa = PBXGroup;
 			children = (
-				F76FA8702406BE910003D339 /* NCViewerPhotoViewController.swift */,
+				F76FA8702406BE910003D339 /* NCViewerPhotoView.swift */,
 				F76FA8692406B9F90003D339 /* NCViewerPhotoTileManager.swift */,
 				F76FA86A2406B9F90003D339 /* NCViewerPhotoTilingView.swift */,
 				F76FA86B2406B9F90003D339 /* NCViewerPhotoImageScrollView.swift */,
@@ -3593,7 +3593,7 @@
 				F73B4F0C1F470D9100BBEE4B /* nsHebrewProber.cpp in Sources */,
 				F762CAFB1EACB66200B38484 /* XLFormDatePickerCell.m in Sources */,
 				F762CB0F1EACB66200B38484 /* NSObject+XLFormAdditions.m in Sources */,
-				F76FA8712406BE910003D339 /* NCViewerPhotoViewController.swift in Sources */,
+				F76FA8712406BE910003D339 /* NCViewerPhotoView.swift in Sources */,
 				F7B2DEF01F976854007CF4D2 /* NYMnemonic.m in Sources */,
 				F707C26521A2DC5200F6181E /* NCStoreReview.swift in Sources */,
 				F73B4EFF1F470D9100BBEE4B /* LangRussianModel.cpp in Sources */,

+ 14 - 6
iOSClient/Main/NCDetailViewController.swift

@@ -31,8 +31,9 @@ class NCDetailViewController: UIViewController {
     
     @objc var metadata: tableMetadata?
     @objc var selector: String?
-
+    
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    private var viewerPhotoView: NCViewerPhotoView?
     
     required init?(coder: NSCoder) {
         super.init(coder: coder)
@@ -64,6 +65,16 @@ class NCDetailViewController: UIViewController {
         }
     }
     
+    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
+        super.viewWillTransition(to: size, with: coordinator)
+        
+        viewerPhotoView?.saveCurrentStatesForRotation()
+        
+        coordinator.animate(alongsideTransition: nil) { _ in
+            self.viewerPhotoView?.restoreStatesForRotation(in: size)
+        }
+    }
+    
     func viewUnload() {
         if let splitViewController = self.splitViewController as? NCSplitViewController {
             if splitViewController.isCollapsed {
@@ -106,11 +117,8 @@ class NCDetailViewController: UIViewController {
         
         // IMAGE
         if metadata.typeFile == k_metadataTypeFile_image {
-            let viewerPhotoViewController = NCViewerPhotoViewController()
-            viewerPhotoViewController.metadata = metadata
-            self.addChild(viewerPhotoViewController)
-            self.backgroundView.addSubview(viewerPhotoViewController.view)
-            viewerPhotoViewController.didMove(toParent: self)
+            viewerPhotoView = NCViewerPhotoView.init(frame: backgroundView.frame)
+            viewerPhotoView?.setup(metadata: metadata, view: backgroundView)
             return
         }
         

+ 42 - 67
iOSClient/Viewer/NCViewerPhoto/NCViewerPhotoViewController.swift → iOSClient/Viewer/NCViewerPhoto/NCViewerPhotoView.swift

@@ -1,9 +1,8 @@
 import UIKit
 
-class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
+class NCViewerPhotoView: UIScrollView, UIScrollViewDelegate {
 	
 	let pagePadding: CGFloat = 10
-	var pagingScrollView: UIScrollView!
 	var recycledPages: Set<NCViewerPhotoImageScrollView> = []
 	var visiblePages: Set<NCViewerPhotoImageScrollView> = []
 	var firstVisiblePageIndexBeforeRotation: Int!
@@ -14,41 +13,45 @@ class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
     var metadata = tableMetadata()
     var metadatas = [tableMetadata]()
     
-	override func viewDidLoad() {
-		super.viewDidLoad()
-		
-        // Get Metadatas
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
+    }
+    
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
+    }
+    
+    @objc func setup(metadata: tableMetadata, view: UIView) {
+        
+        self.metadata = metadata
         if let metadatas = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND typeFile == %@", metadata.account, metadata.serverUrl, k_metadataTypeFile_image), sorted: "fileName", ascending: true) {
             self.metadatas = metadatas
         }
         
-		// single tap to show or hide navigation bar
-		self.singleTap = UITapGestureRecognizer(target: self, action: #selector(handleSingleTap))
-		self.view.addGestureRecognizer(self.singleTap)
-		
-		self.pagingScrollView = UIScrollView(frame: self.frameForPagingScrollView())
-		//self.updateBackgroundColor()
-		self.pagingScrollView.showsVerticalScrollIndicator = false
-		self.pagingScrollView.showsHorizontalScrollIndicator = false
-		self.pagingScrollView.isPagingEnabled = true
-		self.pagingScrollView.contentSize = self.contentSizeForPagingScrollView()
-		self.pagingScrollView.delegate = self
-        if #available(iOS 11.0, *) {
-            pagingScrollView.contentInsetAdjustmentBehavior = .never
-        } else {
-            automaticallyAdjustsScrollViewInsets = false
-        }
-		self.view.addSubview(self.pagingScrollView)
-		self.layoutPagingScrollView()
-		
-		self.tilePages()
-	}
-	
+        // single tap to show or hide navigation bar
+        singleTap = UITapGestureRecognizer(target: self, action: #selector(handleSingleTap))
+        addGestureRecognizer(self.singleTap)
+        
+        showsVerticalScrollIndicator = false
+        showsHorizontalScrollIndicator = false
+        isPagingEnabled = true
+        contentSize = self.contentSizeForPagingScrollView()
+        delegate = self
+        view.addSubview(self)
+        
+        tilePages()
+    }
+   
+    @objc func changeTheming() {
+        backgroundColor = NCBrandColor.sharedInstance.backgroundView
+    }
+    
 	//MARK: - Tiling and page configuration
 	
 	func tilePages() {
 		// Calculate which pages should now be visible
-		let visibleBounds = pagingScrollView.bounds
+		let visibleBounds = self.bounds
 		
 		var firstNeededPageIndex: Int = Int(floor(visibleBounds.minX/visibleBounds.width))
 		var lastNeededPageIndex: Int = Int(floor((visibleBounds.maxX - 1)/visibleBounds.width))
@@ -70,7 +73,7 @@ class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
 				let page = self.dequeueRecycledPage() ?? NCViewerPhotoImageScrollView()
 				
 				self.configure(page, for: index)
-				self.pagingScrollView.addSubview(page)
+				self.addSubview(page)
 				self.visiblePages.insert(page)
 			}
 		}
@@ -95,7 +98,7 @@ class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
 	
 	func configure(_ page: NCViewerPhotoImageScrollView, for index: Int) {
 		self.singleTap.require(toFail: page.zoomingTap)
-		page.backgroundColor = self.view.backgroundColor
+		page.backgroundColor = self.backgroundColor
 
 		page.index = index
 		page.frame = self.frameForPage(at: index)
@@ -170,7 +173,7 @@ class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
 	//MARK: - Frame calculations
 	
 	func frameForPagingScrollView(in size: CGSize? = nil) -> CGRect {
-        var frame = self.view.bounds
+        var frame = self.bounds
 		
 		if size != nil {
 			frame.size = size!
@@ -182,13 +185,13 @@ class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
 	}
 	
 	func contentSizeForPagingScrollView() -> CGSize {
-		let bounds = self.pagingScrollView.bounds
+		let bounds = self.bounds
         return CGSize(width: bounds.size.width*CGFloat(metadatas.count), height: bounds.size.height)
 	}
 	
 	func frameForPage(at index: Int) -> CGRect {
 		
-		let bounds = self.pagingScrollView.bounds
+		let bounds = self.bounds
 		var pageFrame = bounds
 		pageFrame.size.width -= 2*pagePadding
 		pageFrame.origin.x = (bounds.size.width*CGFloat(index)) + pagePadding
@@ -196,32 +199,16 @@ class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
 		return pageFrame
 	}
 	
-	//MARK: - Rotation Configuration
-	
-	override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
-		self.saveCurrentStatesForRotation()
-	}
-	
-	override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
-		self.restoreStatesForRotation(in: size)
-	}
-	
-	/**
-	Save current page and zooming states for device rotation.
-	*/
 	func saveCurrentStatesForRotation() {
-		let visibleBounds = pagingScrollView.bounds
+        let visibleBounds = self.bounds
 		firstVisiblePageIndexBeforeRotation = Int(floor(visibleBounds.minX/visibleBounds.width))
 	}
 	
-	/**
-	Apply tracked informations for device rotation.
-	*/
 	func restoreStatesForRotation(in size: CGSize) {
 		// recalculate contentSize based on current orientation
 		let pagingScrollViewFrame = self.frameForPagingScrollView(in: size)
-		pagingScrollView?.frame = pagingScrollViewFrame
-		pagingScrollView?.contentSize = self.contentSizeForPagingScrollView()
+		self.frame = pagingScrollViewFrame
+		self.contentSize = self.contentSizeForPagingScrollView()
 		
 		// adjust frames and configuration of each visible page
 		for page in visiblePages {
@@ -235,10 +222,10 @@ class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
 		// adjust contentOffset to preserve page location based on values collected prior to location
 		var contentOffset = CGPoint.zero
 		
-		let pageWidth = pagingScrollView?.bounds.size.width ?? 1
+		let pageWidth = self.bounds.size.width
 		contentOffset.x = (CGFloat(firstVisiblePageIndexBeforeRotation) * pageWidth)
 		
-		pagingScrollView?.contentOffset = contentOffset
+		self.contentOffset = contentOffset
 		
 	}
 	
@@ -297,16 +284,4 @@ class NCViewerPhotoViewController: UIViewController, UIScrollViewDelegate {
 		}
 	}
 	*/
-    
-	func layoutPagingScrollView() {
-		self.pagingScrollView.translatesAutoresizingMaskIntoConstraints = false
-		
-		let top = NSLayoutConstraint(item: self.pagingScrollView!, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0.0)
-		let left = NSLayoutConstraint(item: self.pagingScrollView!, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: -10.0)
-		
-		let bottom = NSLayoutConstraint(item: self.pagingScrollView!, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0.0)
-		let right = NSLayoutConstraint(item: self.pagingScrollView!, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 10.0)
-		
-		self.view.addConstraints([top, left, bottom, right])
-	}
 }