【SwiftUI】画面遷移の方法

# はじめに
SwiftUIで公式に提供されている画面遷移方法は3つあります。
① NavigationLink
② sheet
③ fullScreenCover

今回は上記の3つ + カスタム遷移を1つ紹介しようと思います。

# NavigationLink
![Videotogif.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/1eb773ae-9c64-b288-5ca5-6981747daf3f.gif)

```ContentView.swift
import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink("NavigationLink") {
                SubView()
            }
        }
    }
}
```
```SubView.swift
import SwiftUI

struct SubView: View {
    @Environment(\.dismiss) var dismiss
    var body: some View {
        ZStack {
            Color.yellow.edgesIgnoringSafeArea(.all)
            Button("閉じる") {
                dismiss()
            }
        }
    }
}
```

# Sheet
![Videotogif.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/1c88ee7d-ded6-fa4f-4ca7-80027a53ec20.gif)
```ContentView.swift
import SwiftUI

struct ContentView: View {
    @State var ShowSheet: Bool = false
    var body: some View {
        Button("Sheet") {
            ShowSheet.toggle()
        }
        .sheet(isPresented: $ShowSheet) {
            SubView()
        }
    }
}
```
```SubView.swift
import SwiftUI

struct SubView: View {
    @Environment(\.dismiss) var dismiss
    var body: some View {
        ZStack {
            Color.yellow.edgesIgnoringSafeArea(.all)
            Button("閉じる") {
                dismiss()
            }
        }
    }
}
```

# fullScreenCover
![Videotogif.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/705f2a11-d886-d98b-91b9-c0ed2b718f58.gif)
```ContentView.swift
import SwiftUI

struct ContentView: View {
    @State var ShowFullScreenCover: Bool = false
    var body: some View {
        Button("fullScreenCover") {
            ShowFullScreenCover.toggle()
        }
        .fullScreenCover(isPresented: $ShowFullScreenCover) {
            SubView()
        }
    }
}
```
```SubView.swift
import SwiftUI

struct SubView: View {
    @Environment(\.dismiss) var dismiss
    var body: some View {
        ZStack {
            Color.yellow.edgesIgnoringSafeArea(.all)
            Button("閉じる") {
                dismiss()
            }
        }
    }
}
```

# overlay
![Videotogif.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1745371/3fbfe2b7-2874-7a0d-9e00-98e07f82b286.gif)
```ContentView.swift
import SwiftUI

struct ContentView: View {
    @State var ShowViewOverlay: Bool = false
    var body: some View {
        NavigationView {
            Button("Overlay") {
                withAnimation {
                    ShowViewOverlay.toggle()
                }
            }
        }
        .overlay(
            SubView(ShowViewOverlay: $ShowViewOverlay)
        )
    }
}
```
```SubView.swift
import SwiftUI

struct SubView: View {
    @Binding var ShowViewOverlay: Bool
    var body: some View {
        if ShowViewOverlay {
            ZStack {
                Color.yellow.edgesIgnoringSafeArea(.all)
                Button("閉じる") {
                    withAnimation {
                        ShowViewOverlay.toggle()
                    }
                }
            }
        }
    }
}
```