Skip to content
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

[ABW-3635] FIx Text with markdown #1231

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading