view LazyBear/Views/Company/CompanyView.swift @ 415:34f9e408b861

Minor UI Updates and tests
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 09 Jun 2021 12:49:17 +0200
parents c804ce7a1560
children 5f21f7c23c5e
line wrap: on
line source

//
//  CompanyView.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 8/5/21.
//

import SwiftUI
import StockCharts

struct CompanyView: View {
    var symbol: String
    
    @ObservedObject var company = Company()
    @State private var showViewSelector = false
    
    // Views
    @State private var showChartView = true
    @State private var showInsiderView = false
    
    var body: some View {
        ScrollView {
            VStack {
                CompanyHeader(symbol: symbol, showViewSelector: $showViewSelector)
                    .padding(.bottom)
                
                // Chart View
                if showChartView {
                    Chart(company: company, symbol: symbol)
                } else if showInsiderView {
                    Insiders(company: company, symbol: symbol)
                }
            }
            .padding()
        }
        .actionSheet(isPresented: $showViewSelector) {
            ActionSheet(title: Text("Select an option"), buttons: [
                .default(Text("Chart & News")) { resetViews(); showChartView = true },
                .default(Text("Insiders")) { resetViews(); showInsiderView = true },
                .cancel()
            ])
        }
    }
    
    /*
     Hide all views to show later the one tapped
     */
    private func resetViews() {
        showChartView = false
        showInsiderView = false
    }
}

struct CompanyView_Previews: PreviewProvider {
    static var previews: some View {
        CompanyView(symbol: "AAPL")
    }
}