Fixes #617 - Prevent navigation bar breaking when backgrounding the app froma a split view

This commit is contained in:
Stefan Ceriu
2023-09-04 14:45:56 +03:00
committed by Stefan Ceriu
parent d182202c78
commit 1a12c729de
2 changed files with 27 additions and 4 deletions
@@ -359,15 +359,19 @@ class NavigationSplitCoordinator: CoordinatorProtocol, ObservableObject, CustomS
private struct NavigationSplitCoordinatorView: View { private struct NavigationSplitCoordinatorView: View {
@State private var columnVisibility = NavigationSplitViewVisibility.all @State private var columnVisibility = NavigationSplitViewVisibility.all
@State private var isInSplitMode = true
@Environment(\.horizontalSizeClass) private var horizontalSizeClass @Environment(\.horizontalSizeClass) private var horizontalSizeClass
@Environment(\.scenePhase) private var scenePhase
@ObservedObject var navigationSplitCoordinator: NavigationSplitCoordinator @ObservedObject var navigationSplitCoordinator: NavigationSplitCoordinator
var body: some View { var body: some View {
Group { Group {
if horizontalSizeClass == .compact { if isInSplitMode {
navigationStack
} else {
navigationSplitView navigationSplitView
} else {
navigationStack
} }
} }
// This needs to be handled on the top level otherwise sheets // This needs to be handled on the top level otherwise sheets
@@ -380,6 +384,25 @@ private struct NavigationSplitCoordinatorView: View {
.fullScreenCover(item: $navigationSplitCoordinator.fullScreenCoverModule) { module in .fullScreenCover(item: $navigationSplitCoordinator.fullScreenCoverModule) { module in
module.coordinator?.toPresentable() module.coordinator?.toPresentable()
} }
// Handle `horizontalSizeClass` changes breaking the navigation bar
// https://github.com/vector-im/element-x-ios/issues/617
.onChange(of: horizontalSizeClass) { value in
guard scenePhase != .background else {
return
}
isInSplitMode = value == .regular
}
.onChange(of: scenePhase) { value in
guard value == .active else {
return
}
isInSplitMode = horizontalSizeClass == .regular
}
.task {
isInSplitMode = horizontalSizeClass == .regular
}
} }
/// The NavigationStack that will be used in compact layouts /// The NavigationStack that will be used in compact layouts
@@ -37,7 +37,7 @@ struct PlaceholderScreen: View {
.frame(maxWidth: .infinity, maxHeight: .infinity) .frame(maxWidth: .infinity, maxHeight: .infinity)
.background() .background()
.environment(\.backgroundStyle, AnyShapeStyle(Color.compound.bgCanvasDefault)) .environment(\.backgroundStyle, AnyShapeStyle(Color.compound.bgCanvasDefault))
.toolbar(.hidden, for: .automatic) .ignoresSafeArea(edges: .top)
} }
@ViewBuilder @ViewBuilder