Here's the code for DialogueView in case that's helpful:
struct DialogueView: View {
@EnvironmentObject var dialogueModel: DialogueViewModel
var body: some View {
VStack{
ScrollView{
ForEach(dialogueModel.messages.filter({$0.role != .system}), id: \.id){ message in
messageView(message: message)
Spacer()
}
}
HStack{
TextField("Enter a message...", text: $dialogueModel.currentInput)
Button{
dialogueModel.sendMessage()
} label: {
Text("Send")
}
}
}
.padding()
}
func messageView(message: Message) -> some View{
HStack{
if message.role == .user {Spacer()}
Text(message.content)
if message.role == .assistant {Spacer()}
}
}
}
Post
Replies
Boosts
Views
Activity
I need the view to update every time the index changes, but only once. The reason I try to check and re-set scene change is because I don't want it to re-render the same content every time update is called, since it's getting called when I enter messages in the attachment, and other times.
Is it not an issue for the view to re-render every time update is called? (right now this means removing current scene images and adding the corresponding images for the 'new' scene) I'm not sure why update is called on a loop whenever I start to enter text into the dialogue view.
This still gives the same error, I just don't know how to edit the original post so it shows the right code.
Quick Edit: I was debugging and forgot to add the statement to the provided code, at the beginning of the "if sceneChange { ... conditional.
DispatchQueue.main.async{
self.sceneChange = false
}