From 5cf978df69f83fea5252f0a720a05a65d296da81 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 12 Dec 2022 01:23:52 +0100 Subject: [PATCH] Implemented the showing of the Login and the Profile views from the ContentView view in the BeReal app target. --- BeReal.xcodeproj/project.pbxproj | 10 +++- BeReal/ContentView.swift | 49 ------------------- BeReal/UI/Views/ContentView.swift | 78 +++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 50 deletions(-) delete mode 100644 BeReal/ContentView.swift create mode 100644 BeReal/UI/Views/ContentView.swift diff --git a/BeReal.xcodeproj/project.pbxproj b/BeReal.xcodeproj/project.pbxproj index e849508..f0ad43e 100644 --- a/BeReal.xcodeproj/project.pbxproj +++ b/BeReal.xcodeproj/project.pbxproj @@ -86,6 +86,7 @@ isa = PBXGroup; children = ( 02659B162946AA2E00C3AD63 /* Enumerations */, + 02659B172946AA4400C3AD63 /* Views */, ); path = UI; sourceTree = ""; @@ -98,6 +99,14 @@ path = Enumerations; sourceTree = ""; }; + 02659B172946AA4400C3AD63 /* Views */ = { + isa = PBXGroup; + children = ( + 02AE64F029363DBF005A4AF3 /* ContentView.swift */, + ); + path = Views; + sourceTree = ""; + }; 02AE64E229363DBF005A4AF3 = { isa = PBXGroup; children = ( @@ -126,7 +135,6 @@ isa = PBXGroup; children = ( 02AE64EE29363DBF005A4AF3 /* BeRealApp.swift */, - 02AE64F029363DBF005A4AF3 /* ContentView.swift */, 02AE64F229363DC1005A4AF3 /* Assets.xcassets */, 02659B152946AA2700C3AD63 /* UI */, 02AE64F429363DC1005A4AF3 /* Preview Content */, diff --git a/BeReal/ContentView.swift b/BeReal/ContentView.swift deleted file mode 100644 index 2c544e1..0000000 --- a/BeReal/ContentView.swift +++ /dev/null @@ -1,49 +0,0 @@ -// -// 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: Body - - var body: some View { - NavigationView { - BrowseView() - } - .sheet(isPresented: showLogin) { - LoginView() - } - } - -} - -// MARK: - Helpers - -private extension ContentView { - var showLogin: Binding { - .init { account == nil } set: { _ in } - } -} - -// MARK: - Previews - -struct ContentView_Previews: PreviewProvider { - static var previews: some View { - ContentView() - } -} diff --git a/BeReal/UI/Views/ContentView.swift b/BeReal/UI/Views/ContentView.swift new file mode 100644 index 0000000..d8bbabd --- /dev/null +++ b/BeReal/UI/Views/ContentView.swift @@ -0,0 +1,78 @@ +// +// 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() + } +}