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

View File

@ -359,15 +359,19 @@ class NavigationSplitCoordinator: CoordinatorProtocol, ObservableObject, CustomS
private struct NavigationSplitCoordinatorView: View {
@State private var columnVisibility = NavigationSplitViewVisibility.all
@State private var isInSplitMode = true
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@Environment(\.scenePhase) private var scenePhase
@ObservedObject var navigationSplitCoordinator: NavigationSplitCoordinator
var body: some View {
Group {
if horizontalSizeClass == .compact {
navigationStack
} else {
if isInSplitMode {
navigationSplitView
} else {
navigationStack
}
}
// 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
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

View File

@ -37,7 +37,7 @@ struct PlaceholderScreen: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background()
.environment(\.backgroundStyle, AnyShapeStyle(Color.compound.bgCanvasDefault))
.toolbar(.hidden, for: .automatic)
.ignoresSafeArea(edges: .top)
}
@ViewBuilder