mastodon-ios/Mastodon/Scene/Profile/Timeline/UserTimelineViewModel+Diffa...

40 lines
1.3 KiB
Swift
Raw Normal View History

2021-04-01 08:39:15 +02:00
//
// UserTimelineViewModel+Diffable.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-3-30.
//
import UIKit
extension UserTimelineViewModel {
func setupDiffableDataSource(
for tableView: UITableView,
dependency: NeedsDependency,
statusTableViewCellDelegate: StatusTableViewCellDelegate
) {
let timestampUpdatePublisher = Timer.publish(every: 1.0, on: .main, in: .common)
.autoconnect()
.share()
.eraseToAnyPublisher()
diffableDataSource = StatusSection.tableViewDiffableDataSource(
for: tableView,
dependency: dependency,
managedObjectContext: statusFetchedResultsController.fetchedResultsController.managedObjectContext,
timestampUpdatePublisher: timestampUpdatePublisher,
statusTableViewCellDelegate: statusTableViewCellDelegate,
2021-04-13 13:46:42 +02:00
timelineMiddleLoaderTableViewCellDelegate: nil,
threadReplyLoaderTableViewCellDelegate: nil
2021-04-01 08:39:15 +02:00
)
// set empty section to make update animation top-to-bottom style
var snapshot = NSDiffableDataSourceSnapshot<StatusSection, Item>()
snapshot.appendSections([.main])
snapshot.appendItems([.bottomLoader], toSection: .main)
2021-04-01 08:39:15 +02:00
diffableDataSource?.apply(snapshot)
}
}