Skip to content

Commit

Permalink
Fix: only install gestureRecog if gesture enabled
Browse files Browse the repository at this point in the history
Even if shouldDismissOnTap was set to false, the gesture was installed and prevented touch events being called correctly in a custom view. These changes prevent unnecessary gesture installation and also fix touch events in custom views.
  • Loading branch information
whitepixelstudios committed Dec 19, 2017
1 parent 217c0b0 commit 0153369
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions Source/PopTip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,18 @@ open class PopTip: UIView {

setNeedsDisplay()

if tapGestureRecognizer == nil {
tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(PopTip.handleTap(_:)))
tapGestureRecognizer?.cancelsTouchesInView = true
self.addGestureRecognizer(tapGestureRecognizer ?? UITapGestureRecognizer())
}
if tapRemoveGestureRecognizer == nil {
tapRemoveGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(PopTip.handleTapOutside(_:)))
}
if swipeGestureRecognizer == nil {
if shouldDismissOnTap || shouldDismissOnTapOutside { /////If shouldDismissOnTapOutside enabled, we need both tap gestures to prevent 'tapRemoveGestureRecognizer' being called when tapping on the bubble
if tapGestureRecognizer == nil {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PopTip.handleTap(_:)))
tapGesture.cancelsTouchesInView = false
self.addGestureRecognizer(tapGesture)
tapGestureRecognizer = tapGesture
}
if shouldDismissOnTapOutside && tapRemoveGestureRecognizer == nil {
tapRemoveGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(PopTip.handleTapOutside(_:)))
}
}
if shouldDismissOnSwipeOutside && swipeGestureRecognizer == nil {
swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(PopTip.handleSwipeOutside(_:)))
swipeGestureRecognizer?.direction = swipeRemoveGestureDirection
}
Expand Down Expand Up @@ -656,8 +659,13 @@ open class PopTip: UIView {

setNeedsLayout()
performEntranceAnimation {
self.containerView?.addGestureRecognizer(self.tapRemoveGestureRecognizer ?? UITapGestureRecognizer())
self.containerView?.addGestureRecognizer(self.swipeGestureRecognizer ?? UITapGestureRecognizer())
if let tapRemoveGesture = self.tapRemoveGestureRecognizer {
self.containerView?.addGestureRecognizer(tapRemoveGesture)
}
if let swipeGesture = self.swipeGestureRecognizer {
self.containerView?.addGestureRecognizer(swipeGesture)
}

self.appearHandler?(self)
if self.startActionAnimationOnShow {
self.performActionAnimation()
Expand Down

0 comments on commit 0153369

Please sign in to comment.