Set image height from image URL to PinterestLayout CollectionView

I create a CollectionView with PinterestLayout, so this is a collection view with different cells hight. It’s work, but when I put my code to the project with Firestore (when image in cells I take from URL) I have a problem, its show pictures, but hight are not correct.
this is how it should be: 01 — ImgBB
this is how it is: 02 — ImgBB

{
func collectionView(collectionView: UICollectionView, heightForPhotoAt indexPath: IndexPath, with width: CGFloat) → CGFloat {

    if let post = posts?[indexPath.item], let photo = post.floverImg {
        let boundingRect = CGRect(x: 0, y: 0, width: width, height: CGFloat(MAXFLOAT))
        let rect = AVMakeRect(aspectRatio: photo.size(), insideRect: boundingRect)
       
        return CGFloat(rect.size.height)
    }
    
    return 200
}

P.S. This code works with App where Images I have in project, not in Firestore

Without more context it’s hard to tell what will fix toe issue.

I used this series to help me make a Pinterest layout.