Mercurial > public > lazybear
changeset 246:35be981ccb31
Implementing CustomAction view
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Wed, 10 Mar 2021 21:19:28 +0100 |
parents | 14f2f6ea69f8 |
children | 2d7ad67a3e95 |
files | LazyBear/ContentView.swift LazyBear/HUDManager.swift LazyBear/UI/ActionView.swift LazyBear/UI/CompanyView.swift |
diffstat | 4 files changed, 111 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear/ContentView.swift Sun Mar 07 12:45:53 2021 +0100 +++ b/LazyBear/ContentView.swift Wed Mar 10 21:19:28 2021 +0100 @@ -9,7 +9,7 @@ struct ContentView: View { // Start ObservedObjects - @ObservedObject var hudManager = HUDManager() + @ObservedObject var hudManager = HudManager() // Fetch user appearence settings @FetchRequest(entity: UserSettings.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \UserSettings.changedAt, ascending: false)]) @@ -37,9 +37,23 @@ } } - HUD(text: hudManager.text, image: hudManager.image) - .offset(y: hudManager.isShowing ? 0 : -100) + Notification(text: "Company saved", image: "checkmark.circle") + .offset(y: hudManager.showNotification ? 0 : -100) .animation(.easeInOut) + + // Action sheet + ZStack(alignment: .bottom) { + Color(.gray) + .edgesIgnoringSafeArea(.all) + .opacity(hudManager.showAction ? 0.2: 0) + .animation(.easeInOut) + .onTapGesture { hudManager.showAction = false } + + ActionView() + .offset(y: hudManager.showAction ? 0 : 250) + .animation(.easeInOut) + .padding(.horizontal) + } } .accentColor(Color("\(userSettings.first?.theme?.lowercased() ?? "default")Accent")) // If this value is not optional it will cause a crash
--- a/LazyBear/HUDManager.swift Sun Mar 07 12:45:53 2021 +0100 +++ b/LazyBear/HUDManager.swift Wed Mar 10 21:19:28 2021 +0100 @@ -7,19 +7,24 @@ import SwiftUI -class HUDManager: ObservableObject { - var text = "Company saved" - var image = "checkmark.circle" - @Published var isShowing = false +enum HudType { + case notification, action +} + +class HudManager: ObservableObject { + @Published var showNotification = false + @Published var showAction = false - func show(text: String, image: String) { - self.text = text - self.image = image - self.isShowing = true - - // Dimiss after time - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { - self.isShowing = false + func selectHud(type: HudType) { + if type == .notification { + self.showNotification = true + + // Dimiss after time + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + self.showNotification = false + } + } else if type == .action { + self.showAction = true } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/UI/ActionView.swift Wed Mar 10 21:19:28 2021 +0100 @@ -0,0 +1,68 @@ +// +// ActionView.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 8/3/21. +// + +import SwiftUI + +struct ActionView: View { + + var body: some View { + VStack { + VStack { + Group { + Button(action: { }) { + Image(systemName: "chart.bar") + Text("Stock & news") + Spacer() + } + Divider() + .offset(x: 45) + + Button(action: { }) { + Image(systemName: "chart.pie") + Text("Insider transactions") + Spacer() + } + } + .modifier(Title()) + } + .padding() + .background( + Color(.white) + .cornerRadius(20) + ) + + Button(action: { }) { + Spacer() + Text("Cancel") + Spacer() + } + .modifier(Title()) + .padding(.vertical) + .background( + Color(.white) + .cornerRadius(20) + ) + } + .frame(maxWidth: 600) + } +} + + +struct ActionView_Previews: PreviewProvider { + static var previews: some View { + ActionView() + } +} + +struct Title: ViewModifier { + func body(content: Content) -> some View { + content + .font(.title3) + .imageScale(.large) + .frame(maxWidth: .infinity) + } +}
--- a/LazyBear/UI/CompanyView.swift Sun Mar 07 12:45:53 2021 +0100 +++ b/LazyBear/UI/CompanyView.swift Wed Mar 10 21:19:28 2021 +0100 @@ -15,11 +15,10 @@ var name: String var symbol: String - @ObservedObject var hudManager: HUDManager + @ObservedObject var hudManager: HudManager @FetchRequest(entity: Company.entity(), sortDescriptors: []) var companies: FetchedResults<Company> @Environment(\.managedObjectContext) private var moc - - @State private var showingAction = false + @State var viewState = ViewType.stock var body: some View { @@ -31,20 +30,15 @@ NewsView(symbol: symbol) } else if viewState == .insiders { - InsiderSum(symbol: symbol) - InsiderTrans(symbol: symbol) + InsiderSummary(symbol: symbol) + InsiderTransactions(symbol: symbol) } } } .toolbar { ToolbarItem(placement: .principal) { - Button(action: { self.showingAction = true }) { - if viewState == .stock { - Text("Stock") - } else if viewState == .insiders { - Text("Insiders") - } - Image(systemName: "chevron.down") + Button(action: { self.hudManager.showAction.toggle() }) { + Text("Test") } } @@ -58,13 +52,6 @@ } } } - .actionSheet(isPresented: $showingAction) { - ActionSheet(title: Text("Select an option"), buttons: [ - .default(Text("Stock & news")) { self.viewState = ViewType.stock }, - .default(Text("Insiders")) { self.viewState = ViewType.insiders }, - .cancel() - ]) - } } // Add to watchlist @@ -75,7 +62,7 @@ company.name = name do { try moc.save() - hudManager.show(text: "Company saved", image: "checkmark.circle") + hudManager.selectHud(type: .notification) generator.notificationOccurred(.success) print("Company saved.") } catch { @@ -87,7 +74,8 @@ struct CompanyView_Previews: PreviewProvider { static var previews: some View { NavigationView { - CompanyView(name: "apple inc", symbol: "aapl", hudManager: HUDManager()) + CompanyView(name: "apple inc", symbol: "aapl", hudManager: HudManager()) + .navigationTitle("APPL") } .navigationViewStyle(StackNavigationViewStyle()) }