Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: only install gestureRecog if gesture enabled #143

Merged
merged 1 commit into from
Dec 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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