Skip to content

Commit

Permalink
Merge pull request #32 from NicFontana/feat/scrollview-delegate-method
Browse files Browse the repository at this point in the history
Feat: Add `scrollStackDidEndScrollingAnimation(_ stackView: ScrollStack)` delegate method
  • Loading branch information
malcommac authored Nov 13, 2024
2 parents be6fe36 + b47668b commit 8ada87d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,33 +634,37 @@ Example:

```swift
class ViewController: ScrollStackController, ScrollStackControllerDelegate {

func viewDidLoad() {
super.viewDidLoad()

self.scrollStack.stackDelegate = self
}

func scrollStackDidScroll(_ stackView: ScrollStack, offset: CGPoint) {
// stack did scroll
}

func scrollStackRowDidBecomeVisible(_ stackView: ScrollStack, row: ScrollStackRow, index: Int, state: ScrollStack.RowVisibility) {
// Row did become partially or entirely visible.
}

func viewDidLoad() {
super.viewDidLoad()

self.scrollStack.stackDelegate = self
}

func scrollStackDidScroll(_ stackView: ScrollStack, offset: CGPoint) {
// Stack did scroll
}

func scrollStackRowDidBecomeHidden(_ stackView: ScrollStack, row: ScrollStackRow, index: Int, state: ScrollStack.RowVisibility) {
// Row did become partially or entirely invisible.
}

func scrollStackDidEndScrollingAnimation(_ stackView: ScrollStack) {
// Scrolling animation has ended
}

func scrollStackDidUpdateLayout(_ stackView: ScrollStack) {
// This function is called when layout is updated (added, removed, hide or show one or more rows).
}
func scrollStackRowDidBecomeVisible(_ stackView: ScrollStack, row: ScrollStackRow, index: Int, state: ScrollStack.RowVisibility) {
// Row did become partially or entirely visible.
}

func scrollStackContentSizeDidChange(_ stackView: ScrollStack, from oldValue: CGSize, to newValue: CGSize) {
// This function is called when content size of the stack did change (remove/add, hide/show rows).
}
func scrollStackRowDidBecomeHidden(_ stackView: ScrollStack, row: ScrollStackRow, index: Int, state: ScrollStack.RowVisibility) {
// Row did become partially or entirely invisible.
}

func scrollStackDidUpdateLayout(_ stackView: ScrollStack) {
// This function is called when layout is updated (added, removed, hide or show one or more rows).
}

func scrollStackContentSizeDidChange(_ stackView: ScrollStack, from oldValue: CGSize, to newValue: CGSize) {
// This function is called when content size of the stack did change (remove/add, hide/show rows).
}
}
```

Expand Down
8 changes: 8 additions & 0 deletions Sources/ScrollStackController/ScrollStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,14 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
dispatchRowsVisibilityChangesTo(stackDelegate)
}

public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
guard let stackDelegate = stackDelegate else {
return
}

stackDelegate.scrollStackDidEndScrollingAnimation(self)
}

open override func layoutSubviews() {
super.layoutSubviews()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public protocol ScrollStackControllerDelegate: AnyObject {
/// - Parameter offset: current scroll offset.
func scrollStackDidScroll(_ stackView: ScrollStack, offset: CGPoint)

/// Tells the delegate when a scrolling animation in the scroll view concludes.
///
/// - Parameter stackView: The ScrollStack object that’s performing the scrolling animation.
func scrollStackDidEndScrollingAnimation(_ stackView: ScrollStack)

/// Row did become partially or entirely visible.
///
/// - Parameter row: target row.
Expand Down

0 comments on commit 8ada87d

Please sign in to comment.