feat: profile timeline scroll performance

This commit is contained in:
CMK 2021-02-24 17:23:01 +08:00
parent 738ba832a9
commit a79f5140b5
2 changed files with 15 additions and 14 deletions

View File

@ -23,6 +23,13 @@ extension LoadMoreConfigurableTableViewContainer {
func handleScrollViewDidScroll(_ scrollView: UIScrollView) { func handleScrollViewDidScroll(_ scrollView: UIScrollView) {
guard scrollView === loadMoreConfigurableTableView else { return } guard scrollView === loadMoreConfigurableTableView else { return }
// check if current scroll position is the bottom of table
let contentOffsetY = loadMoreConfigurableTableView.contentOffset.y
let bottomVisiblePageContentOffsetY = loadMoreConfigurableTableView.contentSize.height - (1.5 * loadMoreConfigurableTableView.visibleSize.height)
guard contentOffsetY > bottomVisiblePageContentOffsetY else {
return
}
let cells = loadMoreConfigurableTableView.visibleCells.compactMap { $0 as? BottomLoaderTableViewCell } let cells = loadMoreConfigurableTableView.visibleCells.compactMap { $0 as? BottomLoaderTableViewCell }
guard let loaderTableViewCell = cells.first else { return } guard let loaderTableViewCell = cells.first else { return }

View File

@ -175,23 +175,17 @@ extension HomeTimelineViewController {
// MARK: - UIScrollViewDelegate // MARK: - UIScrollViewDelegate
extension HomeTimelineViewController { extension HomeTimelineViewController {
func scrollViewDidScroll(_ scrollView: UIScrollView) { func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard scrollView === tableView else { return } handleScrollViewDidScroll(scrollView)
let cells = tableView.visibleCells.compactMap { $0 as? TimelineBottomLoaderTableViewCell }
guard let loaderTableViewCell = cells.first else { return }
if let tabBar = tabBarController?.tabBar, let window = view.window {
let loaderTableViewCellFrameInWindow = tableView.convert(loaderTableViewCell.frame, to: nil)
let windowHeight = window.frame.height
let loaderAppear = (loaderTableViewCellFrameInWindow.origin.y + 0.8 * loaderTableViewCell.frame.height) < (windowHeight - tabBar.frame.height)
if loaderAppear {
viewModel.loadoldestStateMachine.enter(HomeTimelineViewModel.LoadOldestState.Loading.self)
}
} else {
viewModel.loadoldestStateMachine.enter(HomeTimelineViewModel.LoadOldestState.Loading.self)
}
} }
} }
extension HomeTimelineViewController: LoadMoreConfigurableTableViewContainer {
typealias BottomLoaderTableViewCell = TimelineBottomLoaderTableViewCell
typealias LoadingState = HomeTimelineViewModel.LoadOldestState.Loading
var loadMoreConfigurableTableView: UITableView { return tableView }
var loadMoreConfigurableStateMachine: GKStateMachine { return viewModel.loadoldestStateMachine }
}
// MARK: - UITableViewDelegate // MARK: - UITableViewDelegate
extension HomeTimelineViewController: UITableViewDelegate { extension HomeTimelineViewController: UITableViewDelegate {