-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Styled markdown with AttributedString #757
base: develop
Are you sure you want to change the base?
Conversation
branch = "feature/attributed-string-styled-markdown"; | ||
kind = branch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change it before merge
Generated by 🚫 Danger |
Group { | ||
if let displayedText { | ||
Text(displayedText) | ||
} else if markdownEnabled { | ||
Text(text) | ||
} else { | ||
Text(message.adjustedText) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file's diff is pretty unreadable.
Before
- Manual link detection for mentions and plain links was separate from markdown handling
- Markdown handling came purely from Text's markdown support
After
- First parse and style markdown (if allowed)
- Add links for mentions (if allowed)
- Detect plain links in text (if allowed)
- Apply styling attributes for links
Some things could be improved further: since now we use AttributedString always, then it could be created in init (onAppear feels unnecessary, but removing it does break tint color). Needs some investigation (probably better to be a separate PR).
var linkAttributeContainer = AttributeContainer() | ||
if let uiColor = linkAttributes[.foregroundColor] as? UIColor { | ||
linkAttributeContainer = linkAttributeContainer.foregroundColor(Color(uiColor: uiColor)) | ||
linkAttributes.removeValue(forKey: .foregroundColor) | ||
} | ||
linkAttributeContainer.merge(AttributeContainer(linkAttributes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly messy because I need to make sure SwiftUIAttributes.ForegroundColor is used if UIColor is passed in from messageLinkDisplayResolver
. Only way I found it make it working is init attributes without UIColor and then adding Color to the container using the .foregroundColor()
functions which takes in a Color instance.
SDK Size
|
..._Snapshots__/MessageView_Tests/test_markdown_mixedLists_nested.rightToLeftLayout-default.png
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! ✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
|
🔗 Issue Link
Resolves: IOS-41
🎯 Goal
Use AttributedString's markdown parsing support with additional styling.
🛠 Implementation
MarkdownParser
for styling the finalAttributedString
LinkDetectionTextView
and then apply mentions and plain link detection🧪 Testing
@username
,@userid
) + plain links🎨 Changes
☑️ Checklist