Skip to content

Commit 723249a

Browse files
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 <[email protected]>
1 parent ae799d0 commit 723249a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Sources/MarkdownUI/Views/Blocks/ListItemView.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,30 @@ struct ListItemView: View {
4040
.readWidth(column: 0)
4141
.frame(width: self.markerWidth, alignment: .trailing)
4242
}
43+
#if os(visionOS)
44+
.labelStyle(BulletItemStyle())
45+
#endif
4346
}
4447
}
48+
49+
50+
extension VerticalAlignment {
51+
private enum CenterOfFirstLine: AlignmentID {
52+
static func defaultValue(in context: ViewDimensions) -> CGFloat {
53+
let heightAfterFirstLine = context[.lastTextBaseline] - context[.firstTextBaseline]
54+
let heightOfFirstLine = context.height - heightAfterFirstLine
55+
return heightOfFirstLine / 2
56+
}
57+
}
58+
static let centerOfFirstLine = Self(CenterOfFirstLine.self)
59+
}
60+
61+
62+
struct BulletItemStyle: LabelStyle {
63+
func makeBody(configuration: Configuration) -> some View {
64+
HStack(alignment: .centerOfFirstLine, spacing: 4) {
65+
configuration.icon
66+
configuration.title
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)