Proper fix fox recent photo thumbnails changing size in media attachment sheet.
Simply update item sizes in `layoutSubviews` which is getting called each time sheet size changes.
This commit is contained in:
parent
77fbf610bc
commit
7fcf28d35f
@ -72,11 +72,6 @@ class AttachmentKeyboard: CustomKeyboard {
|
||||
setupRecentPhotos()
|
||||
setupGalleryButton()
|
||||
setupFormatPicker()
|
||||
|
||||
NotificationCenter.default.addObserver(self,
|
||||
selector: #selector(keyboardFrameDidChange),
|
||||
name: UIResponder.keyboardDidChangeFrameNotification,
|
||||
object: nil)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
@ -85,7 +80,7 @@ class AttachmentKeyboard: CustomKeyboard {
|
||||
|
||||
// MARK: Recent Photos
|
||||
|
||||
func setupRecentPhotos() {
|
||||
private func setupRecentPhotos() {
|
||||
recentPhotosCollectionView.recentPhotosDelegate = self
|
||||
mainStackView.addArrangedSubview(recentPhotosCollectionView)
|
||||
|
||||
@ -93,7 +88,7 @@ class AttachmentKeyboard: CustomKeyboard {
|
||||
recentPhotosErrorView.isHidden = true
|
||||
}
|
||||
|
||||
func showRecentPhotos() {
|
||||
private func showRecentPhotos() {
|
||||
guard recentPhotosCollectionView.hasPhotos else {
|
||||
return showRecentPhotosError()
|
||||
}
|
||||
@ -105,7 +100,7 @@ class AttachmentKeyboard: CustomKeyboard {
|
||||
recentPhotosCollectionView.isHidden = false
|
||||
}
|
||||
|
||||
func showRecentPhotosError() {
|
||||
private func showRecentPhotosError() {
|
||||
recentPhotosErrorView.hasMediaLibraryAccess = isMediaLibraryAccessGranted
|
||||
|
||||
galleryButton.isHidden = true
|
||||
@ -117,7 +112,7 @@ class AttachmentKeyboard: CustomKeyboard {
|
||||
|
||||
// MARK: Gallery Button
|
||||
|
||||
func setupGalleryButton() {
|
||||
private func setupGalleryButton() {
|
||||
addSubview(galleryButton)
|
||||
galleryButton.setTemplateImage(#imageLiteral(resourceName: "photo-album-outline-28"), tintColor: .white)
|
||||
galleryButton.setBackgroundImage(UIImage(color: UIColor.black.withAlphaComponent(0.7)), for: .normal)
|
||||
@ -133,13 +128,13 @@ class AttachmentKeyboard: CustomKeyboard {
|
||||
}
|
||||
|
||||
@objc
|
||||
func didTapGalleryButton() {
|
||||
private func didTapGalleryButton() {
|
||||
delegate?.didTapGalleryButton()
|
||||
}
|
||||
|
||||
// MARK: Format Picker
|
||||
|
||||
func setupFormatPicker() {
|
||||
private func setupFormatPicker() {
|
||||
attachmentFormatPickerView.attachmentFormatPickerDelegate = self
|
||||
|
||||
mainStackView.addArrangedSubview(attachmentFormatPickerView)
|
||||
@ -155,22 +150,15 @@ class AttachmentKeyboard: CustomKeyboard {
|
||||
|
||||
override func willPresent() {
|
||||
super.willPresent()
|
||||
|
||||
checkPermissions { [weak self] in
|
||||
self?.updateItemSizes()
|
||||
}
|
||||
checkPermissions()
|
||||
}
|
||||
|
||||
@objc
|
||||
func keyboardFrameDidChange() {
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
updateItemSizes()
|
||||
}
|
||||
|
||||
func updateItemSizes() {
|
||||
// Force a layout cycle so that `recentPhotosCollectionView` has the correct size in all cases.
|
||||
// This became necessary with iOS 16.
|
||||
layoutIfNeeded()
|
||||
|
||||
private func updateItemSizes() {
|
||||
// The items should always expand to fit the height of their collection view.
|
||||
|
||||
// If we have space we will show two rows of recent photos (e.g. iPad in landscape).
|
||||
@ -188,21 +176,19 @@ class AttachmentKeyboard: CustomKeyboard {
|
||||
attachmentFormatPickerView.itemSize = CGSize(square: attachmentFormatPickerView.height)
|
||||
}
|
||||
|
||||
func checkPermissions(completion: @escaping () -> Void) {
|
||||
private func checkPermissions() {
|
||||
switch mediaLibraryAuthorizationStatus {
|
||||
case .authorized, .limited:
|
||||
showRecentPhotos()
|
||||
case .denied, .restricted:
|
||||
showRecentPhotosError()
|
||||
case .notDetermined:
|
||||
return PHPhotoLibrary.requestAuthorization { _ in
|
||||
DispatchQueue.main.async { self.checkPermissions(completion: completion) }
|
||||
PHPhotoLibrary.requestAuthorization { _ in
|
||||
DispatchQueue.main.async { self.checkPermissions() }
|
||||
}
|
||||
@unknown default:
|
||||
showRecentPhotosError()
|
||||
}
|
||||
|
||||
completion()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user