Nantes
Nantes copied to clipboard
Pass a `linkTappedBlock` handler when adding multiple links to a single label
This is necessary because the linkTappedBlock
can't be set after a link got created using addLink(to:URL)
method since the Link DTO is a struct.
It may sound pointless because we already have to pass an URL which then calls a delegate method when being tapped but we have a case where we add multiple links to a single label and each link press is handled differently.
@PatrickDotStar I'm not 100% sure I understand what you're trying to do with your code. Do you have an example you can post in here that will help me understand it?
Sure. we have something like this which will get called in a for loop
// NantesLabel attributedString is something like = "one, two, three, four"
// We then want each word separated by ',' to have its own link tapped handler
// Since we only want one NantesLabel instead of adding multiple ones separated by ',' we have to do it like this
public class func addLink(to url: URL, range: NSRange, label: NantesLabel, linkTappedHandler: (() -> Void)? = nil) {
if let linkTappedHandler = linkTappedHandler {
label.addLink(to: url, withRange: range, linkTappedBlock: { _, _ in
linkTappedHandler()
})
}
else {
label.addLink(to: url, withRange: range)
}
}
Sorry it's taken me so long to get back to you!
LGTM @namolnad do you have any time to check it?
thanks @PatrickDotStar sounds like you're planning to add unit tests. will merge when they're good to go.