Fix: Inline StatusRowView accessibilityLabel modifier to avoid flashing (#1278)
* Inline StatusRowView accessibilityLabel modifier By inlining this label, we avoid the creation of `ConditionalContent`, which often leads to views being recreated unnecessarily. In focused mode, the empty label is not read as, it is the accessibility container label for the post component elements. * Inline StatusRowView accessibilityLabel modifier By inlining this label, we avoid the creation of `ConditionalContent`, which often leads to views being recreated unnecessarily. In focused mode, the empty label is not read as, it is the accessibility container label for the post component elements. * Wrap --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
parent
4ffdd46a2a
commit
3a3d0a7b55
|
@ -1,6 +1,7 @@
|
|||
import DesignSystem
|
||||
import EmojiText
|
||||
import Env
|
||||
import Foundation
|
||||
import Models
|
||||
import Network
|
||||
import Shimmer
|
||||
|
@ -110,7 +111,13 @@ public struct StatusRowView: View {
|
|||
bottom: 12,
|
||||
trailing: .layoutPadding))
|
||||
.accessibilityElement(children: viewModel.isFocused ? .contain : .combine)
|
||||
.modifier(ConditionalAccessibilityLabelModifier(viewModel: viewModel, setLabel: viewModel.isFocused == false))
|
||||
.accessibilityLabel(viewModel.isFocused == false && UIAccessibility.isVoiceOverRunning
|
||||
? CombinedAccessibilityLabel(viewModel: viewModel).finalLabel() : Text(""))
|
||||
.accessibilityCustomContent(
|
||||
LocalizedStringKey("accessibility.status.spoiler-full-content"),
|
||||
viewModel.finalStatus.content.asRawText,
|
||||
importance: .high
|
||||
)
|
||||
.accessibilityAction {
|
||||
viewModel.navigateToDetail()
|
||||
}
|
||||
|
@ -202,11 +209,10 @@ public struct StatusRowView: View {
|
|||
}
|
||||
}
|
||||
|
||||
/// A ``ViewModifier`` that creates a suitable combined accessibility label for a `StatusRowView` that is not focused.
|
||||
/// A utility that creates a suitable combined accessibility label for a `StatusRowView` that is not focused.
|
||||
@MainActor
|
||||
private struct ConditionalAccessibilityLabelModifier: ViewModifier {
|
||||
private struct CombinedAccessibilityLabel {
|
||||
let viewModel: StatusRowViewModel
|
||||
let setLabel: Bool
|
||||
|
||||
var hasSpoiler: Bool {
|
||||
viewModel.displaySpoiler && viewModel.finalStatus.spoilerText.asRawText.isEmpty == false
|
||||
|
@ -223,27 +229,7 @@ private struct ConditionalAccessibilityLabelModifier: ViewModifier {
|
|||
viewModel.status.reblog != nil
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
if UIAccessibility.isVoiceOverRunning == true, setLabel {
|
||||
if hasSpoiler {
|
||||
// Use the spoiler text in the label and place the full text as custom content
|
||||
content
|
||||
.accessibilityLabel(combinedAccessibilityLabel())
|
||||
.accessibilityCustomContent(
|
||||
LocalizedStringKey("accessibility.status.spoiler-full-content"),
|
||||
viewModel.finalStatus.content.asRawText,
|
||||
importance: .high
|
||||
)
|
||||
} else {
|
||||
content
|
||||
.accessibilityLabel(combinedAccessibilityLabel())
|
||||
}
|
||||
} else {
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
func combinedAccessibilityLabel() -> Text {
|
||||
func finalLabel() -> Text {
|
||||
userNamePreamble() +
|
||||
Text(hasSpoiler
|
||||
? viewModel.finalStatus.spoilerText.asRawText
|
||||
|
|
Loading…
Reference in New Issue