Skip to content

Commit

Permalink
Fix black horizontal line on top of pulley on Mac Catalyst (#430)
Browse files Browse the repository at this point in the history
The height and position of the pulley is rounded to nearest even number on Mac Catalyst. This will fix the horizontal ghost line.
  • Loading branch information
mpfeifer-svg authored Dec 3, 2024
1 parent 31dc5d9 commit 9d58b99
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions PulleyLib/PulleyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel
} else if currentDisplayMode == .drawer {
height -= drawerTopInset
}
#if targetEnvironment(macCatalyst)
height = roundToEven(height)
#endif

return height
}
Expand Down Expand Up @@ -926,14 +929,22 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel

if supportedPositions.contains(.open)
{
var topPos = drawerTopInset + safeAreaTopInset
#if targetEnvironment(macCatalyst)
topPos = roundToEven(topPos)
#endif
// Layout scrollview
drawerScrollView.frame = CGRect(x: adjustedLeftSafeArea, y: drawerTopInset + safeAreaTopInset, width: self.view.bounds.width - adjustedLeftSafeArea - adjustedRightSafeArea, height: heightOfOpenDrawer)
drawerScrollView.frame = CGRect(x: adjustedLeftSafeArea, y: topPos, width: self.view.bounds.width - adjustedLeftSafeArea - adjustedRightSafeArea, height: heightOfOpenDrawer)
}
else
{
// Layout scrollview
let adjustedTopInset: CGFloat = getStopList().max() ?? 0.0
drawerScrollView.frame = CGRect(x: adjustedLeftSafeArea, y: self.view.bounds.height - adjustedTopInset, width: self.view.bounds.width - adjustedLeftSafeArea - adjustedRightSafeArea, height: adjustedTopInset)
var topPos = self.view.bounds.height - adjustedTopInset
#if targetEnvironment(macCatalyst)
topPos = roundToEven(topPos)
#endif
drawerScrollView.frame = CGRect(x: adjustedLeftSafeArea, y: topPos, width: self.view.bounds.width - adjustedLeftSafeArea - adjustedRightSafeArea, height: adjustedTopInset)
}

drawerScrollView.addSubview(drawerShadowView)
Expand Down Expand Up @@ -1009,7 +1020,9 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel
yOrigin = (panelCornerPlacement == .bottomLeft || panelCornerPlacement == .bottomRight) ? (panelInsets.top + safeAreaTopInset) : (panelInsets.top + safeAreaTopInset + bounceOverflowMargin)

}

#if targetEnvironment(macCatalyst)
yOrigin = roundToEven(yOrigin)
#endif
if supportedPositions.contains(.open)
{
// Layout scrollview
Expand Down Expand Up @@ -1091,7 +1104,11 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel
collapsedHeight = drawerVCCompliant.collapsedDrawerHeight?(bottomSafeArea: pulleySafeAreaInsets.bottom) ?? kPulleyDefaultCollapsedHeight
partialRevealHeight = drawerVCCompliant.partialRevealDrawerHeight?(bottomSafeArea: pulleySafeAreaInsets.bottom) ?? kPulleyDefaultPartialRevealHeight
}

#if targetEnvironment(macCatalyst)
collapsedHeight = roundToEven(collapsedHeight)
partialRevealHeight = roundToEven(partialRevealHeight)
#endif

if supportedPositions.contains(.collapsed)
{
drawerStops.append(collapsedHeight)
Expand All @@ -1104,7 +1121,11 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel

if supportedPositions.contains(.open)
{
drawerStops.append((self.view.bounds.size.height - drawerTopInset - pulleySafeAreaInsets.top))
var value = (self.view.bounds.size.height - drawerTopInset - pulleySafeAreaInsets.top)
#if targetEnvironment(macCatalyst)
value = roundToEven(value)
#endif
drawerStops.append(value)
}

return drawerStops
Expand Down Expand Up @@ -1622,6 +1643,13 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel
drawerVCCompliant.drawerChangedDistanceFromBottom?(drawer: drawer, distance: distance, bottomSafeArea: bottomSafeArea)
}
}

#if targetEnvironment(macCatalyst)
func roundToEven(_ number: CGFloat) -> CGFloat {
let rounded = number.rounded()
return rounded.remainder(dividingBy: 2) == 0 ? rounded : rounded + 1
}
#endif
}

extension PulleyViewController: PulleyPassthroughScrollViewDelegate {
Expand Down

0 comments on commit 9d58b99

Please sign in to comment.