another try

This commit is contained in:
Avently
2023-01-20 23:49:59 +03:00
parent 96808f18d4
commit f69cdb84bc
2 changed files with 16 additions and 6 deletions

View File

@@ -17,7 +17,7 @@ struct ChatListView: View {
@State private var showAddChat = false
var body: some View {
NavStackWorkaround {
NavStackWorkaround(isPresented: Binding(get: { chatModel.chatId != nil }, set: { _ in }), destination: chatView) {
VStack {
if chatModel.chats.isEmpty {
onboardingButtons()
@@ -29,7 +29,6 @@ struct ChatListView: View {
}
}
}
.navigationViewStyle(.stack)
}
var chatList: some View {
@@ -76,13 +75,15 @@ struct ChatListView: View {
}
}
.background(
NavigationLink(
ProcessInfo().operatingSystemVersion.majorVersion < 16
? NavigationLink(
destination: chatView(),
isActive: Binding(
get: { chatModel.chatId != nil },
set: { _ in }
)
) { EmptyView() }
: nil
)
}

View File

@@ -65,12 +65,21 @@ extension View {
}
}
struct NavStackWorkaround<T: View>: View {
let content: ()->T
struct NavStackWorkaround <C: View, D: View>: View {
let isPresented: Binding<Bool>
let destination: () -> D
let content: () -> C
var body: some View {
if #available(iOS 16, *) {
NavigationStack(root: content)
NavigationStack {
content()
.navigationDestination(isPresented: isPresented) {
destination()
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden(true)
}
}
} else {
NavigationView(content: content)
.navigationViewStyle(.stack)