The reply immediately above this has one other change: I'm passing just an index (shownSteps) into the scrollTo method rather than gameModel.conversationPoints[shownSteps].id, but the behavior is the same either way.
Interestingly, I've tried to reproduce this behavior in a smaller app, shown here, and the simpler app seems to work correctly everywhere. I have no what the difference is in the "real" app that makes it behave differently on some platforms.
import SwiftUI
import SwiftData
@main
struct SampleScrollApp: App {
static var numbers = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"]
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State var index = 0
var body: some View {
VStack {
HStack {
Button {
} label: {
Text("Show Full Conversation")
}
Spacer()
Button {
} label: {
Text("Skip Conversation")
}
}.padding(5).background(Color.black)
ScrollView {
ScrollViewReader { proxy in
VStack {
ForEach(0..<12) { item in
if (item <= index)
{
TextyView(myIndex: item)
.id(item)
}
}
}.onChange(of: index) { _,_ in proxy.scrollTo(index, anchor: .bottom) }
}
}
Button { index = index + 1 } label: {Text("More") }
}.frame(width:400, height: 375)
}
}
struct TextyView : View {
var myIndex: Int
var body: some View {
VStack {
Text("[\(myIndex)]").font(.title)
HStack {
Spacer()
Text(SampleScrollApp.numbers[myIndex])
.font(.title)
.multilineTextAlignment(.center)
}
}.padding(50)
.border(Color.primary)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
#Preview {
ContentView()
}