view ContentView.swift @ 0:668fd7e0d121

first commit
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Tue, 05 Jan 2021 16:43:09 +0000
parents
children 9f11c3e32bad
line wrap: on
line source

//
//  ContentView.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 27/09/2020.
//

import SwiftUI

struct ContentView: View {
    @State var searchedCompany: String = ""
    @State var showingSettings = false
    @State var showingUser = false
    @State public var showingSearch: Bool = false  // Search Bar
    
    var body: some View {
        VStack {
            if showingSearch == false {
                // Setting and user
                HStack {
                    Button(action: {self.showingSettings.toggle()}
                    ) {
                        Image(systemName: "gear")
                            .imageIconModifier()
                    }.sheet(isPresented: $showingSettings) {
                        About()
                    }
                    
                    Spacer()
                    
                    Button(action: {self.showingUser.toggle()
                    }) {
                        Image(systemName: "person")
                            .imageIconModifier()
                    }.sheet(isPresented: $showingUser) {
                        User()
                    }
                }
                .transition(.move(edge: .top))
                .animation(.default)
                .padding()
            }
            
            SearchBar(searchedText: $searchedCompany, placeholder: "Search ...", showingSearch: $showingSearch)
            
            if showingSearch == false {
                Companies()
                .transition(.move(edge: .bottom))
                .animation(.default)
                
                
            } else {
                if searchedCompany.count > 2 {
                    Spacer()
                    List {
                        ForEach(companiesData.filter({ searchedCompany.isEmpty ? true : $0.name.localizedStandardContains(searchedCompany) }), id: \.cik) { company in
                            CompanyRow(company: company)
                        }
                    }
                    .edgesIgnoringSafeArea(.bottom)
                    .cornerRadius(20)
                    .id(UUID())  // Increase speed in search the list
                }
                Spacer()
            }
        }
        .navigationBarHidden(true)
    }
}
extension Image {
    func imageIconModifier() -> some View {
        self
            .resizable()
            .aspectRatio(contentMode: .fit)
            .frame(maxWidth: 30)
    }
}
     

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationView {
            ContentView()
        }
        .navigationViewStyle(StackNavigationViewStyle())
    }
}