-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleView.swift
106 lines (94 loc) · 2.1 KB
/
ExampleView.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// RSTabBar
//
// Created by Radu Ursache
//
import SwiftUI
import RSTabBar
struct ExampleView: View {
static let tabs = [
TabItem(index: 0, title: "Home", icon: "house", iconSelected: "house.fill"),
TabItem(index: 1, title: "Items", icon: "list.dash"),
TabItem(index: 2, title: "More", icon: "bolt.car")
]
@State var tabBarVisible: Bool = true
@State var tabs = DemoView.tabs
@State var selectedTab: TabItem = DemoView.tabs.first!
var body: some View {
RSTabBar(
tabs: $tabs,
selectedTab: $selectedTab,
tabBarVisible: $tabBarVisible,
tabBarShowSeparator: true,
tabBarBackgroundColor: .white.opacity(0.75),
tabBarSelectedItemColor: .red
) {
HStack {
Spacer()
VStack(spacing: 12) {
Text("First view")
.font(.title).bold()
.padding()
Button("\(tabBarVisible ? "Hide" : "Show") tab bar") {
tabBarVisible.toggle()
}
Button("Switch to random tab") {
selectedTab = self.tabs.randomElement()!
}
Spacer()
}
Spacer()
}
.background(Color(uiColor: .systemGroupedBackground))
.tag(self.tabs[0])
ListViewDemo(tabBarVisible: $tabBarVisible)
.tag(self.tabs[1])
Text("Third view")
.font(.title).bold()
.padding()
.tag(self.tabs[2])
}
}
}
struct ListViewDemo: View {
@Binding var tabBarVisible: Bool
var body: some View {
NavigationView {
List {
ForEach(0...50, id: \.self) { number in
NavigationLink {
List {
ForEach(50...100, id: \.self) { number in
NavigationLink {
Text("It works!")
} label: {
Text("\(number)")
}
}
}
.navigationTitle("2nd View")
.navigationBarTitleDisplayMode(.inline)
.onAppear {
tabBarVisible = false
}
} label: {
Text("\(number)")
}
}
}
.onAppear {
tabBarVisible = true
}
.navigationTitle("Large Title Here")
}
}
}
//struct ExampleView_Previews: PreviewProvider {
// static var previews: some View {
// ExampleView()
// .previewDevice("iPhone 8")
//
// ExampleView()
// .previewDevice("iPhone 12")
// }
//}