Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleve committed Mar 3, 2024
1 parent 1bc42a2 commit 0e03e66
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 9 deletions.
127 changes: 127 additions & 0 deletions ListableUI/Sources/CollectionView/CollectionView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//
// CollectionView.swift
// ListableUI
//
// Created by Kyle Van Essen on 11/29/23.
//

import Foundation


final class LSTCollectionView : UIView {

private let queue : ListChangesQueue

private(set) var content : Content

private var reuseCache : ReusableViewCache

private let view : ContentView

// MARK: Initialization

override init(frame: CGRect) {

self.queue = .init()
self.content = .empty
self.reuseCache = .init()
self.view = .init(frame: .init(origin: .zero, size: frame.size))

super.init(frame: frame)

self.addSubview(self.view)
}

// MARK: UIView

override func layoutSubviews() {
super.layoutSubviews()

self.view.frame = bounds
}

required init?(coder: NSCoder) { fatalError() }

func set(
content : Content,
changes: SectionedDiff<Section,
AnyIdentifier,
AnyItem,
AnyIdentifier>,
completion : @escaping () -> ()
) {
queue.add {

}
}

}

extension LSTCollectionView {
final class ContentView : UIScrollView {

}
}

open class LSTCollectionReusableView : UIView {

}

open class LSTCollectionSupplementaryView : LSTCollectionReusableView {

}

open class LSTCollectionItemView : LSTCollectionReusableView {

}


extension LSTCollectionView {

struct Content {

static var empty : Self {
fatalError()
}

var supplementaries : Supplementaries

var sections : [Section]
}

struct Section {
var supplementaries : Supplementaries

var items : [Item]
}

struct Item {
var value : AnyItem

var state : State

final class State {

}
}

struct Supplementaries {

private var byType : [ObjectIdentifier:Supplementary]

}

struct Supplementary {
var value : AnyHeaderFooter

var state : State

final class State {

}
}
}

protocol SupplementaryTypeKey {

}
16 changes: 7 additions & 9 deletions ListableUI/Sources/Internal/ReusableViewCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,32 @@ import Foundation

final class ReusableViewCache
{
private var views : [String:[AnyObject]] = [:]

init() {}
private var views : [AnyHashable:[AnyObject]] = [:]

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

return views.count
}

func push<Content,View:AnyObject>(_ view : View, with reuseIdentifier: ReuseIdentifier<Content>)
{
var views = self.views[reuseIdentifier.stringValue, default: []]
var views = self.views[reuseIdentifier, default: []]

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

views.append(view)

self.views[reuseIdentifier.stringValue] = views
self.views[reuseIdentifier] = views
}

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

if let view = views.popLast() {
self.views[reuseIdentifier.stringValue] = views
self.views[reuseIdentifier] = views
return view as! View
} else {
return create()
Expand All @@ -46,7 +44,7 @@ final class ReusableViewCache

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

if let view = views.last {
// Fast path: Already in the cache, just reference it here.
Expand Down
16 changes: 16 additions & 0 deletions ListableUI/Sources/ListView/ListView+FeatureFlag.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ListView+FeatureFlag.swift
// ListableUI
//
// Created by Kyle Van Essen on 11/29/23.
//

import Foundation


extension ListView {

public static let isNewBackingViewEnabled : Bool = {
UserDefaults.standard.bool(forKey: "Listable.isNewBackingViewEnabled")
}()
}

0 comments on commit 0e03e66

Please sign in to comment.