Skip to content

Commit

Permalink
修复监听点击事件问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiang1994 committed Jul 7, 2020
1 parent d82df3b commit 7d1b4cd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Sources/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ extension AttributedString {
self.highlights = highlights
self.callback = callback
}

init(_ trigger: Trigger = .click, highlights: [Highlight] = .defalut) {
self.trigger = trigger
self.highlights = highlights
self.callback = { _ in }
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion Sources/Extension/AppKit/NSTextFieldExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ extension AttributedStringWrapper where Base: NSTextField {

default:
guard let value = observation[type] else { return }
base.actions[range] = .init(.click, highlights: value.0) { _ in value.1(result) }
var action = Action(.click, highlights: value.0)
action.handle = {
value.1(result)
}
base.actions[range] = action
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/Extension/UIKit/UILabelExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ extension AttributedStringWrapper where Base: UILabel {

default:
guard let value = observation[type] else { return }
base.actions[range] = .init(.click, highlights: value.0) { _ in value.1(result) }
var action = Action(.click, highlights: value.0)
action.handle = {
value.1(result)
}
base.actions[range] = action
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Sources/Extension/UIKit/UITextViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ extension AttributedStringWrapper where Base: UITextView {

default:
guard let value = observation[type] else { return }
base.actions[range] = .init(.click, highlights: value.0) { _ in value.1(result) }
var action = Action(.click, highlights: value.0)
action.handle = {
value.1(result)
}
base.actions[range] = action
}
}
}
Expand Down

0 comments on commit 7d1b4cd

Please sign in to comment.