Skip to content

Commit

Permalink
Add SPM updates and changes to the base (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif authored Jan 18, 2023
1 parent af8d44e commit 324307c
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 85 deletions.
16 changes: 8 additions & 8 deletions base/base.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
2937EB7629636BEB00BBC0E6 /* RegisterNetworking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2329636BEA00BBC0E6 /* RegisterNetworking.swift */; };
2937EB7729636BEB00BBC0E6 /* RegisterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2429636BEA00BBC0E6 /* RegisterViewModel.swift */; };
2937EB7829636BEB00BBC0E6 /* RegisterFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2529636BEA00BBC0E6 /* RegisterFields.swift */; };
2937EB7929636BEB00BBC0E6 /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2629636BEA00BBC0E6 /* LoginScreen.swift */; };
2937EB7929636BEB00BBC0E6 /* RegisterScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2629636BEA00BBC0E6 /* RegisterScreen.swift */; };
2937EB8029636BEB00BBC0E6 /* ImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB2F29636BEA00BBC0E6 /* ImageView.swift */; };
2937EB8129636BEB00BBC0E6 /* Taskable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB3129636BEA00BBC0E6 /* Taskable.swift */; };
2937EB8229636BEB00BBC0E6 /* Usable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2937EB3229636BEA00BBC0E6 /* Usable.swift */; };
Expand Down Expand Up @@ -92,7 +92,7 @@
2937EB2329636BEA00BBC0E6 /* RegisterNetworking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterNetworking.swift; sourceTree = "<group>"; };
2937EB2429636BEA00BBC0E6 /* RegisterViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterViewModel.swift; sourceTree = "<group>"; };
2937EB2529636BEA00BBC0E6 /* RegisterFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterFields.swift; sourceTree = "<group>"; };
2937EB2629636BEA00BBC0E6 /* LoginScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginScreen.swift; sourceTree = "<group>"; };
2937EB2629636BEA00BBC0E6 /* RegisterScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterScreen.swift; sourceTree = "<group>"; };
2937EB2F29636BEA00BBC0E6 /* ImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageView.swift; sourceTree = "<group>"; };
2937EB3129636BEA00BBC0E6 /* Taskable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Taskable.swift; sourceTree = "<group>"; };
2937EB3229636BEA00BBC0E6 /* Usable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Usable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -257,7 +257,7 @@
2937EB2229636BEA00BBC0E6 /* Register */,
2937EB1F29636BEA00BBC0E6 /* ProfileScreen.swift */,
2937EB2529636BEA00BBC0E6 /* RegisterFields.swift */,
2937EB2629636BEA00BBC0E6 /* LoginScreen.swift */,
2937EB2629636BEA00BBC0E6 /* RegisterScreen.swift */,
);
path = Profile;
sourceTree = "<group>";
Expand Down Expand Up @@ -657,7 +657,7 @@
2937EB8229636BEB00BBC0E6 /* Usable.swift in Sources */,
2937EB8D29636BEB00BBC0E6 /* ForwardNavigatable.swift in Sources */,
2937EB9529636BEB00BBC0E6 /* CartographyAlert.swift in Sources */,
2937EB7929636BEB00BBC0E6 /* LoginScreen.swift in Sources */,
2937EB7929636BEB00BBC0E6 /* RegisterScreen.swift in Sources */,
2937EB7029636BEB00BBC0E6 /* HomeScreen.swift in Sources */,
2937EBA729636BEB00BBC0E6 /* User.swift in Sources */,
2937EB9229636BEB00BBC0E6 /* AlertPresenting.swift in Sources */,
Expand Down Expand Up @@ -774,7 +774,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -828,7 +828,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -983,8 +983,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/0xOpenBytes/o";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.3.0;
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
2937EBC529636D1500BBC0E6 /* XCRemoteSwiftPackageReference "c" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/0xOpenBytes/c",
"state" : {
"revision" : "f24cc61b1ca4b72bcc690748232f254771e4d6a8",
"version" : "3.0.0"
"revision" : "e50c296ae2e0cdb9f5032534dfc8e590c7b0cfce",
"version" : "3.0.1"
}
},
{
Expand All @@ -23,17 +23,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/0xOpenBytes/o",
"state" : {
"revision" : "f0ef1e44a79443782f69b5dcab08bdadcb787faa",
"version" : "0.3.0"
"revision" : "7751d08c5db1c7e4f339289dce1e92b033114ffd",
"version" : "1.0.0"
}
},
{
"identity" : "t",
"kind" : "remoteSourceControl",
"location" : "https://github.com/0xOpenBytes/t",
"state" : {
"revision" : "78294df737c524f40267bca42beb8e10ca28aa41",
"version" : "0.2.0"
"revision" : "f4b8f43622a8b772d995210428dd2b3eb66904cd",
"version" : "1.0.1"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion base/base/App/Home/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ struct HomeScreen: View {
.padding()
}
)
Text("Hello, \(settings.user?.username ?? "World")!")
}
.navigationTitle("Hello, \(settings.user?.username ?? "World")!")
}
}

Expand Down
29 changes: 16 additions & 13 deletions base/base/App/Profile/ProfileScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@ struct ProfileScreen: View {
@ObservedObject var settings: AppSettings = AppSettings.shared

var body: some View {
if let user = settings.user {
VStack {
Text("Logged in: \(user.username)")
Group {
if let user = settings.user {
VStack {
Text("Logged in: \(user.username)")

Button(
"Logout",
role: .destructive,
action: { settings.user = nil }
Button(
"Logout",
role: .destructive,
action: { settings.user = nil }
)
}
} else {
RegisterScreen(
registerViewModel: RegisterViewModel(
registerNetworking: SuccessMockRegisterService() // TODO: (base-Template) Update to Production
)
)
}
} else {
LoginScreen(
registerViewModel: RegisterViewModel(
registerNetworking: SuccessMockRegisterService() // TODO: (base-Template) Update to Production
)
)
}
.navigationTitle("Profile")
}
}

Expand Down
8 changes: 4 additions & 4 deletions base/base/App/Profile/Register/RegisterViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ class RegisterViewModel: ObservableObject {
)

await MainActor.run {
AppSettings.shared.user = user
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
Navigation.path.toast(
title: "Success",
message: "You have successfully registered an account.",
style: .success
)
}

await MainActor.run {
AppSettings.shared.user = user
}
} catch {
handle(error: error)
}
Expand Down
2 changes: 1 addition & 1 deletion base/base/App/Profile/RegisterFields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct RegisterFields: View {
}
}

struct RegisterScreen_Previews: PreviewProvider {
struct RegisterFields_Previews: PreviewProvider {
static var previews: some View {
RegisterFields(
username: .constant(""),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// LoginScreen.swift
// RegisterScreen.swift
// base
//
// Created by Rob Maltese on 12/18/22.
//

import SwiftUI

struct LoginScreen: View {
struct RegisterScreen: View {
@ObservedObject var registerViewModel: RegisterViewModel

@FocusState var isFocused: Bool
Expand Down Expand Up @@ -57,9 +57,9 @@ struct LoginScreen: View {
}
}

struct LoginScreen_Previews: PreviewProvider {
struct RegisterScreen_Previews: PreviewProvider {
static var previews: some View {
LoginScreen(
RegisterScreen(
registerViewModel: RegisterViewModel(
registerNetworking: SuccessMockRegisterService()
)
Expand Down
51 changes: 27 additions & 24 deletions base/base/App/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,48 @@ struct RootView: View {
case profile
}

@ObservedObject var cartography: CartographyPath

@State private var selection: Tab = .home
@ObservedObject var navigation: Navigation

var body: some View {
CartographyView(path: cartography) {
TabView(selection: $selection) {
TabView(selection: $navigation.tab) {
CartographyView(path: navigation.home) {
HomeScreen()
.tag(Tab.home)
.tabItem {
Image(systemName: "house")
Text("Home")
}
}
.tag(Tab.home)
.tabItem {
Image(systemName: "house")
Text("Home")
}

CartographyView(path: navigation.search) {
SearchScreen()
.tag(Tab.search)
.tabItem {
Image(systemName: "magnifyingglass")
Text("Search")
}
}
.tag(Tab.search)
.tabItem {
Image(systemName: "magnifyingglass")
Text("Search")
}

CartographyView(path: navigation.profile) {
ProfileScreen()
.tag(Tab.profile)
.tabItem {
Image(systemName: "person")
Text("Profile")
}
}
.tag(Tab.profile)
.tabItem {
Image(systemName: "person")
Text("Profile")
}
}
}
}

struct RootView_Previews: PreviewProvider {
static var previews: some View {
Navigation.use { nav -> RootView in
nav.isPreview = true
nav.path = CartographyPath()
Navigation.shared.use { navigation -> RootView in
navigation.home = CartographyPath(id: "home.preview")
navigation.search = CartographyPath(id: "search.preview")
navigation.profile = CartographyPath(id: "profile.preview")

return RootView(cartography: Navigation.path)
return RootView(navigation: navigation)
}
}
}
1 change: 1 addition & 0 deletions base/base/App/Search/SearchScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct SearchScreen: View {
Text(date, format: .dateTime)
}
)
.navigationTitle("Search")
}
}

Expand Down
2 changes: 1 addition & 1 deletion base/base/App/Views/Components/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ImageViewModel: ObservableObject {

do {
guard
let data = try await Network.get(url: url).0,
let data = try await Network.get(url: url).data,
let imageData = UIImage(data: data)
else { return nil }

Expand Down
4 changes: 2 additions & 2 deletions base/base/App/baseApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import SwiftUI

@main
struct OBbaseApp: App {
let navigate: CartographyPath = Navigation.path
@ObservedObject var navigation: Navigation = Navigation.shared

var body: some Scene {
WindowGroup {
RootView(cartography: navigate)
RootView(navigation: navigation)
}
}
}
21 changes: 14 additions & 7 deletions base/base/Navigation/Implementation/CartographyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
import SwiftUI

class CartographyPath: ObservableObject {
private static let filename = "CartographyPath"
private static let filePrefix = "CartographyPath"

let id: String

@Published var navigation: NavigationPath
@Published var modal: CartographyModal?
@Published var alert: CartographyAlert?
@Published var actionSheet: CartographyActionSheet?
@Published var toast: CartographyToast?

init(_ codable: NavigationPath.CodableRepresentation? = nil) {
init(id: String, _ codable: NavigationPath.CodableRepresentation? = nil) {
self.id = id
if let codable {
navigation = NavigationPath(codable)
} else {
Expand All @@ -30,23 +33,27 @@ class CartographyPath: ObservableObject {

func save() {
guard
Navigation.isPreview == false,
Navigation.shared.isPreview == false,
let representation = navigation.codable
else { return }

do {
try Disk.out(representation, filename: Self.filename)
try Disk.out(representation, filename: Self.name(id: id))
} catch {
print(error.localizedDescription)
}
}

static func load() -> CartographyPath {
static func load(id: String) -> CartographyPath {
defer {
try? Disk.delete(filename: filename)
try? Disk.delete(filename: name(id: id))
}

return CartographyPath(try? Disk.in(filename: filename))
return CartographyPath(id: id, try? Disk.in(filename: name(id: id)))
}

static func name(id: String) -> String {
"\(filePrefix).\(id)"
}
}

Expand Down
3 changes: 1 addition & 2 deletions base/base/Navigation/Implementation/CartographyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ struct CartographyView<RootView: View>: View {

extension CartographyView {
static func preview(_ content: @escaping () -> RootView) -> CartographyView {
Navigation.isPreview = true
Navigation.path = CartographyPath()
Navigation.shared.isPreview = true

return CartographyView(path: Navigation.path, rootView: content)
}
Expand Down
7 changes: 2 additions & 5 deletions base/base/Navigation/Implementation/Toast/ToastModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import SwiftUI

/// This `ViewModifier` allows us to define the actual view modifier, its animation and interaction within the view.
/// This is built to be applied over any of the content shown, using `ZStack`.
struct ToastModifer: ViewModifier {
@Binding var toast: CartographyToast?
@State private var workItem: DispatchWorkItem?
Expand All @@ -17,9 +15,8 @@ struct ToastModifer: ViewModifier {
content
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay(
ZStack {
toastView()
}.animation(.spring(), value: toast)
toastView()
.animation(.spring(), value: toast)
)
.onChange(of: toast) { _ in
showToast()
Expand Down
Loading

0 comments on commit 324307c

Please sign in to comment.