Shapes inside ScrollView not shown in SwiftUI?

Hello all,


I'm just playing around with the new SwiftUI' ScrollView and I would like to draw some basic shapes inside the ScrollView. It compiles but does not show for an unknown reason. The Circle above the ScrollView is shown, but the ScrollView itself has no content shown and I would like to understand why? I added a size because it seams that SwiftUI is not knowing how to scale it - just an idea.


import SwiftUI


struct ContentView : View {

var body: some View {

NavigationView {

VStack {

Circle().size(width: 40, height: 40).fill(Color.red)

ScrollView(showsHorizontalIndicator: false) {

HStack {

ForEach(0..<100) {

Circle().size(width: 40, height: 40).fill(Color.red)

}

}

}.frame(height: 80)

Spacer()

}.navigationBarTitle(Text("Test"))

}

}

}


But when I embed this into a ZStack containing additional Text it works. Obviously, there is something like the position missing:


struct ContentView : View {

var body: some View {

NavigationView {

VStack {

ScrollView(showsHorizontalIndicator: false) {

HStack {

ForEach(0..<100) { h in

ZStack {

Circle().fill(Color.red)

Text("\(h)").padding()

}

}

}

}.frame(height: 80)

Spacer()

}.navigationBarTitle(Text("Test"))

}

}

}


Did anybody find out how this works? I checked all tutorials, maybe I must use a GeometryReader and draw the circle using a Path but I was not able to get this to work yet.


Best regards,

Jürgen

Replies

Tried ScrollView(.horizontal) ?