It works well, if it is the first view when the app start. Else, it doesn't work well within Navigation. why?? I have no clues.
struct TestView: View { @StateObject var viewModel = TestViewModel1() @State var data : [String] = ["one", "two", "three", "four", "five", "one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "five","one", "two", "three", "four", "bottom most" ]
@State var scrollToId = "hi"
var body: some View {
ScrollViewReader { proxy in
List{
ForEach(0..<data.count, id : \.self){ index in
Text(data[index])
.frame(minWidth : 0, maxWidth : .infinity)
}
Text("")
.frame(minHeight : 0, maxHeight: 0)
.id(self.scrollToId)
}
.onAppear{
proxy.scrollTo(self.scrollToId)
}
}
}
}
With navigation, "scrollTo" doesn't work
Without navigation, it works well