another.im-ios/AnotherIM/View/SharedComponents/SharedListRow.swift

85 lines
2.6 KiB
Swift
Raw Permalink Normal View History

2024-06-19 15:15:27 +00:00
import SwiftUI
2024-08-07 19:07:39 +00:00
enum SharedListRowIconType {
case charCircle(String)
case image(Image, Color)
2024-09-19 16:50:48 +00:00
case none
}
enum SharedListRowControlType {
case none
case switcher(isOn: Binding<Bool>)
2024-06-19 15:15:27 +00:00
}
2024-08-07 19:07:39 +00:00
struct SharedListRow: View {
let iconType: SharedListRowIconType
let text: String
2024-09-19 16:50:48 +00:00
let controlType: SharedListRowControlType
2024-08-07 19:07:39 +00:00
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)
}
}
2024-09-19 16:50:48 +00:00
case .none:
Rectangle()
.fill(Color.clear)
.frame(width: 0.1, height: 44)
2024-08-07 19:07:39 +00:00
}
// Text
Text(text)
.foregroundColor(Color.Material.Text.main)
.font(.body2)
Spacer()
2024-09-19 16:50:48 +00:00
// 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)
}
2024-08-07 19:07:39 +00:00
}
.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)
2024-06-19 15:15:27 +00:00
}
}