Skip to content

Commit

Permalink
fix: Bridge color on AS -> NSAS.
Browse files Browse the repository at this point in the history
  • Loading branch information
laosb committed Mar 11, 2024
1 parent 07d0f6c commit c3a1a95
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Sources/EasyRichText/ERTAttributedStringBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,32 @@ public struct ERTAttributedStringBridge {

for run in attributedString.runs {
let mutableSubstring = NSMutableAttributedString(AttributedString(attributedString[run.range]))
let range = NSRange(location: 0, length: mutableSubstring.length)

if bridgeInternalAttributes {
if run.synthesizedItalic ?? false {
mutableSubstring.addAttribute(.ertSynthesizedItalic, value: true, range: NSRange(location: 0, length: mutableSubstring.length))
mutableSubstring.addAttribute(.ertSynthesizedItalic, value: true, range: range)
}
}

if bridgeColor {
#if canImport(AppKit)
if let color = run.attributes.swiftUI.foregroundColor {
mutableSubstring.addAttribute(.foregroundColor, value: NSColor(color), range: range)
}
if let color = run.attributes.swiftUI.backgroundColor {
mutableSubstring.addAttribute(.backgroundColor, value: NSColor(color), range: range)
}
#elseif canImport(UIKit)
if let color = run.attributes.swiftUI.foregroundColor {
mutableSubstring.addAttribute(.foregroundColor, value: UIColor(color), range: range)
}
if let color = run.attributes.swiftUI.backgroundColor {
mutableSubstring.addAttribute(.backgroundColor, value: UIColor(color), range: range)
}
#endif
}

mutableString.append(mutableSubstring)
}

Expand Down

0 comments on commit c3a1a95

Please sign in to comment.