mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-06-26 17:10:36 +00:00
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 DesignSystem
|
||||||
import EmojiText
|
import EmojiText
|
||||||
import Env
|
import Env
|
||||||
|
import Foundation
|
||||||
import Models
|
import Models
|
||||||
import Network
|
import Network
|
||||||
import Shimmer
|
import Shimmer
|
||||||
|
@ -110,7 +111,13 @@ public struct StatusRowView: View {
|
||||||
bottom: 12,
|
bottom: 12,
|
||||||
trailing: .layoutPadding))
|
trailing: .layoutPadding))
|
||||||
.accessibilityElement(children: viewModel.isFocused ? .contain : .combine)
|
.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 {
|
.accessibilityAction {
|
||||||
viewModel.navigateToDetail()
|
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
|
@MainActor
|
||||||
private struct ConditionalAccessibilityLabelModifier: ViewModifier {
|
private struct CombinedAccessibilityLabel {
|
||||||
let viewModel: StatusRowViewModel
|
let viewModel: StatusRowViewModel
|
||||||
let setLabel: Bool
|
|
||||||
|
|
||||||
var hasSpoiler: Bool {
|
var hasSpoiler: Bool {
|
||||||
viewModel.displaySpoiler && viewModel.finalStatus.spoilerText.asRawText.isEmpty == false
|
viewModel.displaySpoiler && viewModel.finalStatus.spoilerText.asRawText.isEmpty == false
|
||||||
|
@ -223,27 +229,7 @@ private struct ConditionalAccessibilityLabelModifier: ViewModifier {
|
||||||
viewModel.status.reblog != nil
|
viewModel.status.reblog != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
func finalLabel() -> Text {
|
||||||
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 {
|
|
||||||
userNamePreamble() +
|
userNamePreamble() +
|
||||||
Text(hasSpoiler
|
Text(hasSpoiler
|
||||||
? viewModel.finalStatus.spoilerText.asRawText
|
? viewModel.finalStatus.spoilerText.asRawText
|
||||||
|
|
Loading…
Reference in a new issue