瀏覽代碼

replaced PreviewController with BetterPreviewController - tweak to show doneButton

nayooti 5 年之前
父節點
當前提交
12fc1797f6
共有 2 個文件被更改,包括 7 次插入27 次删除
  1. 4 24
      deltachat-ios/Controller/PreviewController.swift
  2. 3 3
      deltachat-ios/Coordinator/AppCoordinator.swift

+ 4 - 24
deltachat-ios/Controller/PreviewController.swift

@@ -1,27 +1,7 @@
 import QuickLook
 import UIKit
 
-class PreviewController: QLPreviewControllerDataSource {
-    var urls: [URL]
-    var qlController: QLPreviewController
-
-    init(currentIndex: Int, urls: [URL]) {
-        self.urls = urls
-        qlController = QLPreviewController()
-        qlController.dataSource = self
-        qlController.currentPreviewItemIndex = currentIndex
-    }
-
-    func numberOfPreviewItems(in _: QLPreviewController) -> Int {
-        return urls.count
-    }
-
-    func previewController(_: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
-        return urls[index] as QLPreviewItem
-    }
-}
-
-class BetterPreviewController: QLPreviewController {
+class PreviewController: QLPreviewController {
 
     var urls: [URL]
 
@@ -43,8 +23,8 @@ class BetterPreviewController: QLPreviewController {
 
     override func viewDidLoad() {
         super.viewDidLoad()
-        if navigationController != nil {
-            /* QLPreviewController comes with a done-button by default. But if is embedded in UINavigationContrller we set a done-button manually.
+        if navigationController != nil && isBeingPresented {
+            /* QLPreviewController comes with a done-button by default. But if is embedded in UINavigationContrller we need to set a done-button manually.
             */
             navigationItem.leftBarButtonItem = doneButtonItem
         }
@@ -56,7 +36,7 @@ class BetterPreviewController: QLPreviewController {
     }
 }
 
-extension BetterPreviewController: QLPreviewControllerDataSource {
+extension PreviewController: QLPreviewControllerDataSource {
 
     func numberOfPreviewItems(in _: QLPreviewController) -> Int {
         return urls.count

+ 3 - 3
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -414,7 +414,7 @@ class GroupChatDetailCoordinator: Coordinator {
         }
         previewController = PreviewController(currentIndex: 0, urls: mediaUrls)
         if let previewController = previewController {
-            navigationController.pushViewController(previewController.qlController, animated: true)
+            navigationController.pushViewController(previewController, animated: true)
         }
     }
 
@@ -525,7 +525,7 @@ class ChatViewCoordinator: NSObject, Coordinator {
     }
 
     func showMediaGallery(currentIndex: Int, mediaUrls urls: [URL]) {
-        let betterPreviewController = BetterPreviewController(currentIndex: currentIndex, urls: urls)
+        let betterPreviewController = PreviewController(currentIndex: currentIndex, urls: urls)
         let nav = UINavigationController(rootViewController: betterPreviewController)
 
         navigationController.present(nav, animated: true)
@@ -677,7 +677,7 @@ class ContactDetailCoordinator: Coordinator, ContactDetailCoordinatorProtocol {
         }
         previewController = PreviewController(currentIndex: 0, urls: mediaUrls)
         if let previewController = previewController {
-            navigationController.pushViewController(previewController.qlController, animated: true)
+            navigationController.pushViewController(previewController, animated: true)
         }
     }