listless

A simple list app for Apple platforms
Log | Files | Refs | README | LICENSE

ItemCardModifier.swift (1025B)


      1 import SwiftUI
      2 
      3 struct ItemCardModifier: ViewModifier {
      4     var accentColor: Color
      5     var isSelected: Bool
      6 
      7     static let shape = UnevenRoundedRectangle(
      8         topLeadingRadius: 0, bottomLeadingRadius: 0,
      9         bottomTrailingRadius: ItemRowMetrics.trailingCornerRadius,
     10         topTrailingRadius: ItemRowMetrics.trailingCornerRadius
     11     )
     12 
     13     func body(content: Content) -> some View {
     14         content
     15             .clipShape(Self.shape)
     16             .overlay(alignment: .leading) {
     17                 Rectangle()
     18                     .fill(accentColor)
     19                     .frame(width: ItemRowMetrics.accentBarWidth)
     20             }
     21             .overlay(
     22                 isSelected
     23                     ? Self.shape
     24                         .strokeBorder(accentColor.opacity(0.40), lineWidth: 2)
     25                     : nil
     26             )
     27     }
     28 }
     29 
     30 extension View {
     31     func itemCard(accentColor: Color, isSelected: Bool) -> some View {
     32         modifier(ItemCardModifier(accentColor: accentColor, isSelected: isSelected))
     33     }
     34 }