Don't collide gestures on AttributedStringView (#1127)

* dont collide string gestures

* remove redundant type
This commit is contained in:
Ryan Nystrom
2017-12-02 16:15:15 -05:00
committed by GitHub
parent 7d483c0247
commit a6741c96c2
3 changed files with 35 additions and 6 deletions

View File

@@ -18,4 +18,16 @@ enum MarkdownAttribute {
static let details = NSAttributedStringKey(rawValue: "com.freetime.Markdown.details")
static let label = NSAttributedStringKey(rawValue: "com.freetime.Markdown.label")
static let commit = NSAttributedStringKey(rawValue: "com.freetime.Markdown.commit")
static let all = Set<NSAttributedStringKey>([
url,
email,
username,
usernameDisabled,
linkShorteningDisabled,
issue,
details,
label,
commit
])
}

View File

@@ -56,8 +56,7 @@ final class IssueReferencedModel: ListDiffable {
attributes: [
.font: Styles.Fonts.secondaryBold,
.foregroundColor: Styles.Colors.Gray.medium.color,
// TODO: enable once #1125 is fixed
// MarkdownAttribute.username: actor
MarkdownAttribute.username: actor
]
))
attributedText.append(NSAttributedString(

View File

@@ -26,6 +26,8 @@ final class AttributedStringView: UIView {
weak var issueDelegate: AttributedStringViewIssueDelegate?
private var text: NSAttributedStringSizing?
private var tapGesture: UITapGestureRecognizer?
private var longPressGesture: UILongPressGestureRecognizer?
override init(frame: CGRect) {
super.init(frame: frame)
@@ -36,12 +38,13 @@ final class AttributedStringView: UIView {
layer.contentsGravity = kCAGravityTopLeft
let tap = UITapGestureRecognizer(target: self, action: #selector(AttributedStringView.onTap(recognizer:)))
tap.cancelsTouchesInView = false
let tap = UITapGestureRecognizer(target: self, action: #selector(onTap(recognizer:)))
addGestureRecognizer(tap)
let long = UILongPressGestureRecognizer(target: self, action: #selector(AttributedStringView.onLong(recognizer:)))
long.cancelsTouchesInView = false
self.tapGesture = tap
let long = UILongPressGestureRecognizer(target: self, action: #selector(onLong(recognizer:)))
addGestureRecognizer(long)
self.longPressGesture = long
}
required init?(coder aDecoder: NSCoder) {
@@ -52,6 +55,21 @@ final class AttributedStringView: UIView {
return true
}
// MARK: UIGestureRecognizerDelegate
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
guard (gestureRecognizer === tapGesture || gestureRecognizer === longPressGesture),
let attributes = text?.attributes(point: gestureRecognizer.location(in: self)) else {
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
for attribute in attributes {
if MarkdownAttribute.all.contains(attribute.key) {
return true
}
}
return false
}
// MARK: Accessibility
override var accessibilityLabel: String? {