Merge branch 'mkirk/photo-picker-scroll-to-bottom'

pull/1/head
Michael Kirk 6 years ago
commit f9b1b2f360

@ -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() {

@ -57,12 +57,12 @@ public class PhotoGridViewCell: UICollectionViewCell {
self.highlightedView = UIView()
highlightedView.alpha = 0.2
highlightedView.backgroundColor = Theme.primaryColor
highlightedView.backgroundColor = Theme.darkThemePrimaryColor
highlightedView.isHidden = true
self.selectedView = UIView()
selectedView.alpha = 0.3
selectedView.backgroundColor = Theme.backgroundColor
selectedView.backgroundColor = Theme.darkThemeBackgroundColor
selectedView.isHidden = true
super.init(frame: frame)

Loading…
Cancel
Save