mastodon-ios/Mastodon/Scene/Notification/Cell/NotificationTableViewCell+V...

67 lines
1.8 KiB
Swift
Raw Normal View History

//
// NotificationView+ViewModel.swift
// Mastodon
//
// Created by MainasuK on 2022-1-21.
//
import UIKit
import Combine
import CoreDataStack
2023-11-22 12:32:04 +01:00
import MastodonSDK
extension NotificationTableViewCell {
final class ViewModel {
let value: Value
init(value: Value) {
self.value = value
}
enum Value {
2023-11-22 12:32:04 +01:00
case feed(MastodonFeed)
}
}
}
extension NotificationTableViewCell {
func configure(
tableView: UITableView,
viewModel: ViewModel,
delegate: NotificationTableViewCellDelegate?
) {
if notificationView.frame == .zero {
// set status view width
notificationView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin
2023-09-21 12:52:05 +02:00
notificationView.statusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin
notificationView.quoteStatusView.frame.size.width = tableView.frame.width - containerViewHorizontalMargin // the as same width as statusView
}
switch viewModel.value {
case .feed(let feed):
notificationView.configure(feed: feed)
}
self.delegate = delegate
Publishers.CombineLatest(
notificationView.statusView.viewModel.$isContentReveal.removeDuplicates(),
notificationView.quoteStatusView.viewModel.$isContentReveal.removeDuplicates()
)
.dropFirst()
.receive(on: DispatchQueue.main)
2023-09-21 14:11:44 +02:00
.sink { [weak tableView] _, _ in
guard let tableView = tableView else { return }
UIView.performWithoutAnimation {
tableView.beginUpdates()
tableView.endUpdates()
}
}
.store(in: &disposeBag)
}
}