From da8d82eba104afec39897f588095d733f7f63fca Mon Sep 17 00:00:00 2001 From: Antonio Cabezuelo Vivo Date: Sat, 13 Apr 2024 19:26:37 +0200 Subject: [PATCH] Fix bullets in visionOS Label does not align the icon with the center of the first line like on iOS Signed-off-by: Antonio Cabezuelo Vivo --- .../Views/Blocks/ListItemView.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Sources/MarkdownUI/Views/Blocks/ListItemView.swift b/Sources/MarkdownUI/Views/Blocks/ListItemView.swift index 11643ac1..69e1d81e 100644 --- a/Sources/MarkdownUI/Views/Blocks/ListItemView.swift +++ b/Sources/MarkdownUI/Views/Blocks/ListItemView.swift @@ -40,5 +40,30 @@ struct ListItemView: View { .readWidth(column: 0) .frame(width: self.markerWidth, alignment: .trailing) } + #if os(visionOS) + .labelStyle(BulletItemStyle()) + #endif } } + + +extension VerticalAlignment { + private enum CenterOfFirstLine: AlignmentID { + static func defaultValue(in context: ViewDimensions) -> CGFloat { + let heightAfterFirstLine = context[.lastTextBaseline] - context[.firstTextBaseline] + let heightOfFirstLine = context.height - heightAfterFirstLine + return heightOfFirstLine / 2 + } + } + static let centerOfFirstLine = Self(CenterOfFirstLine.self) +} + + +struct BulletItemStyle: LabelStyle { + func makeBody(configuration: Configuration) -> some View { + HStack(alignment: .centerOfFirstLine, spacing: 4) { + configuration.icon + configuration.title + } + } +}