struct HomeListView:View {
@State private var favoriteColor = 0
var body: some View {
VStack {
Picker("What is your favorite color?", selection: $favoriteColor) {
Text("Red").tag(0)
Text("Green").tag(1)
}
.pickerStyle(.segmented)
.padding(EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8))
selectedView
}
.navigationBarTitleDisplayMode(.inline)
}
@ViewBuilder var selectedView: some View {
switch favoriteColor {
case 0:
HomeViewListing()
default:
TestListingView()
}
}
}
struct HomeViewListing:View {
var body: some View {
ScrollView {
LazyVStack {
ForEach(0..<100) { item in
Text("\(item)")
}
}
}
.scrollIndicators(.hidden)
}
}
struct TestListingView:View {
var body: some View {
ScrollView {
LazyVStack {
ForEach(0..<100) { item in
Text("\(item)")
}
}
}
.scrollIndicators(.hidden)
}
}
Steps to reproduce
1)Scroll HomeListingView item to 98
2)Change segment control( to TestListingView)
3)Change segment control again(to HomeListingView)
Scroll position is changed now to 0 but it should be at position 98(step 1 )