When using safeAreaBar, what’s the best way to keep its content on just one side of the fold in book mode? Would you recommend using the .division reserved region to adjust the layout manually, or is there a more built-in SwiftUI approach?
Hello @hiddevdploeg ,
The code snippet you shared seems correct, however the screenshot does not demonstrate two views currently in an ArrangementView – it only shows one view spanning both folds. I was able to achieve the expected result using the same skeleton you shared:
ArrangementView {
someView
.safeAreaBar(edge: .bottom) {
someContent
}
} secondary: {
someView
.safeAreaBar(edge: .bottom) {
someContent
}
}
Take a look at the full code below.
I have a feeling there is code you didn’t share that is conflicting with the display of the ArrangementView.
In that code you will see I used an ArrangementViewStyle, where you can customize what axis two views are arranged by: .horizontal for side-by-side views, .vertical for views stacked ontop of one another, or use the default style to opt in to both vertical and horizontal arrangements. In your screenshot, I don’t see any arrangements, so try the full code.
For this example the ArrangementView is using a split axis of horizontal to make sure the views are only displayed side by side.
For a full list of arrangement styles see ArrangmentViewStyles
Travis
struct ContentView: View {
var body: some View {
NavigationStack {
ArrangementView {
someView
.safeAreaBar(edge: .bottom) {
someContent
}
} secondary: {
someView
.safeAreaBar(edge: .bottom) {
someContent
}
}
.arrangementViewStyle(
.split.axes(.horizontal))
}
}
private var someView: some View {
Color.red
.ignoresSafeArea()
}
private var someContent: some View {
Text("Continue")
.padding(.vertical, 5)
.frame(maxWidth: .infinity)
.padding(.horizontal)
.glassEffect()
.padding()
}
}