Skip to content

Commit 298a77b

Browse files
committed
formating
1 parent 9b44e68 commit 298a77b

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Experimenting with navigation link. if you find this idea interesting you can take and expend it into a more powerful solution.
55
[Live youtube](https://youtu.be/_wbJqWjqCO0)
66

7-
## The result navigaion
7+
## The result navigation
88
```swift
99

1010
@State var route : Router = .empty
@@ -52,7 +52,7 @@ enum Router {
5252
}
5353
}
5454
```
55-
### 3. Define view modifire
55+
### 3. Define view modifier
5656
```swift
5757
struct NavigationModifire : ViewModifier{
5858

Shared/ContentView.swift

+21-27
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,50 @@
66
// The link to the code is under the video
77
//
88

9-
109
import SwiftUI
1110

12-
//experimenting with nav link
11+
// experimenting with nav link
1312
struct ContentView: View {
14-
15-
@State var route : Router = .empty
13+
@State var route: Router = .empty
1614

1715
var body: some View {
18-
NavigationView{
19-
VStack{
20-
Button("go1") { route = .go1}
21-
Button("go2") { route = .go2}
22-
Button("go3") { route = .go3}
16+
NavigationView {
17+
VStack {
18+
Button("go1") { route = .go1 }
19+
Button("go2") { route = .go2 }
20+
Button("go3") { route = .go3 }
2321
}.navigation(route: $route)
2422
}.navigationViewStyle(.stack)
2523
}
2624
}
2725

28-
extension View{
26+
extension View {
2927
@ViewBuilder
30-
func navigation(route : Binding<Router>) -> some View{
31-
if route.wrappedValue != .empty{
28+
func navigation(route: Binding<Router>) -> some View {
29+
if route.wrappedValue != .empty {
3230
modifier(NavigationModifire(route: route))
33-
}else { self }
31+
} else { self }
3432
}
3533
}
3634

3735
// MARK: - define view modifire
38-
struct NavigationModifire : ViewModifier{
39-
40-
@State var isActive : Bool = true
41-
42-
@Binding var route : Router
43-
36+
37+
struct NavigationModifire: ViewModifier {
38+
@State var isActive: Bool = true
39+
40+
@Binding var route: Router
41+
4442
func body(content: Content) -> some View {
4543
content
46-
.background{
47-
NavigationLink(destination : route.builder, isActive: $isActive ){
44+
.background {
45+
NavigationLink(destination: route.builder, isActive: $isActive) {
4846
EmptyView()
4947
}.hidden()
5048
}
51-
.onChange(of: isActive){
49+
.onChange(of: isActive) {
5250
if $0 == false { route = .empty }
5351
}
5452
}
55-
5653
}
5754

5855
// MARK: - Define routes
@@ -65,7 +62,7 @@ enum Router {
6562

6663
@ViewBuilder
6764
var builder: some View {
68-
switch(self) {
65+
switch self {
6966
case .go1: SubView(text: "go1")
7067
case .go2: SubView(text: "go2")
7168
case .go3: SubView(text: "go3")
@@ -77,16 +74,13 @@ enum Router {
7774
// MARK: - Define sub view
7875

7976
struct SubView: View {
80-
8177
let text: String
8278

8379
var body: some View {
8480
Text("\(text)")
8581
}
8682
}
8783

88-
89-
9084
struct ContentView_Previews: PreviewProvider {
9185
static var previews: some View {
9286
ContentView()

0 commit comments

Comments
 (0)