mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-31 20:36:19 +00:00
* add two way binding for chatList navigation * style --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
46 lines
1.2 KiB
Swift
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)
|
|
}
|
|
}
|
|
}
|