Hello. Can anyone tell me how to implement horizontal and vertical list synchronization in swiftui? For example, a horizontal list is a group, a vertical list is a row of groups. Example: drive.google.com/file/d/13CVnUYaf4zyD295LnDUFJ7aNLVKDfYvp/view?usp=sharing
Two synchronized lists
Could you show the code you have tried, with a state var for each list ?
I haven't written the code yet, because I don't know how to do it right. I just have separate horizontal and vertical scrolling lists.
I have a list in which there are groups, these groups should be above the vertical list in the form of a horizontal list, and if you scroll through the vertical list, then the top list automatically switches to the desired group
Code Block LazyVStack(alignment: .leading, spacing: 15, pinnedViews: [.sectionHeaders], content: { if (tags != nil){ ScrollView (.horizontal, showsIndicators: false) { HStack{ ForEach(tags){tag in TagView(tag: tag) .onTapGesture(count: 1) { print(tag.name) } } } } } VStack(alignment: .leading){ Divider() Text("Example") .font(.system(size:19)) .fontWeight(.bold) .padding(.vertical, 10.0) .foregroundColor(textColor) Divider() if (rests != nil){ ScrollView(.vertical, showsIndicators: true, content: { ForEach(rests){rest in RestView(rest: rest) } }) .padding(.top, 15.0) } } .padding(.leading, 15.0) })
I have a list in which there are groups, these groups should be above the vertical list in the form of a horizontal list, and if you scroll through the vertical list, then the top list automatically switches to the desired group
You should manage each scroll position in a State var.
Have a look here for example:
https://stackoverflow.com/questions/56503243/get-the-current-position-of-scrollview-in-swiftui
Have a look here for example:
https://stackoverflow.com/questions/56503243/get-the-current-position-of-scrollview-in-swiftui
thx, I'll try )