Mercurial > public > lazybear
comparison LazyBear/ContentView.swift @ 449:4255f94d0767
Minor updates
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Wed, 23 Jun 2021 13:03:00 +0200 |
parents | 4effac4733b0 |
children | 37c13ebda381 |
comparison
equal
deleted
inserted
replaced
448:f71761f166f2 | 449:4255f94d0767 |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct ContentView: View { | 10 struct ContentView: View { |
11 @State private var showWelcome = false | 11 @State private var showWelcome = false |
12 @State var selectedView = 1 | 12 @State var selectedTab: Tab = .home |
13 @StateObject var hapticsManager = HapticsManager() | |
13 | 14 |
14 @Environment(\.managedObjectContext) private var moc | 15 @Environment(\.managedObjectContext) private var moc |
15 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) | 16 @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) |
16 var watchlistCompanies: FetchedResults<WatchlistCompany> | 17 var watchlistCompanies: FetchedResults<WatchlistCompany> |
17 | 18 |
18 var body: some View { | 19 var body: some View { |
19 TabView(selection: $selectedView) { | 20 TabView(selection: $selectedTab) { |
20 HomeView() | 21 HomeView() |
21 .tabItem { | 22 .tabItem { |
22 Image(systemName: "house") | 23 Image(systemName: "house") |
23 Text("Home") | 24 Text("Home") |
24 } | 25 } |
25 .tag(1) // Do not remove tags. It causes an odd behaviour when showView is activated | 26 .tag(Tab.home) /// Do not remove tags. It causes an odd behaviour when showView is activated |
26 SearchView() | 27 SearchView() |
27 .tabItem { | 28 .tabItem { |
28 Image(systemName: "magnifyingglass") | 29 Image(systemName: "magnifyingglass") |
29 Text("Search") | 30 Text("Search") |
30 } | 31 } |
31 .tag(2) | 32 .tag(Tab.search) |
32 ProfileView() | 33 ProfileView() |
33 .tabItem { | 34 .tabItem { |
34 Image(systemName: "person") | 35 Image(systemName: "person") |
35 Text("Profile") | 36 Text("Profile") |
36 } | 37 } |
37 .tag(3) | 38 .tag(Tab.profile) |
38 } | 39 } |
39 .onAppear { | 40 .onAppear { |
40 // isAppAlreadyLaunchedOnce() | 41 // isAppAlreadyLaunchedOnce() |
42 hapticsManager.prepareHaptics() | |
41 createDefaultWatchlist() | 43 createDefaultWatchlist() |
42 } | 44 } |
43 .sheet(isPresented: $showWelcome) { | 45 .sheet(isPresented: $showWelcome) { |
44 | 46 |
45 } | 47 } |
76 print(error.localizedDescription) | 78 print(error.localizedDescription) |
77 } | 79 } |
78 } | 80 } |
79 } | 81 } |
80 } | 82 } |
83 extension ContentView { | |
84 enum Tab: Hashable { | |
85 case home | |
86 case search | |
87 case profile | |
88 } | |
89 } | |
81 | 90 |
82 struct ContentView_Previews: PreviewProvider { | 91 struct ContentView_Previews: PreviewProvider { |
83 static var previews: some View { | 92 static var previews: some View { |
84 ContentView() | 93 ContentView() |
85 } | 94 } |