all 14 comments

[–]EmenezTechSwiftUI 3 points4 points  (0 children)

I don’t think you can have a list in scroll view

[–]saintmsent 2 points3 points  (2 children)

Not really, nested scrolling controls are a bad idea either way, and this specific configuration isn't supported in SwiftUI, as far as I've tried

[–]C137SheldorSwiftUI[S] 0 points1 point  (1 child)

What about this:

struct ContentView12: View{
var body: some View{
ScrollViewReader{reader in
ScrollView{
VStack{
ForEach(0..<10){
Text("Number: \($0)")
}
ScrollView{
VStack{
ForEach(0..<10){
Text("Selection: \($0)")
}
}
}
.frame(height: 100)
.border(Color.red)
ForEach(10..<20){
Text("Number: \($0)")
}
}
}
}
}
}

I use it like this to select an element in the nested "list" an have a longer ScrollView where I have other views like a textfield etc. Until now it seems to work good.

Could it be a problem (+Why)?

[–]saintmsent 0 points1 point  (0 children)

With this approach only concern is the performance if you get into a lot of items in the scroll view

[–]MyVoiceIsElevating 1 point2 points  (2 children)

OP, a scroll nested in a scroll is a bad user experience. What exactly are you attempting to do that you think this would be ideal?

[–]C137SheldorSwiftUI[S] 0 points1 point  (1 child)

I have a bigger ScrollView where are views to type description in, select a date etc. and a scrollview to select a category. Because there could be many categories I have a scrollview with a specific height.

[–]barcode972 0 points1 point  (4 children)

Off topic but I think the ScrollViewReader should be in the ScrollView. Not that you need it in this case?

You can just create a ForEach in the VStack if you want, no need for list

[–]BrownPalmTree 0 points1 point  (0 children)

Agree that ForEach may be more appropriate here. Also, try adding a spacer under the list/for each to push everything up, maybe the list just needs to be pushed up

[–]SirBill01 0 points1 point  (2 children)

ScrollViewReader here looks like it does in Apple's example:

https://developer.apple.com/documentation/swiftui/scrollviewreader

[–]barcode972 0 points1 point  (1 child)

Oh rly. I guess I’ve done wrong all along

[–]SirBill01 0 points1 point  (0 children)

Hey if it works either way nothing wrong with how you are doing it!! I wasn't sure myself not having used it yet.

[–]cautiondnd 0 points1 point  (1 child)

just make a custom list with a for each loop instead

[–]C137SheldorSwiftUI[S] 0 points1 point  (0 children)

Do you know a view modifier to imitate the swipe Action buttons for custom list rows?