I was testing out your view and noticed it slows down as more and more text gets added to the view? You can run this test code to see it in action
slow-demo.mov
import SwiftUI
import StreamChatAI
class MockStreamingStringSource : ObservableObject {
@Published var text = " "
let source = " **load_eligibility_plist**: Failed to open \n * One \n * Two \n * Three \n "
let amountLimit = 20
var count = 0
var timer : Timer ?
init ( ) {
timer = Timer . scheduledTimer ( withTimeInterval: 1.0 , repeats: true , block: { t in
self . click ( )
} )
}
deinit {
timer? . invalidate ( )
timer = nil
}
func click( ) {
text. append ( " \( count) : " )
text. append ( source)
count += 1
if count >= amountLimit {
timer? . invalidate ( )
timer = nil
text. append ( " FINISHED!! " )
}
}
}
struct StreamingMessagePreviewView : View {
@StateObject var stream : MockStreamingStringSource = . init( )
var body : some View {
StreamingMessageView (
content: stream. text,
isGenerating: true
)
}
}
#Preview {
ScrollView {
VStack {
StreamingMessagePreviewView ( )
}
}
}
I was testing out your view and noticed it slows down as more and more text gets added to the view? You can run this test code to see it in action
slow-demo.mov