Skip to content

Commit

Permalink
Add ScrollViewDelegate conformance (#215)
Browse files Browse the repository at this point in the history
* Add UIScrollViewDelegate conformance

- Add did scroll closure to TableViewModel to handle scroll events.

* Update podspec

* Update doc

* Update ci.yml

---------

Co-authored-by: Nicholas Wroblewski <njw438@gmail.com>
  • Loading branch information
marco-evc and njw438 committed May 30, 2023
1 parent b511190 commit 30cab90
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
runs-on: macOS-latest
strategy:
matrix:
destination: ["OS=14.5,name=iPhone 11"]
destination: ["OS=15.0,name=iPhone 13"]
steps:
- uses: actions/checkout@v1
- name: Select Xcode version
run: sudo xcode-select -s '/Applications/Xcode_12.5.1.app/Contents/Developer'
run: sudo xcode-select -s '/Applications/Xcode_14.2.app/Contents/Developer'
- name: Bundle Install
run: bundle install
- uses: actions/cache@v1
Expand Down
2 changes: 1 addition & 1 deletion ReactiveLists.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ReactiveLists"
s.version = "0.8.1.beta.6"
s.version = "0.8.1.beta.7"

s.summary = "React-like API for UITableView and UICollectionView"
s.homepage = "https://github.com/plangrid/ReactiveLists"
Expand Down
8 changes: 8 additions & 0 deletions Sources/TableViewDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,11 @@ extension TableViewDriver: UITableViewDelegate {
return self.tableViewModel?[ifExists: indexPath]?.shouldHighlight ?? true
}
}

extension TableViewDriver: UIScrollViewDelegate {
/// :nodoc:
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard let tableViewModel = tableViewModel else { return }
tableViewModel.didScrollClosure?(scrollView)
}
}
11 changes: 8 additions & 3 deletions Sources/TableViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,19 @@ public struct TableViewModel {
return self.sectionModels.allSatisfy { $0.isEmpty }
}

/// Invoked when the tableview is scrolled
public var didScrollClosure: DidScrollClosure?

/// Initializes a table view model with one section and the cell models provided
/// via the initializer.
///
/// - Parameter cellViewModels: the cell models for the only section in this table.
public init(cellViewModels: [TableCellViewModel]) {
public init(cellViewModels: [TableCellViewModel], didScrollClosure: DidScrollClosure? = nil) {
let section = TableSectionViewModel(
diffingKey: "default_section",
cellViewModels: cellViewModels
)
self.init(sectionModels: [section])
self.init(sectionModels: [section], didScrollClosure: didScrollClosure)
}

/// Initializes a table view model with the sections provided.
Expand All @@ -345,10 +348,12 @@ public struct TableViewModel {
/// - Parameters:
/// - sectionModels: the sections that need to be shown in this table view.
/// - sectionIndexTitles: the section index titles for this table view.
public init(sectionModels: [TableSectionViewModel], sectionIndexTitles: [String]? = nil, defaultRowHeight: CGFloat = 44.0) {
/// - didScrollClosure: the scroll closure for this table view.
public init(sectionModels: [TableSectionViewModel], sectionIndexTitles: [String]? = nil, defaultRowHeight: CGFloat = 44.0, didScrollClosure: DidScrollClosure? = nil) {
self.sectionModels = sectionModels
self.sectionIndexTitles = sectionIndexTitles
self.defaultRowHeight = defaultRowHeight
self.didScrollClosure = didScrollClosure
}

/// Returns the section model at the specified index or `nil` if no such section exists.
Expand Down
2 changes: 2 additions & 0 deletions Sources/Typealiases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ public typealias WillBeginEditingClosure = () -> Void
public typealias DidEndEditingClosure = () -> Void
/// :nodoc:
public typealias AccessoryButtonTappedClosure = () -> Void
/// :nodoc:
public typealias DidScrollClosure = (UIScrollView) -> Void

0 comments on commit 30cab90

Please sign in to comment.