Skip to content

Commit

Permalink
Exposes to clients per jessesquires#131
Browse files Browse the repository at this point in the history
  • Loading branch information
ruddfawcett committed Sep 29, 2024
1 parent c697cfa commit e23ff7a
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions Sources/CollectionViewDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public final class CollectionViewDriver: NSObject {

/// The collection view model.
@Published public private(set) var viewModel: CollectionViewModel

/// The scroll view delegate to forward.
public weak var scrollViewDelegate: UIScrollViewDelegate?

private let _emptyViewProvider: EmptyViewProvider?

Expand Down Expand Up @@ -355,3 +358,96 @@ extension CollectionViewDriver: UICollectionViewDelegate {
self.viewModel._safeSupplementaryViewModel(ofKind: elementKind, at: indexPath)?.didEndDisplaying()
}
}

// MARK: UIScrollViewDelegate

extension CollectionViewDriver: UIScrollViewDelegate {
// MARK: Managing offset and zoom scale changes

/// :nodoc:
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.scrollViewDelegate?.scrollViewDidScroll?(scrollView)
}

/// :nodoc:
public func scrollViewDidZoom(_ scrollView: UIScrollView) {
self.scrollViewDelegate?.scrollViewDidZoom?(scrollView)
}

// MARK: Tracking dragging

/// :nodoc:
public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.scrollViewDelegate?.scrollViewWillBeginDragging?(scrollView)
}

/// :nodoc:
public func scrollViewWillEndDragging(_ scrollView: UIScrollView,
withVelocity velocity: CGPoint,
targetContentOffset: UnsafeMutablePointer<CGPoint>) {
self.scrollViewDelegate?.scrollViewWillEndDragging?(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
}

/// :nodoc:
public func scrollViewDidEndDragging(_ scrollView: UIScrollView,
willDecelerate decelerate: Bool) {
self.scrollViewDelegate?.scrollViewDidEndDragging?(scrollView, willDecelerate: decelerate)
}

// MARK: Tracking deceleration and scrolling animation

/// :nodoc:
public func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
self.scrollViewDelegate?.scrollViewWillBeginDragging?(scrollView)
}

/// :nodoc:
public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
self.scrollViewDelegate?.scrollViewDidEndDecelerating?(scrollView)
}

/// :nodoc:
public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
self.scrollViewDelegate?.scrollViewDidEndScrollingAnimation?(scrollView)
}

// MARK: Managing and tracking zooming more granularly

/// :nodoc:
public func viewForZooming(in scrollView: UIScrollView) -> UIView? {
self.scrollViewDelegate?.viewForZooming?(in: scrollView)
}

/// :nodoc:
public func scrollViewWillBeginZooming(_ scrollView: UIScrollView,
with view: UIView?) {
self.scrollViewDelegate?.scrollViewWillBeginZooming?(scrollView, with: view)
}

/// :nodoc:
public func scrollViewDidEndZooming(_ scrollView: UIScrollView,
with view: UIView?,
atScale scale: CGFloat) {
self.scrollViewDelegate?.scrollViewDidEndZooming?(scrollView, with: view, atScale: scale)
}

// MARK: Managing if should scroll to top and tracking if done so

/// :nodoc:
public func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
self.scrollViewDelegate?.scrollViewShouldScrollToTop?(scrollView) ?? true
}

/// :nodoc:
public func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
self.scrollViewDelegate?.scrollViewDidScrollToTop?(scrollView)
}


// MARK: Tracking adjusted content insets on scroll view

/// :nodoc:
public func scrollViewDidChangeAdjustedContentInset(_ scrollView: UIScrollView) {
self.scrollViewDelegate?.scrollViewDidChangeAdjustedContentInset?(scrollView)
}
}

0 comments on commit e23ff7a

Please sign in to comment.