Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Scene/Compose/ComposeViewModel+Diffable.s...

36 lines
1.2 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,
dependency: NeedsDependency
) {
diffableDataSource = ComposeStatusSection.tableViewDiffableDataSource(
for: tableView,
dependency: dependency,
managedObjectContext: context.managedObjectContext,
composeKind: composeKind
)
2021-03-11 08:41:27 +01:00
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, attribute: composeTootAttribute)], toSection: .status)
2021-03-11 08:41:27 +01:00
case .toot:
snapshot.appendItems([.toot(replyToTootObjectID: nil, attribute: composeTootAttribute)], toSection: .status)
2021-03-11 08:41:27 +01:00
}
diffableDataSource.apply(snapshot, animatingDifferences: false)
}
}