// // ContentView.swift // BeReal // // Created by Javier Cicchelli on 29/11/2022. // Copyright © 2022 Röck+Cöde. All rights reserved. // import Browse import DataModels import Login import KeychainStorage import Profile import SwiftUI struct ContentView: View { // MARK: Storages @KeychainStorage(key: .KeychainStorage.account) private var account: Account? // MARK: States @State private var user: User? @State private var showSheet: SheetView? // MARK: Body var body: some View { NavigationView { BrowseView { // ... } uploadFile: { // ... } showProfile: { showSheet = .profile } } .onAppear { shouldShowLogin() } .onChange(of: account) { _ in shouldShowLogin() } .sheet(item: $showSheet) { sheet in switch sheet { case .login: LoginView { account = $0 user = $1 } case .profile: ProfileView { account = nil } } } } } // MARK: - Helpers private extension ContentView { func shouldShowLogin() { showSheet = account == nil ? .login : nil } } // MARK: - Previews struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }