ra1028/Carbon

Add helper scroll methods

andrefmsilva opened this issue · 1 comments

I know this is a bit out of context of the framework, but some methods to scroll the target to a specific section id or cell id are really useful.

That can be done with the following simple code:

enum SectionID: CaseIterable {
    case first, second, third
}

// render sections with order same as SectionID.allCases
renderer.data = SectionID.allCases.map { id in
    Section(id: id, header: ..., footer: ..., cells: ...)
}

// take section index from allCases
if let index = SectionID.allCases.firstIndex(of: .second) {
    let indexPath = IndexPath(item: 0, section: index)
    // scroll to the top of row in the specified section
    tableView.scrollToRow(at: indexPath, at: .top, animated: true)
}