mastodon-app-ufficiale-ipho.../Mastodon/Scene/Compose/ComposeViewModel+Diffable.s...

41 lines
1.6 KiB
Swift
Raw Normal View History

2021-03-11 08:41:27 +01:00
//
// ComposeViewModel+Diffable.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-3-11.
//
import UIKit
extension ComposeViewModel {
func setupDiffableDataSource(for tableView: UITableView) {
diffableDataSource = UITableViewDiffableDataSource(tableView: tableView) { [weak self] tableView, indexPath, item -> UITableViewCell? in
guard let self = self else { return nil }
switch item {
case .replyTo(let tootObjectID):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ComposeRepliedToTootContentTableViewCell.self), for: indexPath) as! ComposeRepliedToTootContentTableViewCell
// TODO:
return cell
case .toot(let attribute):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ComposeTootContentTableViewCell.self), for: indexPath) as! ComposeTootContentTableViewCell
// TODO:
return cell
}
}
var snapshot = NSDiffableDataSourceSnapshot<ComposeStatusSection, ComposeStatusItem>()
snapshot.appendSections([.repliedTo, .status])
switch composeKind {
case .replyToot(let tootObjectID):
snapshot.appendItems([.replyTo(tootObjectID: tootObjectID)], toSection: .repliedTo)
snapshot.appendItems([.toot(replyToTootObjectID: tootObjectID)], toSection: .status)
2021-03-11 08:41:27 +01:00
case .toot:
snapshot.appendItems([.toot(replyToTootObjectID: nil)], toSection: .status)
2021-03-11 08:41:27 +01:00
}
diffableDataSource.apply(snapshot, animatingDifferences: false)
}
}