title: collectionView Animates Color on Reload
body: <p>Whenever collectionView reloads, firstColor and secondColor mixes for a moment then get back to how they should be. For some reason adding gradient caused that problem. without gradient and with only one color this problem does not occur.</p>
  <p>Here is the video link to the problem.  <a href="https://vimeo.com/739974295" rel="nofollow noreferrer">Video</a></p>
  <pre><code>    extension PostSurveyViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return self.surveyColors.count
      }
      
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SurveyColorCollectionViewCell.identifier, for: indexPath) as? SurveyColorCollectionViewCell
          cell!.setup(surveyViewModel.surveyColors[indexPath.row])
          return cell!
      }
      
      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
          collectionView.allowsMultipleSelection = false
          for index in surveyViewModel.surveyColors.indices {
              self.surveyViewModel.surveyColors[index].isSelected = false
          }
          self.surveyViewModel.surveyColors[indexPath.row].isSelected = true
          self.collectionView.reloadData()
      }
  }
  
  class SurveyColorCollectionViewCell: UICollectionViewCell {
  
  @IBOutlet weak var bigSquare: UIView!
  
  let gradientLayer: CAGradientLayer = CAGradientLayer()
  static let identifier = String(describing: SurveyColorCollectionViewCell.self)
  
  override func awakeFromNib() {
      super.awakeFromNib()
  }
  func setupGradient(_ survey: SurveyModel) {
      gradientLayer.frame = bigSquare.bounds
      bigSquare.layer.insertSublayer(gradientLayer, at: 0)
      let topColor: CGColor = survey.firstColor.cgColor
      let bottomColor: CGColor = survey.secondColor.cgColor
      gradientLayer.colors = [topColor, bottomColor]
      gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5)
      gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5)
      bigSquare.clipsToBounds = true
  }
  
  func setup(_ survey: SurveyModel) {
      bigSquare.layer.borderWidth = 1
      bigSquare.layer.borderColor = UIColor.systemGray.cgColor
      bigSquare.layer.cornerRadius = 8
      
      self.setupGradient(survey)
  }
  
      class SurveyViewModel {
      
      var surveyColors: [SurveyModel] = []
      
      func getSurveys() {
          surveyColors = [
              SurveyModel(firstColor: UIColor.white, secondColor: UIColor.white, isSelected: true),
              SurveyModel(firstColor: UIColor(red: 255/255, green: 138/255, blue: 0/255, alpha: 1), secondColor: UIColor(red: 159/255, green: 0/255, blue: 73/255, alpha: 1), isSelected: false),
              SurveyModel(firstColor: UIColor(red: 19/255, green: 146/255, blue: 299/255, alpha: 1), secondColor: UIColor(red: 123/255, green: 0/255, blue: 139/255, alpha: 1), isSelected: false),
              SurveyModel(firstColor: UIColor(red: 68/255, green: 204/255, blue: 98/255, alpha: 1), secondColor: UIColor(red: 0/255, green: 88/255, blue: 139/255, alpha: 1), isSelected: false)
          ]
      }
  }
  
      struct SurveyModel {
      let firstColor: UIColor
      let secondColor: UIColor
      var isSelected: Bool
  }
  </code></pre>