MyRewardsBannerOfferCollectionViewCell.swift 1.46 KB
//
//  MyRewardsBannerOfferCollectionViewCell.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 23/5/25.
//

import UIKit

@objc(MyRewardsBannerOfferCollectionViewCell)
public class MyRewardsBannerOfferCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var backgroundImage: UIImageView!
    
    var postImageURL: String? {
        didSet {
            if let url = postImageURL {
                self.backgroundImage.image = UIImage() // UIImage(named: "loading")

                UIImage.loadImageUsingCacheWithUrlString(url) { image in
                    // set the image only when we are still displaying the content for the image we finished downloading
                    if url == self.postImageURL {
                        self.backgroundImage.image = image
                    }
                }
            }
            else {
                self.backgroundImage.image = nil
            }
        }
    }
    
    public override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        backgroundImage.contentMode = .scaleAspectFill
    }
    
    func configureCell(data: CampaignItemModel) {
        // Use campaign's banner image - no hardcoded defaults
        self.postImageURL = data._banner_img_mobile ?? ""
    }
    
    func configureCell(data: ArticleModel) {
        // Use article's preview image - same visual treatment as campaigns
        self.postImageURL = data.img_preview ?? ""
    }
}