Conversation
There was a problem hiding this comment.
Pull request overview
This PR enables clickable links in FAQ answers by converting the answer text into an AttributedString and applying .link attributes for detected URLs and bare domains.
Changes:
- Map
FAQModel.Question.answerinto anAttributedStringwith link attributes (viaNSDataDetector+ regex). - Update
FAQViewItem.answerfromStringtoAttributedString.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
animeal/src/Flows/Main/Modules/More/Submodules/FAQ/View/QuestionViewMapper.swift
Show resolved
Hide resolved
| let collapsed: Bool | ||
| } | ||
|
|
||
| private extension QuestionViewMapper { |
There was a problem hiding this comment.
Link detection is a common task that shouldn't live in a FAQ-specific mapper. Consider extracting to a reusable service like LinkDetector.
| let id: String | ||
| let question: String | ||
| let answer: String | ||
| let answer: AttributedString |
There was a problem hiding this comment.
You should be careful using AttributedStrings - because they override your Text modifiers (font, color, background, etc)
| } | ||
|
|
||
| func applyBareDomainLinks(to attributed: inout AttributedString, in text: String) { | ||
| let pattern = #"\b(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}\b"# |
There was a problem hiding this comment.
This pattern creates false positives. file.tar.gz as an example. It is better to remove it altogether.
I see two major solutions here:
- We made a decision not to use the bare domains and BE always sends us URLs with https:// - for example, https://animealproject.ge
- Use URL detector, but transform String to markdown format.
- BE sends us strings in markdown format (requires alignment with Android)
| } | ||
|
|
||
| private extension QuestionViewMapper { | ||
| func attributedStringWithLinks(from text: String) -> AttributedString { |
There was a problem hiding this comment.
This is a pretty common problem, it is better to create a reusable LinkDetector class.
Pull Request overview
Enable clickable links in FAQ answers using AttributedString
Problem
FAQ answers were displayed as plain text.
example.com) were not detectedSummary
AttributedStringNSDataDetectorhttps://linksChanges
answertype toAttributedStringHow to test