Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable ScrollView over scroll in SwiftUI

Tags:

swift

swiftui

I've implemented a vertical scroll view (using List) containing two horizontal scroll views (using ScrollViews). The UI currently looks like this:

Here's the relevant code I've written to produce above UI:

NavigationView {
    List {
        VStack(alignment: .leading) {
            CategoryRow(...)
            CategoryRow(...)
            Spacer()
        }
        .listRowInsets(EdgeInsets())
        .navigationBarTitle(Text("Featured"))
    }
}

Inside each CategoryRow, there's an HStack embedded inside a ScrollView.
When introducing a padding on the left & right edges, I get this result:

As you can see, as a result of the padding, the horizontal scroll views are cut-off.

Question

Is there a way to have the horizontal scroll views over-scroll past their boundaries?
The result I am looking for is that there is padding on the left of the scroll views when the scroll offset is 0 and padding on the right when the scrolling all the way to the right.

In UIKit, I did this by setting the contentOffset of the collection view...

like image 606
LinusGeffarth Avatar asked Oct 17 '25 22:10

LinusGeffarth


1 Answers

Add the padding modifier to your HStack inside the RowView

.padding(.horizontal, 20)
like image 140
DenFav Avatar answered Oct 20 '25 11:10

DenFav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!