Skip to content

Commit

Permalink
fix: Update VisibleRadioCalculator calculating logic
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekTree0101 committed May 16, 2024
1 parent 356e7d7 commit 41ac49e
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions Sources/SushiBelt/Private/VisibleRatioCalculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,9 @@ public struct DefaultVisibleRatioCalculator: VisibleRatioCalculator {
trackingRect: CGRect,
scrollDirection: SushiBeltTrackerScrollDirection?
) -> CGFloat? {

guard let scrollDirection = scrollDirection else {
return nil
}

let visibleRect = trackingRect.intersection(item.rect.frameInWindow)

switch scrollDirection {
case .up, .down:
return min(1.0, visibleRect.height / item.rect.frameInWindow.height)
case .left, .right:
return min(1.0, visibleRect.width / item.rect.frameInWindow.width)
case .diagonal:
return nil
}
let itemRectPixels = item.rect.frameInWindow.height * item.rect.frameInWindow.width
let visiblePixels = visibleRect.height * visibleRect.width
return visiblePixels / itemRectPixels
}
}

0 comments on commit 41ac49e

Please sign in to comment.