Search code examples
eureka-forms

Eureka custom row


I'm trying to create a custom row in Eureka, but I cannot seem to find a good guide (for newbies like me) that would guide me and make me understand how to do it.

Basically, I want to create the row below using a XIB. It contains 2 labels and an image. Can anybody help make me understand how to do it properly?

Or at least point me to a place where newbies like me can understand how to implement this:

screenshot is here

Thank you.


Solution

  • I did not get too much help from the community this time, but I managed to sort it myself, so I'm going to post the answer here for other newbies like me..

    final class CartProductRow: Row<CartProductCell>, RowType {
        required init(tag: String?) {
            super.init(tag: tag)
            cellProvider = CellProvider<CartProductCell>(nibName: "CartProductCell")
        }
    }
    
    class CartProductCell: Cell<CartProduct>, CellType {
    
        @IBOutlet weak var productImage: UIImageView!
        @IBOutlet weak var productName: UILabel!
    
        required init(style: UITableViewCellStyle, reuseIdentifier: String?) {
            super.init(style: style, reuseIdentifier: reuseIdentifier)
        }
    
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
        }
    
        override func setup() {
            super.setup()
            selectionStyle = .none
    
            productImage.contentMode = .scaleAspectFill
            productImage.clipsToBounds = true
    
            productName.font = .systemFont(ofSize: 18)
    
            for label in [productName] {
                label?.textColor = .gray
            }
    
            height = { return 97 }
        }
    
        func loadImage(url: String) {
            let url = URL(string:url)
            self.productImage.kf.indicatorType = .activity
            self.productImage.kf.setImage(with: url, options: [.transition(.fade(0.9))])
        }
    
        override func update() {
            super.update()
            textLabel?.text = nil
    
            guard let product = row.value else { return }
            if let url = product.smallImageUrl {
                loadImage(url: url)
            }
    
            productName.text = product.name
        }
    }