Skip to content

Commit aaace27

Browse files
committed
Add refresh control
1 parent fdd7a19 commit aaace27

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

UI/Sources/UI/Updates/View/UpdatesSectionHeaderView.swift

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SwiftUI
99

1010
struct UpdatesSectionHeaderContentView: View {
1111
let title: String
12+
let isPressed: Bool
1213

1314
var body: some View {
1415
Text(title)
@@ -18,6 +19,7 @@ struct UpdatesSectionHeaderContentView: View {
1819
.padding(.vertical, 8)
1920
.frame(height: 120, alignment: .bottomLeading)
2021
.lineLimit(2)
22+
.opacity(isPressed ? 0.6 : 1)
2123
}
2224
}
2325

@@ -36,6 +38,7 @@ struct UpdatesSectionHeaderBackgroundView: View {
3638
.frame(width: geometry.size.width, height: geometry.size.height)
3739
.clipped()
3840
}
41+
.ignoresSafeArea()
3942
}
4043
.overlay(
4144
.linearGradient(colors: [.black.opacity(0.8), .black.opacity(0.2)], startPoint: .bottom, endPoint: .top)

UI/Sources/UI/Updates/ViewController/UpdatesViewController+DataSource.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ extension UpdatesViewController {
3232
Image(uiImage: $0.image)
3333
}
3434

35-
cell.contentConfiguration = UIHostingConfiguration {
36-
UpdatesSectionHeaderContentView(title: mangaInfo.title)
37-
}
38-
.background {
39-
UpdatesSectionHeaderBackgroundView(coverImage: image)
35+
cell.configurationUpdateHandler = { cell, state in
36+
cell.contentConfiguration = UIHostingConfiguration {
37+
UpdatesSectionHeaderContentView(title: mangaInfo.title, isPressed: state.isHighlighted)
38+
}
39+
.background {
40+
UpdatesSectionHeaderBackgroundView(coverImage: image)
41+
}
4042
}
4143

4244
if image == nil {

UI/Sources/UI/Updates/ViewController/UpdatesViewController.swift

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ final class UpdatesViewController: UIViewController {
3939
override func loadView() {
4040
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: makeCollectionViewLayout())
4141
collectionView.delegate = self
42+
collectionView.refreshControl = UIRefreshControl()
43+
collectionView.refreshControl?.addTarget(self, action: #selector(refreshCollectionView), for: .valueChanged)
4244
view = collectionView
4345
}
4446

@@ -61,4 +63,11 @@ final class UpdatesViewController: UIViewController {
6163
try await viewModel.fetchFollowedFeed()
6264
}
6365
}
66+
67+
@objc private func refreshCollectionView(_ sender: UIRefreshControl) {
68+
Task {
69+
try await viewModel.fetchFollowedFeed(resetsOffset: true)
70+
sender.endRefreshing()
71+
}
72+
}
6473
}

ViewModels/Sources/ViewModels/Updates/UpdatesViewModel.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public final class UpdatesViewModel: ObservableObject {
5252
self.sections = IdentifiedArray(uniqueElements: sections)
5353
}
5454

55-
public func fetchFollowedFeed() async throws {
56-
try await mangaService.syncUserFollowedFeed(limit: 32, offset: offset)
55+
public func fetchFollowedFeed(resetsOffset: Bool = false) async throws {
56+
try await mangaService.syncUserFollowedFeed(limit: 32, offset: resetsOffset ? 0 : offset)
5757
try loadFollowedFeedFromStorage()
5858
}
5959
}

0 commit comments

Comments
 (0)