From 41977f74374f3509ca58a34fd96df473e35e9878 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 22 Apr 2019 12:08:34 -0700 Subject: [PATCH] snappier presentation of collection picker --- .../Photos/ImagePickerController.swift | 38 +++++++++---------- .../PhotoCollectionPickerController.swift | 3 -- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Signal/src/ViewControllers/Photos/ImagePickerController.swift b/Signal/src/ViewControllers/Photos/ImagePickerController.swift index 5912c7214..8ecbd9ae4 100644 --- a/Signal/src/ViewControllers/Photos/ImagePickerController.swift +++ b/Signal/src/ViewControllers/Photos/ImagePickerController.swift @@ -226,6 +226,11 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat // We don't need to do this when pushing VCs onto the SignalsNavigationController - only when // presenting directly from ConversationVC. _ = self.becomeFirstResponder() + + DispatchQueue.main.async { + // pre-layout collectionPicker for snappier response + self.collectionPickerController.view.layoutIfNeeded() + } } // HACK: Though we don't have an input accessory view, the VC we are presented above (ConversationVC) does. @@ -401,26 +406,23 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat // MARK: - PhotoCollectionPicker Presentation - var isShowingCollectionPickerController: Bool { - return collectionPickerController != nil - } + var isShowingCollectionPickerController: Bool = false + + lazy var collectionPickerController: PhotoCollectionPickerController = { + return PhotoCollectionPickerController(library: library, + collectionDelegate: self) + }() - var collectionPickerController: PhotoCollectionPickerController? func showCollectionPicker() { Logger.debug("") - let collectionPickerController = PhotoCollectionPickerController(library: library, - previousPhotoCollection: photoCollection, - collectionDelegate: self) - guard let collectionPickerView = collectionPickerController.view else { owsFailDebug("collectionView was unexpectedly nil") return } - assert(self.collectionPickerController == nil) - self.collectionPickerController = collectionPickerController - + assert(!isShowingCollectionPickerController) + isShowingCollectionPickerController = true addChild(collectionPickerController) view.addSubview(collectionPickerView) @@ -439,18 +441,16 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat func hideCollectionPicker() { Logger.debug("") - guard let collectionPickerController = collectionPickerController else { - owsFailDebug("collectionPickerController was unexpectedly nil") - return - } - self.collectionPickerController = nil + + assert(isShowingCollectionPickerController) + isShowingCollectionPickerController = false UIView.animate(.promise, duration: 0.25, delay: 0, options: .curveEaseInOut) { - collectionPickerController.view.frame = self.view.frame.offsetBy(dx: 0, dy: self.view.frame.height) + self.collectionPickerController.view.frame = self.view.frame.offsetBy(dx: 0, dy: self.view.frame.height) self.titleView.rotateIcon(.down) }.done { _ in - collectionPickerController.view.removeFromSuperview() - collectionPickerController.removeFromParent() + self.collectionPickerController.view.removeFromSuperview() + self.collectionPickerController.removeFromParent() }.retainUntilComplete() } diff --git a/Signal/src/ViewControllers/Photos/PhotoCollectionPickerController.swift b/Signal/src/ViewControllers/Photos/PhotoCollectionPickerController.swift index d551da139..a0b070b64 100644 --- a/Signal/src/ViewControllers/Photos/PhotoCollectionPickerController.swift +++ b/Signal/src/ViewControllers/Photos/PhotoCollectionPickerController.swift @@ -15,14 +15,11 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg private weak var collectionDelegate: PhotoCollectionPickerDelegate? private let library: PhotoLibrary - private let previousPhotoCollection: PhotoCollection private var photoCollections: [PhotoCollection] required init(library: PhotoLibrary, - previousPhotoCollection: PhotoCollection, collectionDelegate: PhotoCollectionPickerDelegate) { self.library = library - self.previousPhotoCollection = previousPhotoCollection self.photoCollections = library.allPhotoCollections() self.collectionDelegate = collectionDelegate super.init()