Skip to content

Commit

Permalink
[ABW-3635] FIx Text with markdown (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbzurovski committed Jul 22, 2024
1 parent e630a6f commit 41e5c33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extension Text {
/// Shows a markdown string, where any italics sections are shown in the provided color
public init(markdown: String, emphasizedColor: Color) {
let attributed = AttributedString(markdown: markdown, replaceEmphasizedWith: emphasizedColor)
/// Shows a markdown string, where any italics/bold sections are shown in the provided color and font.
public init(markdown: String, emphasizedColor: Color, emphasizedFont: SwiftUI.Font? = nil) {
let attributed = AttributedString(markdown: markdown, replaceEmphasizedWith: emphasizedColor, font: emphasizedFont)
self.init(attributed)
}
}
Expand All @@ -11,14 +11,14 @@ extension AttributedString {
self = update(AttributedString(string)) { $0.foregroundColor = foregroundColor }
}

public init(markdown: some StringProtocol, replaceEmphasizedWith emphasizedColor: Color) {
public init(markdown: some StringProtocol, replaceEmphasizedWith color: Color, font: SwiftUI.Font?) {
let string = String(markdown)
guard let attributed = try? AttributedString(markdown: string) else {
self.init(string)
return
}

let replacement = AttributeContainer.foregroundColor(emphasizedColor)
let replacement = AttributeContainer.emphasized(color: color, font: font)
self = attributed
.replacingAttributes(.emphasized, with: replacement)
.replacingAttributes(.stronglyEmphasized, with: replacement)
Expand All @@ -35,8 +35,9 @@ extension AttributeContainer {
return result
}

public static func foregroundColor(_ color: Color) -> AttributeContainer {
public static func emphasized(color: Color, font: SwiftUI.Font?) -> AttributeContainer {
var result = AttributeContainer()
result.font = font
result.foregroundColor = color
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension DappInteractionOriginVerification {
.textStyle(.sheetTitle)
.padding(.bottom, .large2)

Text(markdown: L10n.MobileConnect.linkSubtitle(store.dAppMetadata.name), emphasizedColor: .app.gray1)
Text(markdown: L10n.MobileConnect.linkSubtitle(store.dAppMetadata.name), emphasizedColor: .app.gray1, emphasizedFont: .app.body1Header)
.foregroundColor(.app.gray1)
.textStyle(.body1Link)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extension ScanQR.View {
ForEach(Array(disclosure.items.enumerated()), id: \.0) { index, message in
HStack(alignment: .top, spacing: .small3) {
Text("\(index + 1).")
Text(markdown: message, emphasizedColor: .app.gray1)
Text(markdown: message, emphasizedColor: .app.gray1, emphasizedFont: .app.body2HighImportance)
}
.multilineTextAlignment(.leading)
.font(.app.body2Regular)
Expand Down

0 comments on commit 41e5c33

Please sign in to comment.