Add move up / move down / remove option actions to poll options
This commit is contained in:
parent
06183f5649
commit
7d8c40218c
|
@ -470,7 +470,10 @@
|
|||
"seven_days": "7 Days",
|
||||
"option_number": "Option %ld",
|
||||
"the_poll_is_invalid": "The poll is invalid",
|
||||
"the_poll_has_empty_option": "The poll has empty option"
|
||||
"the_poll_has_empty_option": "The poll has empty option",
|
||||
"remove_option": "Remove Option",
|
||||
"move_up": "Move Up",
|
||||
"move_down": "Move Down"
|
||||
},
|
||||
"content_warning": {
|
||||
"placeholder": "Write an accurate warning here..."
|
||||
|
|
|
@ -597,6 +597,10 @@ public enum L10n {
|
|||
public static func durationTime(_ p1: Any) -> String {
|
||||
return L10n.tr("Localizable", "Scene.Compose.Poll.DurationTime", String(describing: p1), fallback: "Duration: %@")
|
||||
}
|
||||
/// Move Down
|
||||
public static let moveDown = L10n.tr("Localizable", "Scene.Compose.Poll.MoveDown", fallback: "Move Down")
|
||||
/// Move Up
|
||||
public static let moveUp = L10n.tr("Localizable", "Scene.Compose.Poll.MoveUp", fallback: "Move Up")
|
||||
/// 1 Day
|
||||
public static let oneDay = L10n.tr("Localizable", "Scene.Compose.Poll.OneDay", fallback: "1 Day")
|
||||
/// 1 Hour
|
||||
|
@ -605,6 +609,8 @@ public enum L10n {
|
|||
public static func optionNumber(_ p1: Int) -> String {
|
||||
return L10n.tr("Localizable", "Scene.Compose.Poll.OptionNumber", p1, fallback: "Option %ld")
|
||||
}
|
||||
/// Remove Option
|
||||
public static let removeOption = L10n.tr("Localizable", "Scene.Compose.Poll.RemoveOption", fallback: "Remove Option")
|
||||
/// 7 Days
|
||||
public static let sevenDays = L10n.tr("Localizable", "Scene.Compose.Poll.SevenDays", fallback: "7 Days")
|
||||
/// 6 Hours
|
||||
|
|
|
@ -212,9 +212,12 @@ uploaded to Mastodon.";
|
|||
"Scene.Compose.MediaSelection.Camera" = "Take Photo";
|
||||
"Scene.Compose.MediaSelection.PhotoLibrary" = "Photo Library";
|
||||
"Scene.Compose.Poll.DurationTime" = "Duration: %@";
|
||||
"Scene.Compose.Poll.MoveDown" = "Move Down";
|
||||
"Scene.Compose.Poll.MoveUp" = "Move Up";
|
||||
"Scene.Compose.Poll.OneDay" = "1 Day";
|
||||
"Scene.Compose.Poll.OneHour" = "1 Hour";
|
||||
"Scene.Compose.Poll.OptionNumber" = "Option %ld";
|
||||
"Scene.Compose.Poll.RemoveOption" = "Remove Option";
|
||||
"Scene.Compose.Poll.SevenDays" = "7 Days";
|
||||
"Scene.Compose.Poll.SixHours" = "6 Hours";
|
||||
"Scene.Compose.Poll.ThePollHasEmptyOption" = "The poll has empty option";
|
||||
|
|
|
@ -8,12 +8,16 @@
|
|||
import SwiftUI
|
||||
import MastodonAsset
|
||||
import MastodonCore
|
||||
import MastodonLocalization
|
||||
|
||||
public struct PollOptionRow: View {
|
||||
|
||||
@ObservedObject var viewModel: PollComposeItem.Option
|
||||
|
||||
let index: Int?
|
||||
let index: Int
|
||||
let moveUp: (() -> Void)?
|
||||
let moveDown: (() -> Void)?
|
||||
let removeOption: (() -> Void)?
|
||||
let deleteBackwardResponseTextFieldRelayDelegate: DeleteBackwardResponseTextFieldRelayDelegate?
|
||||
let configurationHandler: (DeleteBackwardResponseTextField) -> Void
|
||||
|
||||
|
@ -25,9 +29,9 @@ public struct PollOptionRow: View {
|
|||
.padding(.leading, 16)
|
||||
.padding(.trailing, 16 - 10) // 8pt for TextField leading
|
||||
.font(.system(size: 17))
|
||||
PollOptionTextField(
|
||||
let field = PollOptionTextField(
|
||||
text: $viewModel.text,
|
||||
index: index ?? -1,
|
||||
index: index,
|
||||
delegate: deleteBackwardResponseTextFieldRelayDelegate
|
||||
) { textField in
|
||||
viewModel.textField = textField
|
||||
|
@ -38,6 +42,60 @@ public struct PollOptionRow: View {
|
|||
viewModel.shouldBecomeFirstResponder = false
|
||||
viewModel.textField?.becomeFirstResponder()
|
||||
}
|
||||
|
||||
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 {
|
||||
// beautiful!
|
||||
if let moveUp {
|
||||
if let moveDown {
|
||||
if let removeOption {
|
||||
field
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp)
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown)
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption)
|
||||
} else {
|
||||
field
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp)
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown)
|
||||
}
|
||||
} else {
|
||||
if let removeOption {
|
||||
field
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp)
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption)
|
||||
} else {
|
||||
field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveUp, moveUp)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let moveDown {
|
||||
if let removeOption {
|
||||
field
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown)
|
||||
.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption)
|
||||
} else {
|
||||
field.accessibilityAction(named: L10n.Scene.Compose.Poll.moveDown, moveDown)
|
||||
}
|
||||
} else {
|
||||
if let removeOption {
|
||||
field.accessibilityAction(named: L10n.Scene.Compose.Poll.removeOption, removeOption)
|
||||
} else {
|
||||
field
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.background(Color(viewModel.backgroundColor))
|
||||
.cornerRadius(10)
|
||||
|
|
|
@ -180,13 +180,23 @@ extension ComposeContentView {
|
|||
ReorderableForEach(
|
||||
items: $viewModel.pollOptions
|
||||
) { $pollOption in
|
||||
let _index = viewModel.pollOptions.firstIndex(of: pollOption)
|
||||
PollOptionRow(
|
||||
viewModel: pollOption,
|
||||
index: _index,
|
||||
deleteBackwardResponseTextFieldRelayDelegate: viewModel
|
||||
) { textField in
|
||||
viewModel.customEmojiPickerInputViewModel.configure(textInput: textField)
|
||||
if let _index = viewModel.pollOptions.firstIndex(of: pollOption) {
|
||||
PollOptionRow(
|
||||
viewModel: pollOption,
|
||||
index: _index,
|
||||
moveUp: _index == 0 ? nil : {
|
||||
viewModel.pollOptions.swapAt(_index, _index - 1)
|
||||
},
|
||||
moveDown: _index == viewModel.pollOptions.count - 1 ? nil : {
|
||||
viewModel.pollOptions.swapAt(_index, _index + 1)
|
||||
},
|
||||
removeOption: viewModel.pollOptions.count <= 2 ? nil : {
|
||||
viewModel.pollOptions.remove(at: _index)
|
||||
},
|
||||
deleteBackwardResponseTextFieldRelayDelegate: viewModel
|
||||
) { textField in
|
||||
viewModel.customEmojiPickerInputViewModel.configure(textInput: textField)
|
||||
}
|
||||
}
|
||||
}
|
||||
if viewModel.maxPollOptionLimit != viewModel.pollOptions.count {
|
||||
|
|
Loading…
Reference in New Issue