Skip to content

Commit

Permalink
Merge pull request #250 from sgraesser/master
Browse files Browse the repository at this point in the history
bug: Fixed library crash after adding image attachment #237
  • Loading branch information
Kaspik committed Aug 23, 2023
2 parents 152b4fa + a7c4ca2 commit 10066ac
Showing 1 changed file with 11 additions and 4 deletions.
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

0 comments on commit 10066ac

Please sign in to comment.