From 723249a1ba361042812cf785244de94f11f7c8fd Mon Sep 17 00:00:00 2001 From: Antonio Cabezuelo Vivo Date: Mon, 15 Apr 2024 09:55:40 +0200 Subject: [PATCH] Fix bullets in visionOS (#308) 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 + } + } +}