Skip to content

Commit a978644

Browse files
authored
Merge pull request #31 from Marcodeg/feature/visbility-percentage
Add visibility percentage to partial RowvìVisibility case
2 parents 71363b2 + 7de2809 commit a978644

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Sources/ScrollStackController/ScrollStack.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,13 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
794794
return .offscreen
795795
}
796796

797-
return (bounds.contains(rowFrame) ? .entire : .partial)
797+
if bounds.contains(rowFrame) {
798+
return .entire
799+
} else {
800+
let intersection = bounds.intersection(rowFrame)
801+
let intersectionPercentage = ((intersection.width * intersection.height) / (rowFrame.width * rowFrame.height)) * 100
802+
return .partial(percentage: intersectionPercentage)
803+
}
798804
}
799805

800806
/// Remove passed row from stack view.

Sources/ScrollStackController/Support/ScrollStack+Protocols.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ public extension ScrollStack {
177177
/// - `hidden`: row is invisible and hidden.
178178
/// - `offscreen`: row is not hidden but currently offscreen due to scroll position.
179179
/// - `removed`: row is removed manually.
180-
enum RowVisibility {
180+
enum RowVisibility: Equatable {
181181
case hidden
182-
case partial
182+
case partial(percentage: Double)
183183
case entire
184184
case offscreen
185185
case removed

0 commit comments

Comments
 (0)