2022-10-21 13:12:44 +02:00
|
|
|
//
|
|
|
|
// PollOptionRow.swift
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Created by MainasuK on 2022-5-31.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-10-26 12:35:10 +02:00
|
|
|
import MastodonAsset
|
2022-10-21 13:12:44 +02:00
|
|
|
import MastodonCore
|
2023-02-07 22:55:58 +01:00
|
|
|
import MastodonLocalization
|
2022-10-21 13:12:44 +02:00
|
|
|
|
|
|
|
public struct PollOptionRow: View {
|
|
|
|
|
|
|
|
@ObservedObject var viewModel: PollComposeItem.Option
|
|
|
|
|
2023-02-07 22:55:58 +01:00
|
|
|
let index: Int
|
|
|
|
let moveUp: (() -> Void)?
|
|
|
|
let moveDown: (() -> Void)?
|
|
|
|
let removeOption: (() -> Void)?
|
2022-10-21 13:12:44 +02:00
|
|
|
let deleteBackwardResponseTextFieldRelayDelegate: DeleteBackwardResponseTextFieldRelayDelegate?
|
|
|
|
let configurationHandler: (DeleteBackwardResponseTextField) -> Void
|
|
|
|
|
|
|
|
public var body: some View {
|
2022-10-26 12:35:10 +02:00
|
|
|
HStack(alignment: .center, spacing: 16) {
|
|
|
|
HStack(alignment: .center, spacing: .zero) {
|
|
|
|
Image(systemName: "circle")
|
|
|
|
.frame(width: 20, height: 20)
|
|
|
|
.padding(.leading, 16)
|
|
|
|
.padding(.trailing, 16 - 10) // 8pt for TextField leading
|
|
|
|
.font(.system(size: 17))
|
2023-02-07 22:57:08 +01:00
|
|
|
.accessibilityHidden(true)
|
2023-02-07 22:55:58 +01:00
|
|
|
let field = PollOptionTextField(
|
2022-10-26 12:35:10 +02:00
|
|
|
text: $viewModel.text,
|
2023-02-07 22:55:58 +01:00
|
|
|
index: index,
|
2022-10-26 12:35:10 +02:00
|
|
|
delegate: deleteBackwardResponseTextFieldRelayDelegate
|
|
|
|
) { textField in
|
|
|
|
viewModel.textField = textField
|
|
|
|
configurationHandler(textField)
|
|
|
|
}
|
|
|
|
.onReceive(viewModel.$shouldBecomeFirstResponder) { shouldBecomeFirstResponder in
|
|
|
|
guard shouldBecomeFirstResponder else { return }
|
|
|
|
viewModel.shouldBecomeFirstResponder = false
|
|
|
|
viewModel.textField?.becomeFirstResponder()
|
|
|
|
}
|
2023-02-07 22:55:58 +01:00
|
|
|
|
|
|
|
if #available(iOS 16.0, *) {
|
|
|
|
field.accessibilityActions {
|
|
|
|
if let moveUp {
|
|
|
|
Button(L10n.Scene.Compose.Poll.moveUp, action: moveUp)
|
|
|
|
}
|
|
|
|
if let moveDown {
|
|
|
|
Button(L10n.Scene.Compose.Poll.moveDown, action: moveDown)
|
|
|
|
}
|
|
|
|
if let removeOption {
|
|
|
|
Button(L10n.Scene.Compose.Poll.removeOption, action: removeOption)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2023-02-08 15:22:23 +01:00
|
|
|
switch (moveUp, moveDown, removeOption) {
|
|
|
|
case let (.some(up), .some(down), .some(remove)):
|
|
|
|
field
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up)
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down)
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove)
|
|
|
|
case let (.some(up), .some(down), .none):
|
|
|
|
field
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up)
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down)
|
|
|
|
case let (.some(up), .none, .some(remove)):
|
|
|
|
field
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up)
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove)
|
|
|
|
case let (.some(up), .none, .none):
|
|
|
|
field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, up)
|
|
|
|
case let (.none, .some(down), .some(remove)):
|
|
|
|
field
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down)
|
|
|
|
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove)
|
|
|
|
case let (.none, .some(down), .none):
|
|
|
|
field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, down)
|
|
|
|
case let (.none, .none, .some(remove)):
|
|
|
|
field.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, remove)
|
|
|
|
case (.none, .none, .none):
|
|
|
|
field
|
2023-02-07 22:55:58 +01:00
|
|
|
}
|
|
|
|
}
|
2022-10-26 12:35:10 +02:00
|
|
|
}
|
|
|
|
.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))
|
2023-02-07 22:57:08 +01:00
|
|
|
.accessibilityHidden(true)
|
2022-10-21 13:12:44 +02:00
|
|
|
}
|
2022-10-26 12:35:10 +02:00
|
|
|
.background(Color.clear)
|
2022-10-21 13:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|