another.im-ios/AnotherIM/View/SharedComponents/SharedListRow.swift
2024-10-31 12:43:16 +01:00

85 lines
2.6 KiB
Swift

import SwiftUI
enum SharedListRowIconType {
case charCircle(String)
case image(Image, Color)
case none
}
enum SharedListRowControlType {
case none
case switcher(isOn: Binding<Bool>)
}
struct SharedListRow: View {
let iconType: SharedListRowIconType
let text: String
let controlType: SharedListRowControlType
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 8) {
// Icon
switch iconType {
case .charCircle(let str):
let char = str.firstLetter
let color = str.firstLetterColor
ZStack {
Circle()
.frame(width: 44, height: 44)
.foregroundColor(color)
Text(char)
.foregroundColor(.white)
.font(.body1)
}
case .image(let image, let color):
ZStack {
Circle()
.frame(width: 44, height: 44)
.foregroundColor(.clearTappable)
.overlay {
image
.foregroundColor(color)
}
}
case .none:
Rectangle()
.fill(Color.clear)
.frame(width: 0.1, height: 44)
}
// Text
Text(text)
.foregroundColor(Color.Material.Text.main)
.font(.body2)
Spacer()
// If control is needed
switch controlType {
case .none:
Rectangle()
.fill(Color.clear)
.frame(width: 0.1, height: 44)
case .switcher(let isOn):
Toggle("", isOn: isOn)
.toggleStyle(SwitchToggleStyle(tint: .Material.Elements.active))
.frame(width: 49, height: 31)
}
}
.padding(.horizontal, 16)
.padding(.vertical, 4)
Rectangle()
.frame(maxWidth: .infinity)
.frame(height: 1)
.foregroundColor(.Material.Background.dark)
}
.listRowInsets(.zero)
.listRowSeparator(.hidden)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.Material.Background.light)
}
}