Fix jumpy scrolling caused by reloading data
MODIFY
frontend/ios/DroidKaigi 2019/Scenes/Session/SessionDataSource.swift
frontend/ios/DroidKaigi 2019/Scenes/Session/SessionDataSource.swift
@@ -18,6 +18,8 @@ final class SessionDataSource: NSObject, UITableViewDataSource {
var toggleFavorite = PublishSubject<Session>()
+ private var cellHeightsCache = [IndexPath: CGFloat]()
+
func numberOfSections(in tableView: UITableView) -> Int {
return items.count
}
@@ -39,6 +41,7 @@ final class SessionDataSource: NSObject, UITableViewDataSource {
}
extension SessionDataSource: UITableViewDelegate {
+
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = SessionHeaderView(frame: CGRect(x: 0,
y: 0,
@@ -48,9 +51,17 @@ extension SessionDataSource: UITableViewDelegate {
return view
}
- public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false)
}
+
+ func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
+ cellHeightsCache[indexPath] = cell.frame.height
+ }
+
+ func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
+ return cellHeightsCache[indexPath] ?? UITableView.automaticDimension
+ }
}
extension SessionDataSource: RxTableViewDataSourceType {
@@ -65,6 +76,7 @@ extension SessionDataSource: RxTableViewDataSourceType {
}
extension SessionDataSource: SectionedViewDataSourceType {
+
func model(at indexPath: IndexPath) throws -> Any {
return items[indexPath.section].sessions[indexPath.row]
}

Fix jumpy scrolling caused by reloading data