Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - BusinessListView #11

Merged
merged 6 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Example/GenythingExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
03BA41372742E37300B97AA6 /* Genything in Frameworks */ = {isa = PBXBuildFile; productRef = 03BA41362742E37300B97AA6 /* Genything */; };
03BA41392742E37300B97AA6 /* Trickery in Frameworks */ = {isa = PBXBuildFile; productRef = 03BA41382742E37300B97AA6 /* Trickery */; };
770849362742EA250044E19E /* PhoneBook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 770849352742EA250044E19E /* PhoneBook.swift */; };
777912A727456B9400C92173 /* BusinessListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777912A627456B9400C92173 /* BusinessListView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -37,6 +38,7 @@
03BA41152742DED000B97AA6 /* GenythingExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenythingExampleTests.swift; sourceTree = "<group>"; };
03BA41302742DFAE00B97AA6 /* Genything */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Genything; path = ..; sourceTree = "<group>"; };
770849352742EA250044E19E /* PhoneBook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneBook.swift; sourceTree = "<group>"; };
777912A627456B9400C92173 /* BusinessListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BusinessListView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -125,6 +127,7 @@
770849372742EC8E0044E19E /* Pages */ = {
isa = PBXGroup;
children = (
777912A627456B9400C92173 /* BusinessListView.swift */,
770849352742EA250044E19E /* PhoneBook.swift */,
);
path = Pages;
Expand Down Expand Up @@ -234,6 +237,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
777912A727456B9400C92173 /* BusinessListView.swift in Sources */,
770849362742EA250044E19E /* PhoneBook.swift in Sources */,
03BA41072742DECD00B97AA6 /* IndexView.swift in Sources */,
03BA41052742DECD00B97AA6 /* GenythingExampleApp.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion Example/GenythingExample/IndexView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Trickery

private enum Destination: String, CaseIterable, Identifiable {
case phoneBook
case businessList

var id: String {
rawValue
Expand All @@ -20,7 +21,8 @@ struct IndexView: View {
ForEach(Destination.allCases) { destination in
NavigationLink(destination: {
switch destination {
case .phoneBook: PhoneBook()
case .phoneBook: PhoneBook()
case .businessList: BusinessListView()
}
}) {
Text(destination.title)
Expand Down
75 changes: 75 additions & 0 deletions Example/GenythingExample/Pages/BusinessListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import SwiftUI
import Trickery
import Genything

struct BusinessCard: Identifiable {
let id: UUID = UUID()
let name: String
let email: String
let symbolName: String
let addressLine1: String
let addressLine2: String
}

struct BusinessListCell: View {
let businessCard: BusinessCard

var body: some View {
HStack(alignment: .top) {
Image(systemName: businessCard.symbolName)
.resizable()
.frame(width: 50, height: 50)
.foregroundColor(.orange)
.padding()

VStack(alignment: .leading, spacing: 5) {
Text(businessCard.name)
.font(.title)
.foregroundColor(.orange)
Text(businessCard.email)
.font(.caption2)
.bold()
.foregroundColor(.blue)
VStack(alignment: .leading) {
Text(businessCard.addressLine1)
.font(.subheadline)
Text(businessCard.addressLine2)
.font(.subheadline)
}
}
Spacer()
}
}
}

struct BusinessListView: View {
let data = Gen<BusinessCard> { ctx in
let addressLine2Gen = Gen<String>.one(of: [
Fake.Addresses.caLastLine,
Fake.Addresses.usLastLine
])

return BusinessCard(
name: Fake.BusinessNames.any.generate(context: ctx),
email: "[email protected]",
symbolName: "circle.fill",
addressLine1: Fake.Addresses.streetLine.generate(context: ctx),
addressLine2: addressLine2Gen.generate(context: ctx)
)
}.take(count: 50)

var body: some View {
List {
ForEach(data){ businessCard in
BusinessListCell(businessCard: businessCard)
}
}
.navigationTitle("Business Cards")
}
}

struct BusinessListView_Previews: PreviewProvider {
static var previews: some View {
BusinessListView()
}
}
1 change: 1 addition & 0 deletions Example/GenythingExample/Pages/PhoneBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct PhoneBookCell: View {
}
}
}

struct PhoneBook: View {
let data = Gen.zip(Fake.PersonNames.full, Fake.PhoneNumbers.formatted) {Contact(name: $0, phoneNumber: $1)}.samples(count: 50)

Expand Down
1 change: 0 additions & 1 deletion Sources/Trickery/ResourceHelper/DataResourceCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extension JsonResourceCodable {
}

static func loadJson() -> Self {

getBundle()
.url(forResource: String(describing: self),
withExtension: "json")
Expand Down