Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.

Commit bf03b41

Browse files
Merge pull request #205 from eonfluxor/feature/displayDelegate
2 parents 2bb3269 + a078d33 commit bf03b41

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

Sources/ASCollectionView/ASCollectionView+Modifiers.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ASCollectionView. Created by Apptek Studios 2019
22

3-
import Foundation
3+
import UIKit
44
import SwiftUI
55

66
// MARK: Modifer: Custom Delegate
@@ -92,6 +92,22 @@ public extension ASCollectionView
9292
return this
9393
}
9494

95+
/// Set a closure that is called when the collectionView will display a cell
96+
func onWillDisplay(_ callback: ((UICollectionViewCell, IndexPath)->Void)?) -> Self
97+
{
98+
var this = self
99+
this.onWillDisplay = callback
100+
return this
101+
}
102+
103+
/// Set a closure that is called when the collectionView did display a cell
104+
func onDidDisplay(_ callback: ((UICollectionViewCell, IndexPath)->Void)?) -> Self
105+
{
106+
var this = self
107+
this.onDidDisplay = callback
108+
return this
109+
}
110+
95111
/// Set a closure that is called when the collectionView is pulled to refresh
96112
func onPullToRefresh(_ callback: ((_ endRefreshing: @escaping (() -> Void)) -> Void)?) -> Self
97113
{

Sources/ASCollectionView/ASTableView+Modifiers.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ public extension ASTableView
4848
this.contentInsets = insets
4949
return this
5050
}
51+
52+
/// Set a closure that is called when the collectionView will display a cell
53+
func onWillDisplay(_ callback: ((UITableViewCell, IndexPath)->Void)?) -> Self
54+
{
55+
var this = self
56+
this.onWillDisplay = callback
57+
return this
58+
}
59+
60+
/// Set a closure that is called when the collectionView did display a cell
61+
func onDidDisplay(_ callback: ((UITableViewCell, IndexPath)->Void)?) -> Self
62+
{
63+
var this = self
64+
this.onDidDisplay = callback
65+
return this
66+
}
5167

5268
/// Set a closure that is called when the tableView is pulled to refresh
5369
func onPullToRefresh(_ callback: ((_ endRefreshing: @escaping (() -> Void)) -> Void)?) -> Self

Sources/ASCollectionView/Implementation/ASCollectionView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public struct ASCollectionView<SectionID: Hashable>: UIViewControllerRepresentab
3636
internal var contentInsets: UIEdgeInsets = .zero
3737

3838
internal var onPullToRefresh: ((_ endRefreshing: @escaping (() -> Void)) -> Void)?
39+
40+
internal var onWillDisplay: ((UICollectionViewCell, IndexPath) -> Void)?
41+
42+
internal var onDidDisplay: ((UICollectionViewCell, IndexPath) -> Void)?
3943

4044
internal var alwaysBounceVertical: Bool = false
4145
internal var alwaysBounceHorizontal: Bool = false
@@ -631,12 +635,14 @@ public struct ASCollectionView<SectionID: Hashable>: UIViewControllerRepresentab
631635
currentlyPrefetching.remove(indexPath)
632636
parent.sections[safe: indexPath.section]?.dataSource.onAppear(indexPath)
633637
queuePrefetch.send()
638+
parent.onWillDisplay?(cell, indexPath)
634639
}
635640

636641
public func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath)
637642
{
638643
guard !indexPath.isEmpty else { return }
639644
parent.sections[safe: indexPath.section]?.dataSource.onDisappear(indexPath)
645+
parent.onDidDisplay?(cell, indexPath)
640646
}
641647

642648
public func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath)

Sources/ASCollectionView/Implementation/ASTableView.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
3535
internal var separatorsEnabled: Bool = true
3636

3737
internal var onPullToRefresh: ((_ endRefreshing: @escaping (() -> Void)) -> Void)?
38+
39+
internal var onWillDisplay: ((UITableViewCell, IndexPath) -> Void)?
40+
41+
internal var onDidDisplay: ((UITableViewCell, IndexPath) -> Void)?
3842

3943
internal var alwaysBounce: Bool = false
4044
internal var animateOnDataRefresh: Bool = true
@@ -390,11 +394,14 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
390394
public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
391395
{
392396
parent.sections[safe: indexPath.section]?.dataSource.onAppear(indexPath)
393-
}
397+
parent.onWillDisplay?(cell,indexPath)
398+
399+
}
394400

395401
public func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath)
396402
{
397403
parent.sections[safe: indexPath.section]?.dataSource.onDisappear(indexPath)
404+
parent.onDidDisplay?(cell,indexPath)
398405
}
399406

400407
public func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int)

0 commit comments

Comments
 (0)