Extra spacing above scrollview

I have a fairly simple view that consists of a tile and below it a horizontal scrollview. This display with a large gap between the title and the scrollview and I want the title sitting on top of the scrollview -- maybe 2 or 4 point gap. The current gap looks like 80 points or so.

Code:

    let section: Section
    let userLevel: Int
    let stringsViewModel: StringsViewModel
    let onItemSelected: (AudioItem) -> Void

    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            Text(section.title)
                .font(.system(size: 18, weight: .medium))
                .foregroundColor(.white)
                .padding(.leading, 16)
            ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 16) {
                    ForEach(section.items, id: \.titleKey) { item in
                        MeditationItemView(audioItem: item, userLevel: userLevel, stringsViewModel: stringsViewModel)
                            .onTapGesture {
                                onItemSelected(item)
                            }
                    }
                }
                .padding(.leading, 0)
                .padding(.trailing, 16)
            }
        }
        .padding(.leading, 16)
    }
}

I added some color tracking and I can see that this extra space seems to be some kind of frame around the ScrollView. I guess I might have to explicitly set the height of the scrollview and not rely on it basing its height specifically on the contained content? Does swift UI have the concept of "wrap_content" for the height of a containing control?

It would probably help if you provided your updated code and a screenshot.

Also, is that code the minimum required to reproduce the issue?

Accepted Answer

I figured it out. It was all caused by images wider than they are tall but me specifying the image to be square

Extra spacing above scrollview
 
 
Q