I am trying to reset my ScrollView when the user selects a tab. The problem is all the tutorials are for buttons nested inside the ScrollView. My ScrollView is completely separate from where I need to tap to reset the ScrollView.
I found this tutorial - https://www.hackingwithswift.com/forums/swiftui/have-a-button-outside-of-scrollviewreader-be-able-to-scroll-the-scrollview-to-a-position/2741
Yet I get the error "Cannot find proxy in scope".
@EnvironmentObject var global: GlobalObserver
return ScrollView {
ScrollViewReader { (proxy: ScrollViewProxy) in
EmptyView()
}.onChange(of: self.global.resetScroll){ resetScroll in
if (resetScroll){
proxy.scrollTo(0)
self.global.resetScroll = false
}
}
If anyone knows an easier implementation to setting ScrollView position outside of the View I would be happy to hear it.