From 0e1a65446f1b858b0fbefa1ff157317d21ddc6ff Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sun, 9 Dec 2018 10:10:36 -0500 Subject: [PATCH] WIP: Present CollectionPicker as child view -[x] establish parent/child relation -[] reconcile changes with collection picker delegate -[] present/dismiss animation -[] animate title label --- .../PhotoLibrary/ImagePickerController.swift | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift index e333fd8d7..0dd8a087b 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift @@ -357,6 +357,50 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat reloadDataAndRestoreSelection() } + // MARK: - PhotoCollectionPicker Presentation + + var isShowingCollectionPickerController: Bool { + return collectionPickerController != nil + } + + var collectionPickerController: PhotoCollectionPickerController? + func showCollectionPicker() { + Logger.debug("") + + let collectionPickerController = PhotoCollectionPickerController(library: library, + previousPhotoCollection: photoCollection, + collectionDelegate: self) + + guard let collectionView = collectionPickerController.view else { + owsFailDebug("collectionView was unexpectedly nil") + return + } + + assert(self.collectionPickerController == nil) + self.collectionPickerController = collectionPickerController + + addChildViewController(collectionPickerController) + + view.addSubview(collectionView) + collectionView.autoPinEdgesToSuperviewEdges() + } + + func hideCollectionPicker() { + Logger.debug("") + guard let collectionPickerController = collectionPickerController else { + owsFailDebug("collectionPickerController was unexpectedly nil") + return + } + self.collectionPickerController = nil + // TODO animate/hide + + // MJK really? This documentation is surprising... + // If you are implementing your own container view controller, it must call the willMove(toParent:) method of the child view controller before calling the removeFromParent() method, passing in a parent value of nil. + + collectionPickerController.view.removeFromSuperview() + collectionPickerController.removeFromParentViewController() + } + // MARK: - PhotoCollectionPickerDelegate func photoCollectionPicker(_ photoCollectionPicker: PhotoCollectionPickerController, didPickCollection collection: PhotoCollection) { @@ -378,11 +422,11 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat guard sender.state == .recognized else { return } - let view = PhotoCollectionPickerController(library: library, - previousPhotoCollection: photoCollection, - collectionDelegate: self) - let nav = OWSNavigationController(rootViewController: view) - self.present(nav, animated: true, completion: nil) + if isShowingCollectionPickerController { + hideCollectionPicker() + } else { + showCollectionPicker() + } } // MARK: - UICollectionView