Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created February 7, 2021 07:45
Show Gist options
  • Save prafullakumar/214b5d124c31496d6cb21557395b94e8 to your computer and use it in GitHub Desktop.
Save prafullakumar/214b5d124c31496d6cb21557395b94e8 to your computer and use it in GitHub Desktop.
ScrollView(.horizontal, showsIndicators: false, content: {
ScrollViewReader { scrollReader in
ForEach(0..<dataModel.count) { i in
Text(dataModel[i])
.id(i)
.onTapGesture {
withAnimation{
self.selection = i //change tab with animation
}
}
Spacer().frame(width: 20)
}
}
.padding(.top).onChange(of: selection, perform: { value in
withAnimation{
scrollReader.scrollTo(value, anchor: .center)
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment