title: Dynamic collection cell size as per backend response URL image size in Horizontal Collectionview
body: <p>I have created tableview with multiple custom tableviewcell and each tableviewcell embedded with collectionview. There is one custom tableview cell with horizontal collectionview in which as per backend response download image from URL and set image in collection cell, every collection cell width and height should be change as per image size. I have implemented that using UICollectionViewCompositionalLayout method,
  Step to achieve this</p>
  <ul>
  <li>Get the size of image from URL.</li>
  <li>Because image size is larger so decrease image size and set in collection cell using UICollectionViewCompositionalLayout</li>
  </ul>
  <p>But when scroll tableview it is not scrolling smoothly it gets stuck for few miliseconds when this view will display in tableview. And same custom tableview cell view is used multiple times as per backend api response.
  Can i achieve this layout in collectionview using UICollectionViewCompositionalLayout? Or do i have to use 'sizeForItemAt indexPath' UICollectionViewDelegateFlowLayout method for this.</p>
  <p>I found some solutions in stackoverflow but it is for vertical collectionview but not for horizontal collectionview.</p>
  <p><strong>Result should be like horizontal collectionview collection cell size should be dynamic as per backend image size.</strong></p>
  <p>Here is below code of UICollectionViewCompositionalLayout</p>
  <pre><code>private func ProductCellLayout() -&gt; UICollectionViewCompositionalLayout{
          return UICollectionViewCompositionalLayout { (index: Int,_) -&gt; NSCollectionLayoutSection in
              let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0))
              let layoutItem = NSCollectionLayoutItem(layoutSize: itemSize)
              var width = 0.4
              var height = 1.0
              if self.viewData != nil{
                  if let url = URL(string: self.viewData?[index].displayImage ?? &quot;&quot;){
                      let size = self.sizeOfImageAt(url: url)
                      let imageWidth = size?.width ?? 1000
                      let imageHeight = size?.height ?? 1000
                      width = (imageWidth / 1000) + 0.05
                      height = imageHeight / 1000
                  }
              }
              let layoutGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(width), heightDimension: .fractionalHeight(1.0))
              let layoutGroup = NSCollectionLayoutGroup.horizontal(layoutSize: layoutGroupSize, subitems: [layoutItem])
              layoutGroup.contentInsets.trailing = 4
              layoutGroup.contentInsets.leading = 4
              let layoutSection = NSCollectionLayoutSection(group: layoutGroup)
              layoutSection.orthogonalScrollingBehavior = .continuousGroupLeadingBoundary
              return layoutSection
          }
      }
  
  </code></pre>