Instantly share code, notes, and snippets.
Last active
November 25, 2022 14:26
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save filimo/a3b5a92c6a0c7b670b97604cd70c521b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
enum NavTestRoute: Hashable { | |
case child(Int) | |
} | |
struct NavTestChildView: View { | |
let num: Int | |
init(num: Int) { | |
print("[init][NavTestChildView]") | |
self.num = num | |
} | |
var body: some View { | |
Text("NavTestChildView \(num)") | |
} | |
} | |
struct NavTestMainView2: View { | |
init() { | |
print("[init][NavTestMainView2]") | |
} | |
var body: some View { | |
VStack { | |
NavigationLink { | |
NavTestMainView2() | |
} label: { | |
Text("Reenter NavTestMainView") | |
} | |
ForEach(1 ..< 10, id: \.self) { num in | |
NavigationLink(value: NavTestRoute.child(num)) { | |
Text("Open child \(num)") | |
} | |
} | |
} | |
.navigationDestination(for: NavTestRoute.self) { route in | |
switch route { | |
case let .child(num): | |
NavTestChildView(num: num) | |
} | |
} | |
} | |
} | |
struct NavTestMainView: View { | |
init() { | |
print("[init][NavTestMainView]") | |
} | |
var body: some View { | |
NavigationStack { | |
NavTestMainView2() | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum NavTestRoute: Hashable { | |
case child(Int) | |
} | |
struct NavTestChildView: View { | |
let num: Int | |
init(num: Int) { | |
print("[init][NavTestChildView]") | |
self.num = num | |
} | |
var body: some View { | |
Text("NavTestChildView \(num)") | |
} | |
} | |
struct NavTestMainView2: View { | |
@Binding var items: [Int] | |
init(items: Binding<[Int]>) { | |
print("[init][NavTestMainView2]") | |
self._items = items | |
} | |
var body: some View { | |
VStack { | |
NavigationLink { | |
NavTestMainView2(items: $items) | |
} label: { | |
Text("Reenter NavTestMainView") | |
} | |
ForEach(1 ..< 10, id: \.self) { num in | |
NavigationLink(value: NavTestRoute.child(num)) { | |
Text("Open child \(num)") | |
} | |
} | |
} | |
.navigationDestination(for: NavTestRoute.self) { route in | |
switch route { | |
case let .child(num): | |
NavTestChildView(num: num) | |
} | |
} | |
} | |
} | |
struct NavTestMainView: View { | |
@State var items: [Int] = [1, 2, 3, 4] | |
init() { | |
print("[init][NavTestMainView]") | |
} | |
var body: some View { | |
NavigationStack { | |
NavTestMainView2(items: $items) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
enum NavTestRoute: Hashable { | |
case child(Int) | |
} | |
struct NavTestChildView: View { | |
let num: Int | |
var body: some View { | |
Text("NavTestChildView \(num)") | |
} | |
} | |
struct NavTestMainView_Control: View { | |
let num: Int | |
let isDetailMode: Bool | |
@Binding var items: [Int] | |
var body: some View { | |
VStack { | |
if isDetailMode { | |
Text("Long mode \(num)") | |
ForEach(items, id: \.self) { item in | |
NavigationLink(value: NavTestRoute.child(item)) { | |
Text("Go to \(item)") | |
} | |
} | |
} else { | |
Text("Short mode \(num)") | |
} | |
} | |
} | |
} | |
struct NavTestMainView2: View { | |
@State var items: [Int] = [] | |
var body: some View { | |
ForEach(1 ..< 5) { num in | |
NavigationLink { | |
NavTestMainView_Control(num: num, isDetailMode: true, items: $items) | |
} label: { | |
NavTestMainView_Control(num: num, isDetailMode: false, items: $items) | |
} | |
.task { | |
items = [1, 2, 4] | |
} | |
.navigationDestination(for: NavTestRoute.self) { route in | |
switch route { | |
case let .child(num): | |
NavTestChildView(num: num) | |
} | |
} | |
} | |
} | |
} | |
struct NavTestMainView: View { | |
init() { | |
print("[init][NavTestMainView]") | |
} | |
var body: some View { | |
NavigationStack { | |
NavTestMainView2() | |
} | |
} | |
} |
поменял на extension Binding: Equatable where Value: Hashable {
иначе ломается .searchable
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With
case detail(num: Int, items: Binding<[DebugItem]>)