mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-05-22 23:42:50 +08:00
Don't collide gestures on AttributedStringView (#1127)
* dont collide string gestures * remove redundant type
This commit is contained in:
@@ -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
|
||||
])
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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? {
|
||||
|
||||
Reference in New Issue
Block a user