Shopify / FunctionalTableData

Declarative UITableViewDataSource implementation
MIT License
365 stars 30 forks source link

Mutable cell actions #189

Closed raulriera closed 4 years ago

raulriera commented 4 years ago

What

This change allows the cell actions to be changed in place. They are still structs, so everything will still be copied around nicely.

Use case

I am working on a view controller that "auto magically" adds visibilityAction to all the cells it passes through its render, in order to do this I need to be able to modify the actions directly and set them back. Pretty much this

content.rows.enumerated().map { index, row in
    var row = row
    /// Store any previous visibility action to be called side by side with our new one.
    let oldVisibilityAction = row.actions.visibilityAction
    row.actions.visibilityAction = { [weak self] view, visible in
        oldVisibilityAction?(view, visible)
        guard visible else { return }
            self?.didChangePage(to: index)
        }
        return row
}