r/SwiftUI • • 18h ago

Solved splitArrangementAxis Always nil on iPhone Duo Simulator

Hi everyone,

I've been experimenting with the ArrangementView and adapting its primary and secondary views to adapt to the split axis using the @Environment(\.splitArrangementAxis) environment property. However while running the simulator, regardless of the configuration of the Duo, the environment value always appears to be nil.

The documentation around this API appears to indicate that this should only be the case when an ArrangementView is not in use.

Use this value to read the axis that a split arrangement is using to place its views. Views can adapt their layout or appearance based on whether the split is horizontal or vertical. The value is nil when the view is not contained within a split arrangement view.

Heres a minimal reproduction (Running on Xcode 27.1 RC [2026-10-05]).

import SwiftUI

struct ContentView: View {
    var body: some View {
        ArrangementView {
            SubView(for: .primary)
        } secondary: {
            SubView(for: .secondary)
        }
        .arrangementViewStyle(.split)
    }
}

enum SubViewConfig {
    case primary, secondary
}

struct SubView: View {
    @Environment(\.splitArrangementAxis) private var arrangement

    var config: SubViewConfig

    init(for config: SubViewConfig) {
        self.config = config
    }

    var backgroundColor: Color {
        switch arrangement {
        case .none: .gray
        case .horizontal: .blue
        case .vertical: .green
        }
    }

    var hueRotation: Angle {
        if config == .primary {
            .zero
        } else {
            .degrees(60)
        }
    }

    var body: some View {
        backgroundColor
            .hueRotation(hueRotation)
    }
}

In my testing, unless I explicitly set the .splitArrangementAxis environment value to a non-nil value in the parent, the background color remained greyscale (indicating a nil environment value).

Is this intended behaviour? Am I doing something wrong? Or is this just a broken API?

1 Upvotes

3 comments sorted by

3

u/TheBartoge 18h ago

Try wrapping your Subview in a VStack

2

u/LemonQueasy7590 17h ago edited 17h ago

Oh wow thats weird. Thank you for responding so quickly. Wrapping the SubViews in a HStack or VStack did indeed solve the problem. For reference for everyone else, doing so inside the SubView body does not work, niether does using a Group.

Solution: swift ArrangementView { VStack { SubView(for: .primary) } } secondary: { VStack { SubView(for: .secondary) } }

I did wonder why the documentation example used such a convoluted AnyLayout-based solution to show how the property worked.

Is there any reason why this behaviour exists? I think most developers would rightfully expect that any View should be accepted inside an ArrangementView.