I have horizontal menu scrollView inside Parent vertical scrollView. When I select menu, it refresh it refreshes listView. But to fix parent scrollView content size, I need to refresh entire View (scrollView) by assigning menuItem selected id to parent scrollView.
Everything works as expected but as I have assigned menuItem id to parent scrollView to fix content size/height issue, animation for scrolling selected menu doesn't work.
Is there any way I can achieve this animation?
struct SampleScrollView: View {
// Parent scroll view to fit multiple sub-views
ScrollView(.vetical, showsIndicators: false) {
Vstack {
HStack {
ScrollView(.horizontal, showsIndicators: false) {
ScrollViewReader { proxy in
HStack {
ForEach(Menus, id: \.menuItem) { menu in
Button(action: {
// This animation is not working as parent scrollView gets assigned with this selected menuItem id on menu click which helps Parent ScrollView to get refreshed so parent scrollview content size get's refreshed based on content height of result list view.
withAnimation {
proxy.scrollTo(menuItem, anchor: .leading)
}
LoadList()
}) {
Text("Option \(menuItem)")
}
}
}
}
}
}
VStack {
ScrollView(.vertical, showsIndicators: false) {
LazyVStack {
ForEach(resultArray, id: \.self) { item in
Text(item.title)
}
}
}
}
// Some other views here
VStack { }
}.id(menuItem) // Parent ScrollView Id get's updated every time when menu button selected
}
}