Fix for the content not updating after an edit, restore the usage of the content based identifier in the formatted body for components.

This commit is contained in:
Mauro Romito
2026-05-26 14:00:35 +02:00
committed by Mauro
parent ef82d184fe
commit 277f0cc5bc
3 changed files with 11 additions and 5 deletions
@@ -68,13 +68,16 @@ struct FormattedBodyText: View {
// timestamp would land on top of it, so append an empty trailing plain-text
// component that exists solely to reserve space for the timestamp underneath.
if trailingReservedSize != .zero, let last = components.last, last.type != .plainText {
components.append(AttributedStringBuilderComponent(attributedString: AttributedString(),
components.append(AttributedStringBuilderComponent(id: "",
attributedString: AttributedString(),
type: .plainText))
}
let lastPlainTextIndex = components.lastIndex { $0.type == .plainText }
return TimelineBubbleLayout(spacing: 8) {
ForEach(Array(components.enumerated()), id: \.offset) { index, component in
// The `ForEach` needs to iterate over the id of the element to allow
// SwiftUI animations to work properly ater any edit.
ForEach(Array(components.enumerated()), id: \.element.id) { index, component in
switch component.type {
case .blockquote:
BlockquoteView(attributedString: component.attributedString, mode: .rendering)
@@ -98,7 +101,7 @@ struct FormattedBodyText: View {
// Make a second iteration through the components adding naturally sized versions of the
// block quotes and code blocks which are used for layout calculations but won't be rendered.
ForEach(Array(components.enumerated()), id: \.offset) { _, component in
ForEach(components) { component in
switch component.type {
case .blockquote:
BlockquoteView(attributedString: component.attributedString, mode: .layout)