Files
simplex-chat/apps/ios/Shared/Views/Helpers/NavStackCompat.swift
Arturs Krumins f922064f5c iOS: fix chat list temporarily navigating to an empty view (#4647)
* add two way binding for chatList navigation

* style

---------

Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
2024-08-10 22:23:56 +01:00

46 lines
1.2 KiB
Swift

//
// NavStackCompat.swift
// SimpleX (iOS)
//
// Created by Evgeny on 23/01/2023.
// Copyright © 2023 SimpleX Chat. All rights reserved.
//
import SwiftUI
struct NavStackCompat <C: View, D: View>: View {
let isActive: Binding<Bool>
let destination: () -> D
let content: () -> C
var body: some View {
if #available(iOS 16, *) {
NavigationStack(path: Binding(
get: { isActive.wrappedValue ? [true] : [] },
set: { path in
if path.isEmpty { isActive.wrappedValue = false }
}
)) {
ZStack {
NavigationLink(value: true) { EmptyView() }
content()
}
.navigationDestination(for: Bool.self) { show in
if show { destination() }
}
}
} else {
NavigationView {
ZStack {
NavigationLink(
destination: destination(),
isActive: isActive
) { EmptyView() }
content()
}
}
.navigationViewStyle(.stack)
}
}
}