mastodon-ios/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Poll/PollAddOptionRow.swift

60 lines
1.7 KiB
Swift

//
// PollAddOptionRow.swift
//
//
// Created by MainasuK on 2022/10/26.
//
import SwiftUI
import MastodonAsset
import MastodonCore
public struct PollAddOptionRow: View {
@StateObject var viewModel = ViewModel()
public var body: some View {
HStack(alignment: .center, spacing: 16) {
HStack(alignment: .center, spacing: .zero) {
Image(systemName: "plus.circle")
.frame(width: 20, height: 20)
.padding(.leading, 16)
.padding(.trailing, 16 - 10) // 8pt for TextField leading
.font(.system(size: 17))
PollOptionTextField(
text: $viewModel.text,
index: 999,
delegate: nil
) { textField in
// do nothing
}
.hidden()
}
.background(Color(viewModel.backgroundColor))
.cornerRadius(10)
.shadow(color: .black.opacity(0.3), radius: 2, x: 0, y: 1)
Image(uiImage: Asset.Scene.Compose.reorderDot.image.withRenderingMode(.alwaysTemplate))
.foregroundColor(Color(UIColor.label))
.hidden()
}
.background(Color.clear)
}
}
extension PollAddOptionRow {
public class ViewModel: ObservableObject {
// input
@Published public var text: String = ""
// output
@Published public var backgroundColor = ThemeService.shared.currentTheme.value.composePollRowBackgroundColor
public init() {
ThemeService.shared.currentTheme
.map { $0.composePollRowBackgroundColor }
.assign(to: &$backgroundColor)
}
}
}