diff --git a/Signal/src/ViewControllers/Photos/ImagePickerController.swift b/Signal/src/ViewControllers/Photos/ImagePickerController.swift index 04777933e..7d197bd6e 100644 --- a/Signal/src/ViewControllers/Photos/ImagePickerController.swift +++ b/Signal/src/ViewControllers/Photos/ImagePickerController.swift @@ -56,6 +56,9 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat collectionView.register(PhotoGridViewCell.self, forCellWithReuseIdentifier: PhotoGridViewCell.reuseIdentifier) + // ensure images at the end of the list can be scrolled above the bottom buttons + let bottomButtonInset = -1 * SendMediaNavigationController.bottomButtonsCenterOffset + SendMediaNavigationController.bottomButtonWidth / 2 + collectionView.contentInset.bottom = bottomButtonInset + 8 view.backgroundColor = .ows_gray95 // The PhotoCaptureVC needs a shadow behind it's cancel button, so we use a custom icon. @@ -235,6 +238,10 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat // MARK: + var lastPageYOffset: CGFloat { + return collectionView.contentSize.height - collectionView.frame.height + } + func scrollToBottom(animated: Bool) { self.view.layoutIfNeeded() @@ -243,12 +250,13 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat return } - let lastSection = collectionView.numberOfSections - 1 - let lastItem = collectionView.numberOfItems(inSection: lastSection) - 1 - if lastSection >= 0 && lastItem >= 0 { - let lastIndex = IndexPath(item: lastItem, section: lastSection) - collectionView.scrollToItem(at: lastIndex, at: .bottom, animated: animated) + let yOffset = lastPageYOffset + guard yOffset > 0 else { + // less than 1 page of content. Do not offset. + return } + + collectionView.setContentOffset(CGPoint(x: 0, y: yOffset), animated: animated) } private func reloadDataAndRestoreSelection() { diff --git a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift index 4aaf1cb4a..94d8c17d8 100644 --- a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift +++ b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift @@ -135,6 +135,7 @@ class SendMediaNavigationController: OWSNavigationController { } // MARK: Views + public static let bottomButtonWidth: CGFloat = 44 private lazy var doneButton: DoneButton = { let button = DoneButton() @@ -149,7 +150,7 @@ class SendMediaNavigationController: OWSNavigationController { tintColor: .ows_gray60, block: { [weak self] in self?.didTapBatchModeButton() }) - let width: CGFloat = 44 + let width: CGFloat = type(of: self).bottomButtonWidth button.autoSetDimensions(to: CGSize(width: width, height: width)) button.layer.cornerRadius = width / 2 button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) @@ -164,7 +165,7 @@ class SendMediaNavigationController: OWSNavigationController { tintColor: .ows_gray60, block: { [weak self] in self?.didTapCameraModeButton() }) - let width: CGFloat = 44 + let width: CGFloat = type(of: self).bottomButtonWidth button.autoSetDimensions(to: CGSize(width: width, height: width)) button.layer.cornerRadius = width / 2 button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) @@ -179,7 +180,7 @@ class SendMediaNavigationController: OWSNavigationController { tintColor: .ows_gray60, block: { [weak self] in self?.didTapMediaLibraryModeButton() }) - let width: CGFloat = 44 + let width: CGFloat = type(of: self).bottomButtonWidth button.autoSetDimensions(to: CGSize(width: width, height: width)) button.layer.cornerRadius = width / 2 button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)