Adjusting Spacing in ArrangementView

I am trying to adjust the spacing between the primary and secondary views within a SwiftUI ArrangementView. I haven't been able to find a direct parameter or modifier (like spacing) that controls this distance on the container itself.

Is there a standard way to achieve this, or should I be looking into a workaround using padding ?

Thanks for the question, interesting you want that spacing but you can use standard SwiftUI you can create a padding inside each view to the edge:

ArrangementView {
    PrimaryView()
        .padding(.trailing, 16) // Creates the gap

Is that what you want instead of letting ArrangementView do the work for you?

I would suggest to play with it inside the view and add padding or changing the frame with and height:

ArrangementView {
        Text("Primary")
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .background(.blue.opacity(0.2), in: .rect(cornerRadius: 12))
    } secondary: {
        Text("Secondary")
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .background(.green.opacity(0.2), in: .rect(cornerRadius: 12))
    }

You can play with the arrangementViewStyle as well to find something that works for you:

ArrangementView {
    PlayerControls()
} secondary: {
    VideoPlayer()
}
.arrangementViewStyle(.overlay) 

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

Hope this helps, I would suggest to make sure the ArrangementViews are padded well in all positions and views as the device can display those differently depending on the position.

Albert  WWDR

Written by DTS Engineer in 910693022
ArrangementView {
    PrimaryView()
        .padding(.trailing, 16) // Creates the gap

While this is a helpful workaround, it doesn't quite fit my needs as it only works for horizontal arrangements, and I would need to apply it to both views to keep everything centered. Obviously, this can be solved by using multiple horizontal and vertical paddings with if statements, but it will be a headache.

There isn't a spacing parameter on ArrangementView itself. Since the gap needs to follow whichever axis the system chooses, padding both children can add unwanted space at the outside edges too.

If you need a precise gap in both orientations, a custom ArrangementViewStyle is the cleaner option: build the split layout with an HStack(spacing:) or VStack(spacing:) based on the axis, and use the style's primary and secondary content. If you want to keep the built-in split style, the splitArrangementAxis environment value can help each child apply padding on the active axis, but you may need to balance the outer padding as well.

ArrangementViewStyle · SwiftUI updates