From 7de2809ac9ce256db7b849b7f000c080db632fe5 Mon Sep 17 00:00:00 2001 From: Marco Del Giudice Date: Thu, 30 May 2024 18:42:45 +0200 Subject: [PATCH] =?UTF-8?q?Add=20visibility=20percentage=20to=20partial=20?= =?UTF-8?q?Rowv=C3=ACVisibility=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/ScrollStackController/ScrollStack.swift | 8 +++++++- .../Support/ScrollStack+Protocols.swift | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/ScrollStackController/ScrollStack.swift b/Sources/ScrollStackController/ScrollStack.swift index ec58435..2d2caa0 100644 --- a/Sources/ScrollStackController/ScrollStack.swift +++ b/Sources/ScrollStackController/ScrollStack.swift @@ -794,7 +794,13 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate { return .offscreen } - return (bounds.contains(rowFrame) ? .entire : .partial) + if bounds.contains(rowFrame) { + return .entire + } else { + let intersection = bounds.intersection(rowFrame) + let intersectionPercentage = ((intersection.width * intersection.height) / (rowFrame.width * rowFrame.height)) * 100 + return .partial(percentage: intersectionPercentage) + } } /// Remove passed row from stack view. diff --git a/Sources/ScrollStackController/Support/ScrollStack+Protocols.swift b/Sources/ScrollStackController/Support/ScrollStack+Protocols.swift index 204ac98..2aceebd 100644 --- a/Sources/ScrollStackController/Support/ScrollStack+Protocols.swift +++ b/Sources/ScrollStackController/Support/ScrollStack+Protocols.swift @@ -177,9 +177,9 @@ public extension ScrollStack { /// - `hidden`: row is invisible and hidden. /// - `offscreen`: row is not hidden but currently offscreen due to scroll position. /// - `removed`: row is removed manually. - enum RowVisibility { + enum RowVisibility: Equatable { case hidden - case partial + case partial(percentage: Double) case entire case offscreen case removed