|
|
|
@ -98,6 +98,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
|
|
|
|
updateLayout()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hasEverAppeared: Bool = false
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
|
|
|
|
@ -113,6 +114,40 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
|
|
|
|
photoMediaSize.thumbnailSize = CGSize(width: cellSize.width * scale, height: cellSize.height * scale)
|
|
|
|
|
|
|
|
|
|
reloadDataAndRestoreSelection()
|
|
|
|
|
if !hasEverAppeared {
|
|
|
|
|
hasEverAppeared = true
|
|
|
|
|
scrollToBottom(animated: false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK:
|
|
|
|
|
|
|
|
|
|
func scrollToBottom(animated: Bool) {
|
|
|
|
|
self.view.layoutIfNeeded()
|
|
|
|
|
|
|
|
|
|
guard let collectionView = collectionView else {
|
|
|
|
|
owsFailDebug("collectionView was unexpectedly nil")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We could try to be more precise by doing something like
|
|
|
|
|
//
|
|
|
|
|
// let botomOffset = collectionView.contentSize + collectionView.contentInset.top - collectionView.bounds.height
|
|
|
|
|
//
|
|
|
|
|
// But `collectionView.contentInset` is based on `safeAreaInsets`, which isn't accurate
|
|
|
|
|
// until `viewDidAppear` at the earliest.
|
|
|
|
|
//
|
|
|
|
|
// from https://developer.apple.com/documentation/uikit/uiview/positioning_content_relative_to_the_safe_area
|
|
|
|
|
// > Make your modifications in [viewDidAppear] because the safe area insets for a view are
|
|
|
|
|
// > not accurate until the view is added to a view hierarchy.
|
|
|
|
|
//
|
|
|
|
|
// Overshooting like this works without visible animation glitch.
|
|
|
|
|
let bottomOffset = CGFloat.greatestFiniteMagnitude
|
|
|
|
|
collectionView.setContentOffset(CGPoint(x: 0, y: bottomOffset), animated: animated)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func reloadDataAndRestoreSelection() {
|
|
|
|
|