snappier presentation of collection picker

pull/2/head
Michael Kirk 7 years ago
parent abd4e0dd41
commit 41977f7437

@ -226,6 +226,11 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
// We don't need to do this when pushing VCs onto the SignalsNavigationController - only when // We don't need to do this when pushing VCs onto the SignalsNavigationController - only when
// presenting directly from ConversationVC. // presenting directly from ConversationVC.
_ = self.becomeFirstResponder() _ = 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. // 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 // MARK: - PhotoCollectionPicker Presentation
var isShowingCollectionPickerController: Bool { var isShowingCollectionPickerController: Bool = false
return collectionPickerController != nil
} lazy var collectionPickerController: PhotoCollectionPickerController = {
return PhotoCollectionPickerController(library: library,
collectionDelegate: self)
}()
var collectionPickerController: PhotoCollectionPickerController?
func showCollectionPicker() { func showCollectionPicker() {
Logger.debug("") Logger.debug("")
let collectionPickerController = PhotoCollectionPickerController(library: library,
previousPhotoCollection: photoCollection,
collectionDelegate: self)
guard let collectionPickerView = collectionPickerController.view else { guard let collectionPickerView = collectionPickerController.view else {
owsFailDebug("collectionView was unexpectedly nil") owsFailDebug("collectionView was unexpectedly nil")
return return
} }
assert(self.collectionPickerController == nil) assert(!isShowingCollectionPickerController)
self.collectionPickerController = collectionPickerController isShowingCollectionPickerController = true
addChild(collectionPickerController) addChild(collectionPickerController)
view.addSubview(collectionPickerView) view.addSubview(collectionPickerView)
@ -439,18 +441,16 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
func hideCollectionPicker() { func hideCollectionPicker() {
Logger.debug("") Logger.debug("")
guard let collectionPickerController = collectionPickerController else {
owsFailDebug("collectionPickerController was unexpectedly nil") assert(isShowingCollectionPickerController)
return isShowingCollectionPickerController = false
}
self.collectionPickerController = nil
UIView.animate(.promise, duration: 0.25, delay: 0, options: .curveEaseInOut) { 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) self.titleView.rotateIcon(.down)
}.done { _ in }.done { _ in
collectionPickerController.view.removeFromSuperview() self.collectionPickerController.view.removeFromSuperview()
collectionPickerController.removeFromParent() self.collectionPickerController.removeFromParent()
}.retainUntilComplete() }.retainUntilComplete()
} }

@ -15,14 +15,11 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
private weak var collectionDelegate: PhotoCollectionPickerDelegate? private weak var collectionDelegate: PhotoCollectionPickerDelegate?
private let library: PhotoLibrary private let library: PhotoLibrary
private let previousPhotoCollection: PhotoCollection
private var photoCollections: [PhotoCollection] private var photoCollections: [PhotoCollection]
required init(library: PhotoLibrary, required init(library: PhotoLibrary,
previousPhotoCollection: PhotoCollection,
collectionDelegate: PhotoCollectionPickerDelegate) { collectionDelegate: PhotoCollectionPickerDelegate) {
self.library = library self.library = library
self.previousPhotoCollection = previousPhotoCollection
self.photoCollections = library.allPhotoCollections() self.photoCollections = library.allPhotoCollections()
self.collectionDelegate = collectionDelegate self.collectionDelegate = collectionDelegate
super.init() super.init()

Loading…
Cancel
Save