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 Combine
|
||||||
|
import ReviewsUIKit
|
||||||
|
import SwiftUI
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public class FeedViewController: UITableViewController {
|
public class FeedViewController: UITableViewController {
|
||||||
@ -30,9 +32,11 @@ public class FeedViewController: UITableViewController {
|
|||||||
public override func viewDidLoad() {
|
public override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
tableView.register(ReviewCell.self, forCellReuseIdentifier: "cellId")
|
tableView.register(
|
||||||
tableView.rowHeight = 160
|
UITableViewCell.self,
|
||||||
|
forCellReuseIdentifier: .Cell.feedItem
|
||||||
|
)
|
||||||
|
|
||||||
bindViewModel()
|
bindViewModel()
|
||||||
|
|
||||||
viewModel.fetch()
|
viewModel.fetch()
|
||||||
@ -50,16 +54,21 @@ public class FeedViewController: UITableViewController {
|
|||||||
_ tableView: UITableView,
|
_ tableView: UITableView,
|
||||||
cellForRowAt indexPath: IndexPath
|
cellForRowAt indexPath: IndexPath
|
||||||
) -> UITableViewCell {
|
) -> UITableViewCell {
|
||||||
guard
|
guard let cell = tableView.dequeueReusableCell(withIdentifier: .Cell.feedItem) else {
|
||||||
let cell = tableView.dequeueReusableCell(
|
|
||||||
withIdentifier: "cellId",
|
|
||||||
for: indexPath
|
|
||||||
) as? ReviewCell
|
|
||||||
else {
|
|
||||||
return .init()
|
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
|
return cell
|
||||||
}
|
}
|
||||||
@ -93,8 +102,8 @@ private extension FeedViewController {
|
|||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
viewModel.$loading
|
viewModel.$loading
|
||||||
.filter { $0 == false }
|
|
||||||
.dropFirst()
|
.dropFirst()
|
||||||
|
.filter { $0 == false }
|
||||||
.receive(on: RunLoop.main)
|
.receive(on: RunLoop.main)
|
||||||
.sink { [weak self] _ in
|
.sink { [weak self] _ in
|
||||||
self?.tableView.reloadData()
|
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