Integrated the FeedItem component into the FeedViewController view controller in the Feed framework.
This commit is contained in:
parent
de79b45b16
commit
a4fa2210e1
@ -7,6 +7,8 @@
|
||||
//
|
||||
|
||||
import Combine
|
||||
import ReviewsUIKit
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
public class FeedViewController: UITableViewController {
|
||||
@ -30,9 +32,11 @@ public class FeedViewController: UITableViewController {
|
||||
public override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
tableView.register(ReviewCell.self, forCellReuseIdentifier: "cellId")
|
||||
tableView.rowHeight = 160
|
||||
|
||||
tableView.register(
|
||||
UITableViewCell.self,
|
||||
forCellReuseIdentifier: .Cell.feedItem
|
||||
)
|
||||
|
||||
bindViewModel()
|
||||
|
||||
viewModel.fetch()
|
||||
@ -50,16 +54,21 @@ public class FeedViewController: UITableViewController {
|
||||
_ tableView: UITableView,
|
||||
cellForRowAt indexPath: IndexPath
|
||||
) -> UITableViewCell {
|
||||
guard
|
||||
let cell = tableView.dequeueReusableCell(
|
||||
withIdentifier: "cellId",
|
||||
for: indexPath
|
||||
) as? ReviewCell
|
||||
else {
|
||||
guard let cell = tableView.dequeueReusableCell(withIdentifier: .Cell.feedItem) else {
|
||||
return .init()
|
||||
}
|
||||
|
||||
cell.update(item: viewModel.items[indexPath.row])
|
||||
cell.contentConfiguration = {
|
||||
if #available(iOS 16.0, *) {
|
||||
UIHostingConfiguration {
|
||||
FeedItem(viewModel.items[indexPath.row])
|
||||
}
|
||||
} else {
|
||||
HostingConfiguration {
|
||||
FeedItem(viewModel.items[indexPath.row])
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return cell
|
||||
}
|
||||
@ -93,8 +102,8 @@ private extension FeedViewController {
|
||||
.store(in: &cancellables)
|
||||
|
||||
viewModel.$loading
|
||||
.filter { $0 == false }
|
||||
.dropFirst()
|
||||
.filter { $0 == false }
|
||||
.receive(on: RunLoop.main)
|
||||
.sink { [weak self] _ in
|
||||
self?.tableView.reloadData()
|
||||
@ -103,3 +112,10 @@ private extension FeedViewController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
private extension String {
|
||||
enum Cell {
|
||||
static let feedItem = "FeedItemCell"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user