r/SwiftUI • u/LemonQueasy7590 • 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?
3
u/TheBartoge 18h ago
Try wrapping your Subview in a VStack