Skip to content

Commit

Permalink
Fix bullets in visionOS (#308)
Browse files Browse the repository at this point in the history
Label does not align the icon with the center of the first line like on iOS

Signed-off-by: Antonio Cabezuelo Vivo <[email protected]>
  • Loading branch information
tapsandswipes authored Apr 15, 2024
1 parent ae799d0 commit 723249a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Sources/MarkdownUI/Views/Blocks/ListItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 723249a

Please sign in to comment.