Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Fixed library crash after adding image attachment #237 #250

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Sources/Plugins/AttachmentManager/AttachmentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,21 @@ extension AttachmentManager: UICollectionViewDataSource, UICollectionViewDelegat

final public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

if let customSize = self.dataSource?.attachmentManager(self, sizeFor: self.attachments[indexPath.row], at: indexPath.row){
return customSize
}

var height = attachmentView.intrinsicContentHeight
if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
height -= (layout.sectionInset.bottom + layout.sectionInset.top + collectionView.contentInset.top + collectionView.contentInset.bottom)
}

// Prevent out of range error when the AttachmentCell has not been added the attachment array
if indexPath.row == attachments.count && showAddAttachmentCell {
return CGSize(width: height, height: height)
}

let attachment = self.attachments[indexPath.row]
if let customSize = self.dataSource?.attachmentManager(self, sizeFor: attachment, at: indexPath.row){
return customSize
}

return CGSize(width: height, height: height)
}

Expand Down