0

我在父垂直滚动视图中有水平菜单滚动视图。当我选择菜单时,它会刷新它会刷新 listView。但是要修复父 scrollView 内容大小,我需要通过将 menuItem 选择的 id 分配给父 scrollView 来刷新整个视图(scrollView)。

一切都按预期工作,但由于我已将 menuItem id 分配给父 scrollView 以修复内容大小/高度问题,滚动选定菜单的动画不起作用。

有什么办法可以实现这个动画吗?

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
}

}
4

0 回答 0