mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 20:09:04 +00:00
A11y: added a hint to inform the user that max selections have been reached (#4308)
* a11y added a hint to inform the user that max selections have been reached * added string
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
"a11y_pin_field" = "PIN field";
|
"a11y_pin_field" = "PIN field";
|
||||||
"a11y_play" = "Play";
|
"a11y_play" = "Play";
|
||||||
"a11y_poll_end" = "Ended poll";
|
"a11y_poll_end" = "Ended poll";
|
||||||
|
"a11y_polls_will_remove_selection" = "Will remove previous selection";
|
||||||
"a11y_polls_winning_answer" = "This is the winning answer";
|
"a11y_polls_winning_answer" = "This is the winning answer";
|
||||||
"a11y_react_with" = "React with %1$@";
|
"a11y_react_with" = "React with %1$@";
|
||||||
"a11y_react_with_other_emojis" = "React with other emojis";
|
"a11y_react_with_other_emojis" = "React with other emojis";
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ internal enum L10n {
|
|||||||
internal static func a11yPollsPercentOfTotal(_ p1: Int) -> String {
|
internal static func a11yPollsPercentOfTotal(_ p1: Int) -> String {
|
||||||
return L10n.tr("Localizable", "a11y_polls_percent_of_total", p1)
|
return L10n.tr("Localizable", "a11y_polls_percent_of_total", p1)
|
||||||
}
|
}
|
||||||
|
/// Will remove previous selection
|
||||||
|
internal static var a11yPollsWillRemoveSelection: String { return L10n.tr("Localizable", "a11y_polls_will_remove_selection") }
|
||||||
/// This is the winning answer
|
/// This is the winning answer
|
||||||
internal static var a11yPollsWinningAnswer: String { return L10n.tr("Localizable", "a11y_polls_winning_answer") }
|
internal static var a11yPollsWinningAnswer: String { return L10n.tr("Localizable", "a11y_polls_winning_answer") }
|
||||||
/// React with %1$@
|
/// React with %1$@
|
||||||
|
|||||||
@@ -92,20 +92,34 @@ struct PollView: View {
|
|||||||
|
|
||||||
private var optionsView: some View {
|
private var optionsView: some View {
|
||||||
ForEach(poll.options, id: \.id) { option in
|
ForEach(poll.options, id: \.id) { option in
|
||||||
Button {
|
if #available(iOS 18, *) {
|
||||||
guard !option.isSelected else { return }
|
pollOption(option: option)
|
||||||
actionHandler(.selectOption(optionID: option.id))
|
.accessibilityHint(L10n.a11yPollsWillRemoveSelection,
|
||||||
feedbackGenerator.impactOccurred()
|
isEnabled: isRemovePreviousSelectionHintEnabled(option: option))
|
||||||
} label: {
|
} else {
|
||||||
PollOptionView(pollOption: option,
|
pollOption(option: option)
|
||||||
showVotes: showVotes,
|
|
||||||
isFinalResult: poll.hasEnded)
|
|
||||||
.foregroundColor(progressBarColor(for: option))
|
|
||||||
}
|
}
|
||||||
.disabled(poll.hasEnded)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func isRemovePreviousSelectionHintEnabled(option: Poll.Option) -> Bool {
|
||||||
|
!poll.hasEnded && poll.hasMaxSelections && !option.isSelected
|
||||||
|
}
|
||||||
|
|
||||||
|
private func pollOption(option: Poll.Option) -> some View {
|
||||||
|
Button {
|
||||||
|
guard !option.isSelected else { return }
|
||||||
|
actionHandler(.selectOption(optionID: option.id))
|
||||||
|
feedbackGenerator.impactOccurred()
|
||||||
|
} label: {
|
||||||
|
PollOptionView(pollOption: option,
|
||||||
|
showVotes: showVotes,
|
||||||
|
isFinalResult: poll.hasEnded)
|
||||||
|
.foregroundColor(progressBarColor(for: option))
|
||||||
|
}
|
||||||
|
.disabled(poll.hasEnded)
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var summaryView: some View {
|
private var summaryView: some View {
|
||||||
if let summaryText = poll.summaryText {
|
if let summaryText = poll.summaryText {
|
||||||
|
|||||||
+4
@@ -38,6 +38,10 @@ struct Poll: Hashable {
|
|||||||
case undisclosed
|
case undisclosed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hasMaxSelections: Bool {
|
||||||
|
options.filter(\.isSelected).count == maxSelections
|
||||||
|
}
|
||||||
|
|
||||||
struct Option: Hashable {
|
struct Option: Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let text: String
|
let text: String
|
||||||
|
|||||||
Reference in New Issue
Block a user