Browse Source

Merge pull request #560 from deltachat/messageInput

Fix inputBar (without Rust-core changes).
cyBerta 5 năm trước cách đây
mục cha
commit
ea33497359

+ 1 - 3
deltachat-ios/Controller/ChatViewController.swift

@@ -65,7 +65,6 @@ class ChatViewController: MessagesViewController {
     private var showNamesAboveMessage: Bool
     var showCustomNavBar = true
     var previewView: UIView?
-    var previewController: PreviewController?
 
     var emptyStateView: PaddingLabel = {
         let view =  PaddingLabel()
@@ -1154,8 +1153,7 @@ extension ChatViewController: MessageCellDelegate {
 
                 // these are the files user will be able to swipe trough
                 let mediaUrls: [URL] = previousUrls + [url] + nextUrls
-                previewController = PreviewController(currentIndex: previousUrls.count, urls: mediaUrls)
-                present(previewController!.qlController, animated: true)
+                coordinator?.showMediaGallery(currentIndex: previousUrls.count, mediaUrls: mediaUrls)
             }
         }
     }

+ 31 - 5
deltachat-ios/Controller/PreviewController.swift

@@ -1,16 +1,42 @@
 import QuickLook
 import UIKit
 
-class PreviewController: QLPreviewControllerDataSource {
+class PreviewController: QLPreviewController {
+
     var urls: [URL]
-    var qlController: QLPreviewController
+
+    private lazy var doneButtonItem: UIBarButtonItem = {
+        let button = UIBarButtonItem(title: String.localized("done"), style: .done, target: self, action: #selector(doneButtonPressed(_:)))
+        return button
+    }()
 
     init(currentIndex: Int, urls: [URL]) {
         self.urls = urls
-        qlController = QLPreviewController()
-        qlController.dataSource = self
-        qlController.currentPreviewItemIndex = currentIndex
+        super.init(nibName: nil, bundle: nil)
+        dataSource = self
+        currentPreviewItemIndex = currentIndex
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        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
+        }
+    }
+
+    // MARK: - actions
+    @objc private func doneButtonPressed(_ sender: UIBarButtonItem) {
+        self.dismiss(animated: true, completion: nil)
     }
+}
+
+extension PreviewController: QLPreviewControllerDataSource {
 
     func numberOfPreviewItems(in _: QLPreviewController) -> Int {
         return urls.count

+ 9 - 2
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)
         }
     }
 
@@ -523,6 +523,13 @@ class ChatViewCoordinator: NSObject, Coordinator {
     func showPhotoVideoLibrary(delegate: MediaPickerDelegate) {
         mediaPicker.showPhotoVideoLibrary(delegate: delegate)
     }
+
+    func showMediaGallery(currentIndex: Int, mediaUrls urls: [URL]) {
+        let betterPreviewController = PreviewController(currentIndex: currentIndex, urls: urls)
+        let nav = UINavigationController(rootViewController: betterPreviewController)
+
+        navigationController.present(nav, animated: true)
+    }
 }
 
 class NewGroupAddMembersCoordinator: Coordinator {
@@ -670,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)
         }
     }