mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Fixes #2286 - Timeline entries flickering when a lot of mention pills present
This commit is contained in:
committed by
Stefan Ceriu
parent
ed380ec4c9
commit
9bb177bff5
@@ -18,7 +18,12 @@ import Foundation
|
|||||||
|
|
||||||
extension AttributedString {
|
extension AttributedString {
|
||||||
var formattedComponents: [AttributedStringBuilderComponent] {
|
var formattedComponents: [AttributedStringBuilderComponent] {
|
||||||
runs[\.blockquote].map { value, range in
|
var components = [AttributedStringBuilderComponent]()
|
||||||
|
|
||||||
|
for (index, run) in runs[\.blockquote].enumerated() {
|
||||||
|
let value = run.0
|
||||||
|
let range = run.1
|
||||||
|
|
||||||
var attributedString = AttributedString(self[range])
|
var attributedString = AttributedString(self[range])
|
||||||
|
|
||||||
// Remove trailing new lines if any
|
// Remove trailing new lines if any
|
||||||
@@ -29,8 +34,10 @@ extension AttributedString {
|
|||||||
|
|
||||||
let isBlockquote = value != nil
|
let isBlockquote = value != nil
|
||||||
|
|
||||||
return AttributedStringBuilderComponent(attributedString: attributedString, isBlockquote: isBlockquote)
|
components.append(AttributedStringBuilderComponent(id: index, attributedString: attributedString, isBlockquote: isBlockquote))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return components
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces the specified placeholder with a string that links to the specified URL.
|
/// Replaces the specified placeholder with a string that links to the specified URL.
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct AttributedStringBuilderComponent: Hashable {
|
struct AttributedStringBuilderComponent: Hashable, Identifiable {
|
||||||
|
let id: Int
|
||||||
let attributedString: AttributedString
|
let attributedString: AttributedString
|
||||||
let isBlockquote: Bool
|
let isBlockquote: Bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ struct FormattedBodyText: View {
|
|||||||
/// The attributed components laid out for the bubbles timeline style.
|
/// The attributed components laid out for the bubbles timeline style.
|
||||||
var bubbleLayout: some View {
|
var bubbleLayout: some View {
|
||||||
TimelineBubbleLayout(spacing: 8) {
|
TimelineBubbleLayout(spacing: 8) {
|
||||||
ForEach(attributedComponents, id: \.self) { component in
|
ForEach(attributedComponents) { component in
|
||||||
// Ignore if the string contains only the layout correction
|
// Ignore if the string contains only the layout correction
|
||||||
if String(component.attributedString.characters) == layoutDirection.isolateLayoutUnicodeString {
|
if String(component.attributedString.characters) == layoutDirection.isolateLayoutUnicodeString {
|
||||||
EmptyView()
|
EmptyView()
|
||||||
@@ -123,7 +123,7 @@ struct FormattedBodyText: View {
|
|||||||
|
|
||||||
// Make a second iteration through the components adding fixed width blockquotes
|
// Make a second iteration through the components adding fixed width blockquotes
|
||||||
// which are used for layout calculations but won't be rendered.
|
// which are used for layout calculations but won't be rendered.
|
||||||
ForEach(attributedComponents, id: \.self) { component in
|
ForEach(attributedComponents) { component in
|
||||||
if component.isBlockquote {
|
if component.isBlockquote {
|
||||||
MessageText(attributedString: component.attributedString.mergingAttributes(blockquoteAttributes))
|
MessageText(attributedString: component.attributedString.mergingAttributes(blockquoteAttributes))
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
@@ -138,7 +138,7 @@ struct FormattedBodyText: View {
|
|||||||
/// The attributed components laid out for the plain timeline style.
|
/// The attributed components laid out for the plain timeline style.
|
||||||
var plainLayout: some View {
|
var plainLayout: some View {
|
||||||
VStack(alignment: .leading, spacing: 8.0) {
|
VStack(alignment: .leading, spacing: 8.0) {
|
||||||
ForEach(attributedComponents, id: \.self) { component in
|
ForEach(attributedComponents) { component in
|
||||||
if component.isBlockquote {
|
if component.isBlockquote {
|
||||||
HStack(spacing: 4.0) {
|
HStack(spacing: 4.0) {
|
||||||
Rectangle()
|
Rectangle()
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Fix timeline entries flickering when a lot of mention pills present
|
||||||
Reference in New Issue
Block a user