From 3ef15b9b0d032a0ff162531c4d61b8d04a606ef9 Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Tue, 22 Aug 2023 18:42:41 +0200 Subject: [PATCH] Fix timestamp not rendering properly when RTL and LTR are mixed together (#1539) * fix * changelog --- .../RoomScreen/View/Timeline/FormattedBodyText.swift | 9 ++++++--- changelog.d/pr-1539.bugfix | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelog.d/pr-1539.bugfix diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/FormattedBodyText.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/FormattedBodyText.swift index 255d34593a..49a25f6d51 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/FormattedBodyText.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/FormattedBodyText.swift @@ -31,9 +31,9 @@ struct FormattedBodyText: View { container.foregroundColor = UIColor.compound.textPrimary return container }() - + private var attributedComponents: [AttributedStringBuilderComponent] { - var adjustedAttributedString = attributedString + AttributedString(additionalWhitespacesSuffix) + var adjustedAttributedString = AttributedString(layoutDirection.isolateLayoutUnicodeString) + attributedString + AttributedString(additionalWhitespacesSuffix) // Required to allow the underlying TextView to use body font when no font is specifie in the AttributedString. adjustedAttributedString.mergeAttributes(defaultAttributesContainer, mergePolicy: .keepCurrent) @@ -89,7 +89,10 @@ struct FormattedBodyText: View { var bubbleLayout: some View { TimelineBubbleLayout(spacing: 8) { ForEach(attributedComponents, id: \.self) { component in - if component.isBlockquote { + // Ignore if the string contains only the layout correction + if String(component.attributedString.characters) == layoutDirection.isolateLayoutUnicodeString { + EmptyView() + } else if component.isBlockquote { // The rendered blockquote with a greedy width. The custom layout prevents the // infinite width from increasing the overall width of the view. MessageText(attributedString: component.attributedString.mergingAttributes(blockquoteAttributes)) diff --git a/changelog.d/pr-1539.bugfix b/changelog.d/pr-1539.bugfix new file mode 100644 index 0000000000..6e992af1c3 --- /dev/null +++ b/changelog.d/pr-1539.bugfix @@ -0,0 +1 @@ +Improve timestamp rendering when mixed LTR and RTL languages are present in the message. \ No newline at end of file