Skip to content

Commit e0a672f

Browse files
committed
Initial commit
1 parent 4c96b6b commit e0a672f

File tree

4 files changed

+151
-10
lines changed

4 files changed

+151
-10
lines changed

Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1320"
3+
LastUpgradeVersion = "1420"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
//
2+
// CollectionView.swift
3+
// ListableUI
4+
//
5+
// Created by Kyle Van Essen on 11/29/23.
6+
//
7+
8+
import Foundation
9+
10+
11+
final class LSTCollectionView : UIView {
12+
13+
private let queue : ListChangesQueue
14+
15+
private(set) var content : Content
16+
17+
private var reuseCache : ReusableViewCache
18+
19+
private let view : ContentView
20+
21+
// MARK: Initialization
22+
23+
override init(frame: CGRect) {
24+
25+
self.queue = .init()
26+
self.content = .empty
27+
self.reuseCache = .init()
28+
self.view = .init(frame: .init(origin: .zero, size: frame.size))
29+
30+
super.init(frame: frame)
31+
32+
self.addSubview(self.view)
33+
}
34+
35+
// MARK: UIView
36+
37+
override func layoutSubviews() {
38+
super.layoutSubviews()
39+
40+
self.view.frame = bounds
41+
}
42+
43+
required init?(coder: NSCoder) { fatalError() }
44+
45+
func set(
46+
content : Content,
47+
changes: SectionedDiff<Section,
48+
AnyIdentifier,
49+
AnyItem,
50+
AnyIdentifier>,
51+
completion : @escaping () -> ()
52+
) {
53+
queue.add {
54+
55+
}
56+
}
57+
58+
}
59+
60+
extension LSTCollectionView {
61+
final class ContentView : UIScrollView {
62+
63+
}
64+
}
65+
66+
open class LSTCollectionReusableView : UIView {
67+
68+
}
69+
70+
open class LSTCollectionSupplementaryView : LSTCollectionReusableView {
71+
72+
}
73+
74+
open class LSTCollectionItemView : LSTCollectionReusableView {
75+
76+
}
77+
78+
79+
extension LSTCollectionView {
80+
81+
struct Content {
82+
83+
static var empty : Self {
84+
fatalError()
85+
}
86+
87+
var supplementaries : Supplementaries
88+
89+
var sections : [Section]
90+
}
91+
92+
struct Section {
93+
var supplementaries : Supplementaries
94+
95+
var items : [Item]
96+
}
97+
98+
struct Item {
99+
var value : AnyItem
100+
101+
var state : State
102+
103+
final class State {
104+
105+
}
106+
}
107+
108+
struct Supplementaries {
109+
110+
private var byType : [ObjectIdentifier:Supplementary]
111+
112+
}
113+
114+
struct Supplementary {
115+
var value : AnyHeaderFooter
116+
117+
var state : State
118+
119+
final class State {
120+
121+
}
122+
}
123+
}
124+
125+
protocol SupplementaryTypeKey {
126+
127+
}

ListableUI/Sources/Internal/ReusableViewCache.swift

+7-9
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,32 @@ import Foundation
1010

1111
final class ReusableViewCache
1212
{
13-
private var views : [String:[AnyObject]] = [:]
14-
15-
init() {}
13+
private var views : [AnyHashable:[AnyObject]] = [:]
1614

1715
func count<Content>(for reuseIdentifier : ReuseIdentifier<Content>) -> Int
1816
{
19-
let views = self.views[reuseIdentifier.stringValue, default: []]
17+
let views = self.views[reuseIdentifier, default: []]
2018

2119
return views.count
2220
}
2321

2422
func push<Content,View:AnyObject>(_ view : View, with reuseIdentifier: ReuseIdentifier<Content>)
2523
{
26-
var views = self.views[reuseIdentifier.stringValue, default: []]
24+
var views = self.views[reuseIdentifier, default: []]
2725

2826
listableInternalPrecondition(views.contains { $0 === view } == false, "Cannot push a view which is already in the cache.")
2927

3028
views.append(view)
3129

32-
self.views[reuseIdentifier.stringValue] = views
30+
self.views[reuseIdentifier] = views
3331
}
3432

3533
func pop<Content,View:AnyObject>(with reuseIdentifier: ReuseIdentifier<Content>, _ create : () -> View) -> View
3634
{
37-
var views = self.views[reuseIdentifier.stringValue, default: []]
35+
var views = self.views[reuseIdentifier, default: []]
3836

3937
if let view = views.popLast() {
40-
self.views[reuseIdentifier.stringValue] = views
38+
self.views[reuseIdentifier] = views
4139
return view as! View
4240
} else {
4341
return create()
@@ -46,7 +44,7 @@ final class ReusableViewCache
4644

4745
func use<Content,View:AnyObject, Result>(with reuseIdentifier: ReuseIdentifier<Content>, create : () -> View, _ use : (View) -> Result) -> Result
4846
{
49-
let views = self.views[reuseIdentifier.stringValue, default: []]
47+
let views = self.views[reuseIdentifier, default: []]
5048

5149
if let view = views.last {
5250
// Fast path: Already in the cache, just reference it here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// ListView+FeatureFlag.swift
3+
// ListableUI
4+
//
5+
// Created by Kyle Van Essen on 11/29/23.
6+
//
7+
8+
import Foundation
9+
10+
11+
extension ListView {
12+
13+
public static let isNewBackingViewEnabled : Bool = {
14+
UserDefaults.standard.bool(forKey: "Listable.isNewBackingViewEnabled")
15+
}()
16+
}

0 commit comments

Comments
 (0)