main
swift 74 lines 2.11 KB
Raw
1 //
2 // ContinueWatchingSection.swift
3 // JomloCollectionView Example
4 //
5 // Created by Seto Elkahfi on 2026-01-27.
6 // Copyright © 2026 Seto Elkahfi. All rights reserved.
7 //
8
9 import JomloCollectionView
10 import UIKit
11
12 @MainActor
13 final class ContinueWatchingSection: JomloSection {
14
15 let identifier = JomloSectionID("continue-watching")
16 var onReloadNeeded: (@MainActor @Sendable () -> Void)?
17
18 private let watchingItems: [ContinueWatchingItem]
19
20 init(items: [ContinueWatchingItem]) {
21 self.watchingItems = items
22 }
23
24 func items() -> [any JomloItem] {
25 watchingItems
26 }
27
28 func layoutSection(
29 environment: NSCollectionLayoutEnvironment,
30 sectionIndex: Int
31 ) -> NSCollectionLayoutSection {
32 JomloLayoutFactory.horizontalShelf(
33 itemWidth: .absolute(200),
34 itemHeight: .absolute(170),
35 interItemSpacing: 12,
36 headerHeight: .estimated(44)
37 )
38 }
39
40 func cell(
41 for item: any JomloItem,
42 in collectionView: UICollectionView,
43 at indexPath: IndexPath
44 ) -> UICollectionViewCell {
45 guard let watchingItem = item as? ContinueWatchingItem else {
46 return UICollectionViewCell()
47 }
48 return collectionView.dequeueJomloCell(
49 ContinueWatchingCell.self, for: indexPath, item: watchingItem)
50 }
51
52 func supplementaryView(
53 ofKind kind: String,
54 in collectionView: UICollectionView,
55 at indexPath: IndexPath
56 ) -> UICollectionReusableView? {
57 guard kind == UICollectionView.elementKindSectionHeader else { return nil }
58 guard
59 let header = collectionView.dequeueReusableSupplementaryView(
60 ofKind: kind,
61 withReuseIdentifier: JomloSectionHeaderView.reuseIdentifier,
62 for: indexPath
63 ) as? JomloSectionHeaderView
64 else {
65 return nil
66 }
67 header.configure(title: "Continue Watching")
68 return header
69 }
70
71 var displayAnimation: JomloAnimator.Animation? {
72 JomloAnimator.moveUpWithFade(offset: 20, duration: 0.4, delayFactor: 0.08)
73 }
74 }