Implemented the showing of the Login and the Profile views from the ContentView view in the BeReal app target.
This commit is contained in:
parent
5eb6164836
commit
5cf978df69
@ -86,6 +86,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
02659B162946AA2E00C3AD63 /* Enumerations */,
|
||||
02659B172946AA4400C3AD63 /* Views */,
|
||||
);
|
||||
path = UI;
|
||||
sourceTree = "<group>";
|
||||
@ -98,6 +99,14 @@
|
||||
path = Enumerations;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
02659B172946AA4400C3AD63 /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
02AE64F029363DBF005A4AF3 /* ContentView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
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 */,
|
||||
|
@ -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<Bool> {
|
||||
.init { account == nil } set: { _ in }
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
}
|
||||
}
|
78
BeReal/UI/Views/ContentView.swift
Normal file
78
BeReal/UI/Views/ContentView.swift
Normal file
@ -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()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user