-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigationViewContainer.swift
59 lines (49 loc) · 1.74 KB
/
NavigationViewContainer.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// NavigationViewContainer.swift
// SwiftUINavigation
//
// Created by Anna Zharkova on 06.09.2020.
// Copyright © 2020 Anna Zharkova. All rights reserved.
//
import Foundation
import SwiftUI
public enum Transition {
case none
case custom(AnyTransition)
}
public enum NavigationType {
case push
case pop
case popToRoot
}
public struct NavigationContainerView<Content>: View where Content: View&IItemView{
@ObservedObject private var viewModel: NavigationViewModel = NavigationViewModel.shared
private let animation: Animation = .easeOut(duration: 0.33)
private let content: NavigationItemContainer<Content>
private let transition: (push: AnyTransition, pop: AnyTransition)
public init(transition: Transition, @ViewBuilder content: @escaping () -> Content) {
self.content = NavigationItemContainer(content: content())
switch transition {
case .custom(let transition):
self.transition = (transition, transition)
case .none:
self.transition = (.identity, .identity)
}
}
public var body: some View {
let isRoot = viewModel.currentScreen == nil
return ZStack {
if isRoot {
content
// .environmentObject(self.viewModel)
.animation(self.animation)
.transition(viewModel.navigationType == .push ? transition.push : transition.pop)
} else {
viewModel.currentScreen?.screenView
//.environmentObject(viewModel)
.animation(self.animation)
.transition(viewModel.navigationType == .push ? transition.push : transition.pop)
}
}
}
}