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

39 lines
1.4 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
import TwitterTextEditor
2021-03-11 08:41:27 +01:00
extension ComposeViewModel {
func setupDiffableDataSource(
for tableView: UITableView,
dependency: NeedsDependency,
textEditorViewTextAttributesDelegate: TextEditorViewTextAttributesDelegate
) {
diffableDataSource = ComposeStatusSection.tableViewDiffableDataSource(
for: tableView,
dependency: dependency,
managedObjectContext: context.managedObjectContext,
composeKind: composeKind,
textEditorViewTextAttributesDelegate: textEditorViewTextAttributesDelegate
)
2021-03-11 08:41:27 +01:00
var snapshot = NSDiffableDataSourceSnapshot<ComposeStatusSection, ComposeStatusItem>()
snapshot.appendSections([.repliedTo, .status])
switch composeKind {
2021-03-15 06:42:46 +01:00
case .reply(let tootObjectID):
2021-03-11 08:41:27 +01:00
snapshot.appendItems([.replyTo(tootObjectID: tootObjectID)], toSection: .repliedTo)
snapshot.appendItems([.toot(replyToTootObjectID: tootObjectID, attribute: composeTootAttribute)], toSection: .status)
2021-03-15 06:42:46 +01:00
case .post:
snapshot.appendItems([.toot(replyToTootObjectID: nil, attribute: composeTootAttribute)], toSection: .status)
2021-03-11 08:41:27 +01:00
}
diffableDataSource.apply(snapshot, animatingDifferences: false)
}
}