You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
//
|
|
// ListRowViewModifier.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 27/03/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ListRowViewModifier: ViewModifier {
|
|
let isActive: Bool
|
|
let color: Color
|
|
var hideColorVariation: Bool = false
|
|
var backgroundColor: Color? = nil
|
|
let alignment: Alignment
|
|
|
|
func colorVariation() -> Color {
|
|
hideColorVariation ? (backgroundColor ?? Color(uiColor: .secondarySystemGroupedBackground)) : color.variation()
|
|
}
|
|
|
|
func body(content: Content) -> some View {
|
|
if isActive {
|
|
content
|
|
.listRowBackground(
|
|
colorVariation()
|
|
.overlay(alignment: alignment, content: {
|
|
color.frame(width: 8)
|
|
})
|
|
)
|
|
} else {
|
|
content
|
|
}
|
|
}
|
|
}
|
|
|
|
extension View {
|
|
func listRowView(isActive: Bool = false, color: Color, hideColorVariation: Bool = false, backgroundColor: Color? = nil, alignment: Alignment = .leading) -> some View {
|
|
modifier(ListRowViewModifier(isActive: isActive, color: color, hideColorVariation: hideColorVariation, backgroundColor: backgroundColor, alignment: alignment))
|
|
}
|
|
}
|
|
|