diff 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
line wrap: on
line diff
--- a/LazyBear/ContentView.swift	Wed Jun 23 11:47:14 2021 +0200
+++ b/LazyBear/ContentView.swift	Wed Jun 23 13:03:00 2021 +0200
@@ -9,35 +9,37 @@
 
 struct ContentView: View {
     @State private var showWelcome = false
-    @State var selectedView = 1
+    @State var selectedTab: Tab = .home
+    @StateObject var hapticsManager = HapticsManager()
     
     @Environment(\.managedObjectContext) private var moc
     @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: [])
     var watchlistCompanies: FetchedResults<WatchlistCompany>
     
     var body: some View {
-        TabView(selection: $selectedView) {
+        TabView(selection: $selectedTab) {
             HomeView()
                 .tabItem {
                     Image(systemName: "house")
                     Text("Home")
                 }
-                .tag(1)  // Do not remove tags. It causes an odd behaviour when showView is activated
+                .tag(Tab.home)  /// Do not remove tags. It causes an odd behaviour when showView is activated
             SearchView()
                 .tabItem {
                     Image(systemName: "magnifyingglass")
                     Text("Search")
                 }
-                .tag(2)
+                .tag(Tab.search)
             ProfileView()
                 .tabItem {
                     Image(systemName: "person")
                     Text("Profile")
                 }
-                .tag(3)
+                .tag(Tab.profile)
         }
         .onAppear {
 //            isAppAlreadyLaunchedOnce()
+            hapticsManager.prepareHaptics()
             createDefaultWatchlist()
         }
         .sheet(isPresented: $showWelcome) {
@@ -78,6 +80,13 @@
         }
     }
 }
+extension ContentView {
+    enum Tab: Hashable {
+        case home
+        case search
+        case profile
+    }
+}
 
 struct ContentView_Previews: PreviewProvider {
     static var previews: some View {