Skip to content

Commit

Permalink
Merge pull request #33 from deliveryhero/bugfix/SMNU-2694/fix-vendor-…
Browse files Browse the repository at this point in the history
…info-scrolling

Bugfix-SMNU-2694: Fix issue with receiving touch events on header view
  • Loading branch information
nazihalbach authored May 9, 2022
2 parents 9aab111 + a2bea11 commit c9b33e6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Sources/ParallaxPagerView/ParallaxPagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class ParallaxPagerView: UIView {
private var rightSwipeGestureRecognizer: UISwipeGestureRecognizer?

private var internalScrollView: UIScrollView
private let shouldReceiveHeaderGestures: Bool

public init(
containerViewController: UIViewController,
Expand All @@ -52,7 +53,8 @@ public final class ParallaxPagerView: UIView {
minimumHeaderHeight: CGFloat,
scaleHeaderOnBounce: Bool,
contentViewController: TabViewController,
parallaxDelegate: ParallaxViewDelegate?
parallaxDelegate: ParallaxViewDelegate?,
shouldReceiveHeaderGestures: Bool = true
) {
self.containerViewController = containerViewController
self.headerView = headerView
Expand All @@ -62,6 +64,7 @@ public final class ParallaxPagerView: UIView {
viewControllers = [contentViewController]
self.parallaxDelegate = parallaxDelegate
internalScrollView = UIScrollView(frame: containerViewController.view.bounds)
self.shouldReceiveHeaderGestures = shouldReceiveHeaderGestures
super.init(frame: containerViewController.view.bounds)

baseConfig()
Expand All @@ -78,7 +81,8 @@ public final class ParallaxPagerView: UIView {
tabsView: PagerTab & UIView,
viewControllers: [TabViewController],
pagerDelegate: PagerDelegate?,
parallaxDelegate: ParallaxViewDelegate?
parallaxDelegate: ParallaxViewDelegate?,
shouldReceiveHeaderGestures: Bool = true
) {
self.containerViewController = containerViewController
self.headerView = headerView
Expand All @@ -91,6 +95,7 @@ public final class ParallaxPagerView: UIView {
self.parallaxDelegate = parallaxDelegate
self.pagerDelegate = pagerDelegate
internalScrollView = UIScrollView(frame: containerViewController.view.bounds)
self.shouldReceiveHeaderGestures = shouldReceiveHeaderGestures
super.init(frame: containerViewController.view.bounds)

baseConfig()
Expand Down Expand Up @@ -562,7 +567,9 @@ public final class ParallaxPagerView: UIView {
hasShownController.add(vc)
scrollView.contentOffset = CGPoint(x: 0, y: -headerHeight - tabsHeight)
// set gestures priority.
if let rightGesture = rightSwipeGestureRecognizer, let leftGesture = leftSwipeGestureRecognizer {
if let rightGesture = rightSwipeGestureRecognizer,
let leftGesture = leftSwipeGestureRecognizer,
shouldReceiveHeaderGestures {
scrollView.gestureRecognizers?.forEach {
$0.require(toFail: rightGesture)
$0.require(toFail: leftGesture)
Expand Down Expand Up @@ -699,17 +706,28 @@ public final class ParallaxPagerView: UIView {
action: #selector(swipeDetected(gesture:))
)
rightSwipeGestureRecognizer!.direction = .right
rightSwipeGestureRecognizer?.delegate = self
addGestureRecognizer(rightSwipeGestureRecognizer!)

leftSwipeGestureRecognizer = UISwipeGestureRecognizer(
target: self,
action: #selector(swipeDetected(gesture:))
)
leftSwipeGestureRecognizer!.direction = .left
leftSwipeGestureRecognizer?.delegate = self
addGestureRecognizer(leftSwipeGestureRecognizer!)
}

deinit {
invalidateObservations()
}
}
extension ParallaxPagerView: UIGestureRecognizerDelegate {
public override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if !shouldReceiveHeaderGestures {
let location = gestureRecognizer.location(in: self)
return !headerView.frame.contains(location)
}
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
}

0 comments on commit c9b33e6

Please sign in to comment.