comparison LazyBear/ContentView.swift @ 296:b481783c32c0

Start version 4
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 21 Mar 2021 19:56:24 +0100
parents 22eba376075e
children 46dfb60e0874
comparison
equal deleted inserted replaced
295:50a2fb4a174e 296:b481783c32c0
1 // 1 //
2 // ContentView.swift 2 // ContentView.swift
3 // LazyBear 3 // LazyBear
4 // 4 //
5 // Created by Dennis Concepción Martín on 17/2/21. 5 // Created by Dennis Concepción Martín on 21/3/21.
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct ContentView: View { 10 struct ContentView: View {
11 @EnvironmentObject var hudManager: HudManager
12 @EnvironmentObject var deviceSize: DeviceSize
13 @EnvironmentObject var hapticsManager: HapticsManager
14
15 // Fetch user appearence settings
16 @FetchRequest(entity: UserSettings.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \UserSettings.changedAt, ascending: false)])
17 var userSettings: FetchedResults<UserSettings>
18
19 var body: some View { 11 var body: some View {
20 GeometryReader { geo in 12 Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
21 ZStack(alignment: .top) {
22 TabView {
23 // First view
24 Watchlist()
25 .tabItem {
26 Label("Watchlist", systemImage: "list.dash")
27 }
28
29 // First view
30 Search()
31 .tabItem {
32 Label("Search", systemImage: "magnifyingglass")
33 }
34
35 // First view
36 Settings()
37 .tabItem {
38 Label("Settings", systemImage: "gear")
39 }
40 }
41
42 // Show HUDs
43 // Notification
44 Notification(text: "Company saved", image: "checkmark.circle")
45 .offset(y: hudManager.showNotification ? 0 : -100)
46 .animation(.easeInOut)
47
48 // Action sheet
49 ZStack(alignment: .bottom) {
50 Color(.black)
51 .edgesIgnoringSafeArea(.all)
52 .opacity(hudManager.showAction ? 0.2: 0)
53 .animation(.easeInOut)
54 .onTapGesture { hudManager.showAction = false }
55
56 ActionView()
57 .offset(y: hudManager.showAction ? 0 : 250)
58 .animation(.easeInOut)
59 .padding()
60 }
61 }
62 .accentColor(Color("\(userSettings.first?.theme?.lowercased() ?? "default")Accent"))
63 // If this value is not optional it will cause a crash
64 .onAppear {
65 // Assign device screen size to the class
66 self.deviceSize.width = geo.size.width
67 self.deviceSize.height = geo.size.height
68 hapticsManager.prepareHaptics()
69 }
70 }
71 } 13 }
72 } 14 }
73
74 15
75 struct ContentView_Previews: PreviewProvider { 16 struct ContentView_Previews: PreviewProvider {
76 static var previews: some View { 17 static var previews: some View {
77 ContentView() 18 ContentView()
78 .environmentObject(HudManager())
79 } 19 }
80 } 20 }