Improve SegmentedPicker UI

This commit is contained in:
Alfonso Grillo
2023-02-06 12:36:31 +01:00
parent 10d2232d8a
commit 4d245575d5
@@ -39,7 +39,7 @@ struct SegmentedPicker<Segment: Hashable & CustomStringConvertible>: View {
} label: {
Text(segment.description)
.font(isSelectedSegment ? theme.fonts.headline : theme.fonts.body)
.underline(isSelectedSegment)
.underlineBar(isSelectedSegment)
}
.accentColor(isSelectedSegment ? theme.colors.accent : theme.colors.primaryContent)
.accessibilityLabel(segment.description)
@@ -49,6 +49,23 @@ struct SegmentedPicker<Segment: Hashable & CustomStringConvertible>: View {
}
}
private extension Text {
@ViewBuilder
func underlineBar(_ isActive: Bool) -> some View {
if #available(iOS 15.0, *) {
overlay(alignment: .bottom) {
if isActive {
Rectangle()
.frame(height: 1)
.offset(y: 2)
}
}
} else {
underline(isActive)
}
}
}
struct SegmentedPicker_Previews: PreviewProvider {
static var previews: some View {
SegmentedPicker(