Few.swift
Few.swift copied to clipboard
iOS: table view selection doesn't really work
@joshaber We call reloadData()
every time we diff a TableView, and that kills our selection. I'll work on this one – just putting it here as a reminder.
Current thinking is we need to make Element
equatable, and not call reloadData()
unless our row data has actually changed. Thoughts?
Good one
This seems hard to fix because if you want to make Element
conform to Equatable
you have to check all properties of Element
and also all subclasses must overwrite the ==
func to add checks for their properties.
Yeah, I'd really like to avoid making Element
Equatable
for those reasons :point_up:
On Mac we save and restore the selected indexes: https://github.com/joshaber/Few.swift/blob/221ff4ccf6c339bb7d815398614556b07a80073d/Few-Mac/TableView.swift#L53-56 Could we do that on iOS too?
@Adlai-Holler you can do something like this to preserve the selection:
TableView([state.elements],
selectedRow: state.selected,
selectionChanged: { [unowned component] indexPath in
component.updateState { state in
var state = state
state.selected = indexPath
return state
}
})
struct AppState {
var elements: [Element]
var selected: NSIndexPath?
}
To me it seems ok that elements do not have state. You can make component that wraps TableView element and adds state in this way. Otherwise leaving state management to native implementation of UITableView seems to me like leaky abstraction.
Hi there!!! My name is Patrick and i'm begin in coding, i was hoping if it's possible if you can help me to understand how this github work, and what it does basically.