From caf00206972dff520e98db57a6378da358a8e9bc Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sun, 9 Dec 2018 10:39:41 -0500 Subject: [PATCH] Present CollectionPicker as child view TODO: -[x] establish parent/child relation -[x] reconcile changes with collection picker delegate -[x] present/dismiss animation -[] animate title label -[] hide (some?) bar button items when collection picker presented Nice to have: -[] crop child view top - so that it comes *up to* the navbar bottom, but doesn't go behind --- .../PhotoLibrary/ImagePickerController.swift | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift index 0549de9d4..7d2774865 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift @@ -371,7 +371,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat previousPhotoCollection: photoCollection, collectionDelegate: self) - guard let collectionView = collectionPickerController.view else { + guard let collectionPickerView = collectionPickerController.view else { owsFailDebug("collectionView was unexpectedly nil") return } @@ -381,8 +381,14 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat addChildViewController(collectionPickerController) - view.addSubview(collectionView) - collectionView.autoPinEdgesToSuperviewEdges() + view.addSubview(collectionPickerView) + collectionPickerView.autoPinEdgesToSuperviewEdges() + collectionPickerView.layoutIfNeeded() + collectionPickerView.frame = view.frame.offsetBy(dx: 0, dy: view.frame.height) + + UIView.animate(.promise, duration: 0.3, delay: 0, options: .curveEaseInOut) { + collectionPickerView.superview?.layoutIfNeeded() + }.retainUntilComplete() } func hideCollectionPicker() { @@ -392,13 +398,13 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat 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() + UIView.animate(.promise, duration: 0.3, delay: 0, options: .curveEaseInOut) { + collectionPickerController.view.frame = self.view.frame.offsetBy(dx: 0, dy: self.view.frame.height) + }.done { _ in + collectionPickerController.view.removeFromSuperview() + collectionPickerController.removeFromParentViewController() + }.retainUntilComplete() } // MARK: - PhotoCollectionPickerDelegate