58 lines
1.6 KiB
Swift
58 lines
1.6 KiB
Swift
//
|
|
// ToggleRowView.swift
|
|
// AutoCat
|
|
//
|
|
// Created by Selim Mustafaev on 18.08.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
extension VerticalAlignment {
|
|
|
|
enum CustomVerticalAlignment: AlignmentID {
|
|
|
|
static func defaultValue(in context: ViewDimensions) -> CGFloat {
|
|
context[.top]
|
|
}
|
|
}
|
|
|
|
static let customTop = VerticalAlignment(CustomVerticalAlignment.self)
|
|
}
|
|
|
|
struct ToggleRowView: View {
|
|
|
|
let title: LocalizedStringKey
|
|
let description: LocalizedStringKey?
|
|
let toggle: Binding<Bool>
|
|
|
|
var body: some View {
|
|
HStack(alignment: .customTop) {
|
|
VStack(alignment: .leading) {
|
|
Text(title)
|
|
.alignmentGuide(.customTop, computeValue: { $0[.firstTextBaseline] })
|
|
if let description {
|
|
Text(description)
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
Spacer()
|
|
Toggle(isOn: toggle) {
|
|
Text(" ")
|
|
.alignmentGuide(.customTop, computeValue: { $0[.firstTextBaseline] })
|
|
}
|
|
.fixedSize()
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
List {
|
|
ToggleRowView(title: "Title",
|
|
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas cursus posuere varius. Maecenas diam neque, lacinia molestie tristique eget, faucibus egestas nibh.",
|
|
toggle: .constant(true))
|
|
ToggleRowView(title: "Title", description: nil, toggle: .constant(true))
|
|
}
|
|
}
|