Skip to content

Commit 24a5a5c

Browse files
committed
Initial commit
1 parent 9280479 commit 24a5a5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+108927
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ playground.xcworkspace
4646
# you should judge for yourself, the pros and cons are mentioned at:
4747
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
4848
#
49-
# Pods/
49+
Pods/
50+
gen/
5051

5152
# Carthage
5253
#

Demo/AppDelegate.swift

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// AppDelegate.swift
3+
// Checkout
4+
//
5+
// Created by Kyle Van Essen on 6/14/19.
6+
// Copyright © 2019 Kyle Van Essen. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
import Blueprint
12+
import Listable
13+
import Dispatch
14+
15+
16+
@UIApplicationMain
17+
class AppDelegate: UIResponder, UIApplicationDelegate
18+
{
19+
var window: UIWindow?
20+
21+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
22+
23+
let window = UIWindow(frame: UIScreen.main.bounds)
24+
window.rootViewController = UINavigationController(rootViewController: DemosRootViewController())
25+
26+
self.window = window
27+
28+
window.makeKeyAndVisible()
29+
30+
return true
31+
}
32+
}
33+

Demo/Blueprint.swift

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
//
2+
// Blueprint.swift
3+
// Listable-DemoApp
4+
//
5+
// Created by Kyle Van Essen on 6/26/19.
6+
//
7+
8+
import Foundation
9+
10+
import Blueprint
11+
import BlueprintLayout
12+
import BlueprintCommonControls
13+
14+
15+
func Init<Value:Element>(_ value : Value, _ block : (inout Value) -> ()) -> Value
16+
{
17+
var value = value
18+
19+
block(&value)
20+
21+
return value
22+
}
23+
24+
public final class ElementView<DisplayedElement:Blueprint.Element> : UIView
25+
{
26+
public var element : DisplayedElement? {
27+
didSet {
28+
self.blueprintView.element = element
29+
}
30+
}
31+
32+
private let blueprintView : BlueprintView
33+
34+
public override convenience init(frame: CGRect)
35+
{
36+
self.init(frame: frame, element: nil)
37+
}
38+
39+
public init(frame: CGRect, element : DisplayedElement? = nil)
40+
{
41+
self.element = element
42+
43+
self.blueprintView = BlueprintView(element: self.element)
44+
45+
super.init(frame: frame)
46+
47+
self.addSubview(self.blueprintView)
48+
}
49+
50+
@available(*, unavailable)
51+
required init?(coder aDecoder: NSCoder) {
52+
fatalError()
53+
}
54+
55+
public override func layoutSubviews()
56+
{
57+
super.layoutSubviews()
58+
59+
self.blueprintView.frame = self.bounds
60+
}
61+
62+
public override func sizeThatFits(_ size: CGSize) -> CGSize
63+
{
64+
guard let element = self.element else {
65+
return .zero
66+
}
67+
68+
return element.measure(in: .init(size))
69+
}
70+
}
71+
72+
struct Square : ProxyElement
73+
{
74+
var box : Box
75+
var dimension : Dimension
76+
77+
enum Dimension {
78+
case horizontal
79+
case vertical
80+
}
81+
82+
public init(in dimension : Dimension, box : Box)
83+
{
84+
self.dimension = dimension
85+
self.box = box
86+
}
87+
88+
89+
var elementRepresentation: Element {
90+
return self.box
91+
}
92+
93+
func measure(in constraint: SizeConstraint) -> CGSize
94+
{
95+
switch self.dimension {
96+
case .horizontal:
97+
let value = constraint.width.maximum
98+
return CGSize(width: value, height: value)
99+
case .vertical:
100+
let value = constraint.height.maximum
101+
return CGSize(width: value, height: value)
102+
}
103+
}
104+
}
105+
106+
107+
struct UniformDistributionBox<Content:Element> : ProxyElement {
108+
var content : Content
109+
110+
init (_ content : Content)
111+
{
112+
self.content = content
113+
}
114+
115+
var elementRepresentation: Element {
116+
return self.content
117+
}
118+
119+
// Override measurement so we take the amount as provided by the row element.
120+
func measure(in constraint: SizeConstraint) -> CGSize {
121+
return CGSize(width: 0.0, height: 0.0)
122+
}
123+
}
124+
125+
extension Element {
126+
func uniformSize() -> UniformDistributionBox<Self> {
127+
return UniformDistributionBox(self)
128+
}
129+
}
130+
131+
struct Priority {
132+
var value : CGFloat
133+
134+
init(_ value : CGFloat) {
135+
self.value = value
136+
}
137+
138+
static var zeroPriority : Priority {
139+
return .init(0)
140+
}
141+
142+
static var defaultPriority : Priority {
143+
return .init(1.0)
144+
}
145+
}
146+
147+
extension Row
148+
{
149+
func scaleContentToFit() -> Row
150+
{
151+
var row = self
152+
153+
row.horizontalUnderflow = .growUniformly
154+
row.verticalAlignment = .fill
155+
156+
return row
157+
}
158+
}
159+
160+
extension Column
161+
{
162+
func scaleContentToFit() -> Column
163+
{
164+
var column = self
165+
166+
column.verticalUnderflow = .growUniformly
167+
column.horizontalAlignment = .fill
168+
169+
return column
170+
}
171+
}
172+
173+
extension StackElement
174+
{
175+
static func += (lhs : inout Self, rhs : Element)
176+
{
177+
lhs.add(child: rhs)
178+
}
179+
180+
static func += (lhs : inout Self, rhs : (growPriority:Priority, element:Element))
181+
{
182+
lhs.add(growPriority: rhs.growPriority.value, key: nil, child: rhs.element)
183+
}
184+
}

Demo/Bundle.swift

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Bundle.swift
3+
// Listable-DemoApp
4+
//
5+
// Created by Kyle Van Essen on 6/26/19.
6+
//
7+
8+
import Foundation
9+
10+
private class ListableDemoResourcesBundleFinderClass: NSObject {}
11+
12+
extension Bundle {
13+
static var ListableDemoResourcesBundle: Bundle {
14+
let mainBundle = Bundle(for: ListableDemoResourcesBundleFinderClass.self)
15+
16+
guard let bundleURL = mainBundle.url(forResource: "ListableDemoResources", withExtension: "bundle"),
17+
let bundle = Bundle(url: bundleURL) else {
18+
fatalError("Could not find resource bundle for ListableDemo within main application bundle.")
19+
}
20+
21+
return bundle
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// CollectionViewDemoFlowLayoutViewController.swift
3+
// Listable-DemoApp
4+
//
5+
// Created by Kyle Van Essen on 7/9/19.
6+
//
7+
8+
import Foundation
9+
import Listable
10+
11+
12+
final class CollectionViewDemoFlowLayoutViewController : UIViewController
13+
{
14+
let collectionView = CollectionView(layout: CollectionViewFlowLayout())
15+
16+
override func loadView()
17+
{
18+
self.view = self.collectionView
19+
20+
21+
}
22+
}

Demo/DemosRootViewController.swift

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// TableViewDemosRootViewController.swift
3+
// CheckoutApplet
4+
//
5+
// Created by Kyle Van Essen on 6/24/19.
6+
//
7+
8+
import UIKit
9+
10+
import Listable
11+
12+
13+
public final class DemosRootViewController : UIViewController
14+
{
15+
public struct State : Equatable {}
16+
17+
let tableView = TableView()
18+
19+
func push(_ viewController : UIViewController)
20+
{
21+
self.navigationController?.pushViewController(viewController, animated: true)
22+
}
23+
24+
override public func loadView()
25+
{
26+
self.title = "Demos"
27+
28+
self.view = self.tableView
29+
30+
self.tableView.setContent { table in
31+
table += TableView.Section(header: "Table Views") { rows in
32+
33+
rows += TableView.Row(
34+
SubtitleRow(
35+
text:"English Dictionary Search",
36+
detail: "Shows the Websters English dictionary, sectioned by letter."
37+
),
38+
onTap: { _ in
39+
self.push(TableViewDemosDictionaryViewController())
40+
})
41+
42+
rows += TableView.Row(
43+
SubtitleRow(
44+
text: "Random Sorter",
45+
detail: "Randomly resorts the content, with animation."),
46+
onTap: { _ in
47+
self.push(TableViewDemosRandomResortViewController())
48+
})
49+
50+
rows += TableView.Row(
51+
SubtitleRow(
52+
text: "Lorem Ipsum",
53+
detail: "Headers, footers, and cells showing varying amounts of ipsum to demonstrate sizing."),
54+
onTap: { _ in
55+
self.push(TableViewDemosIpsumViewController())
56+
})
57+
58+
rows += TableView.Row(
59+
SubtitleRow(
60+
text: "Bindings Demo",
61+
detail: "Shows how bindings work on table view cell."),
62+
onTap: { _ in
63+
self.push(TableViewDemosBindingsViewController())
64+
})
65+
66+
rows += TableView.Row(
67+
SubtitleRow(
68+
text: "SPOS Items List",
69+
detail: "Example of what the items library looks like in SPOS."),
70+
onTap: { _ in
71+
self.push(TableViewDemosSPOSItemsListViewController())
72+
})
73+
74+
rows += TableView.Row(
75+
SubtitleRow(
76+
text: "Transaction History",
77+
detail: "Example of what the transaction list looks like in SPOS, including load on scroll and pull to refresh."),
78+
onTap: { _ in
79+
self.push(TableViewDemosSPOSTransactionsListViewController())
80+
})
81+
82+
rows += TableView.Row(
83+
SubtitleRow(
84+
text: "Cart",
85+
detail: "Example of the cart view in Point of Sale."),
86+
onTap: { _ in
87+
self.push(TableViewDemosCartViewController())
88+
})
89+
}
90+
91+
table += TableView.Section(header: "Collection Views") { rows in
92+
rows += TableView.Row(
93+
SubtitleRow(
94+
text: "Flow Layout",
95+
detail: "Demo of flow layout wrapper."
96+
),
97+
onTap : { _ in
98+
self.push(CollectionViewDemoFlowLayoutViewController())
99+
})
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)