Skip to content

Commit

Permalink
Merge pull request #823 from adevinta/button/action
Browse files Browse the repository at this point in the history
[Button-821] Default gesture
  • Loading branch information
robergro authored Feb 21, 2024
2 parents 0ea0a21 + 94bd550 commit 5d36d72
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ public class ButtonMainUIView: UIControl {
// Setup constraints
self.setupConstraints()

// Setup gesture
self.setupGestureRecognizer()

// Setup publisher subcriptions
self.setupSubscriptions()

Expand Down Expand Up @@ -224,6 +227,18 @@ public class ButtonMainUIView: UIControl {
self.imageView.widthAnchor.constraint(equalTo: self.imageView.heightAnchor).isActive = true
}

// MARK: - Gesture Recognizer

/// Add a default tap gesture recognizer without any action to detect the action/publisher/target action
/// even if the parent view has a gesture recognizer
/// Why ? UIControl action/publisher/target doesn't work if the parent contains a gesture recognizer.
/// *Note*: Native UIButton add the same default recognizer to manage this use case.
private func setupGestureRecognizer() {
let gestureRecognizer = UITapGestureRecognizer()
gestureRecognizer.cancelsTouchesInView = false
self.addGestureRecognizer(gestureRecognizer)
}

// MARK: - Setter & Getter

/// The image of the button for a state.
Expand Down

0 comments on commit 5d36d72

Please sign in to comment.