Skip to content
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
25 changes: 25 additions & 0 deletions ListKit.xcodeproj/ListKitTests_Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
25 changes: 25 additions & 0 deletions ListKit.xcodeproj/ListKit_Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
682 changes: 682 additions & 0 deletions ListKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
<false/>
</dict>
</plist>
68 changes: 68 additions & 0 deletions ListKit.xcodeproj/xcshareddata/xcschemes/ListKit-Package.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "9999"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ListKit::ListKit"
BuildableName = "ListKit.framework"
BlueprintName = "ListKit"
ReferencedContainer = "container:ListKit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ListKit::ListKitTests"
BuildableName = "ListKitTests.xctest"
BlueprintName = "ListKitTests"
ReferencedContainer = "container:ListKit.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ ListKit only support Swift Package Manager.

```swift
dependencies: [
.package(url: "https://github.com/ReactComponentKit/ListKit.git", from: "1.0.0"),
.package(url: "https://github.com/ReactComponentKit/ListKit.git", from: "1.1.0"),
]
```

Expand Down Expand Up @@ -394,6 +394,10 @@ dependencies: [
- The amount of space added around the content of the component to adjust its final size after its position is computed.
- `func supplementComponents() -> [AnySupplementaryComponent]`
- An array of the supplementary items attached to the component.
- `func willDisplay(content: Content)`
- Component's content is about to be displayed in the collection view.
- `func didEndDisplay(content: Content)`
- Component's content was removed from the collection view.
- `func render(in content: Content)`
- Render data to component's content view

Expand Down
24 changes: 24 additions & 0 deletions Sources/ListKit/Common/ComponentQueryable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ComponentQueryable.swift
// ListKit
//
// Created by burt on 2021/09/19.
//
import UIKit

public protocol ComponentQueryable: ComposeLayoutProvider {
/// Query AnyComponent at IndexPath
func anyComponent(at indexPath: IndexPath) -> AnyComponent?
/// Query AnyComponent at IndexPath and casting it to T type if exists
func component<T>(at indexPath: IndexPath, to: T.Type) -> T?
}

extension ComponentQueryable {
public func anyComponent(at indexPath: IndexPath) -> AnyComponent? {
return self.layout?.sections[indexPath.section].components[indexPath.item].component
}

public func component<T>(at indexPath: IndexPath, to type: T.Type) -> T? {
return self.layout?.sections[indexPath.section].components[indexPath.item].component.to(type)
}
}
12 changes: 12 additions & 0 deletions Sources/ListKit/Common/ComposeLayoutProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// ComposeLayoutProvider.swift
// ListKit
//
// Created by burt on 2021/09/19.
//
import Foundation

public protocol ComposeLayoutProvider {
/// UICollectionView's current compose layout
var layout: ComposeLayout? { get set }
}
25 changes: 0 additions & 25 deletions Sources/ListKit/DataSource/DataSource.swift

This file was deleted.

10 changes: 5 additions & 5 deletions Sources/ListKit/DataSource/DiffableDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

open class DiffableDataSource: DataSource {
open class DiffableDataSource: ListKitDataSource {
public var layout: ComposeLayout?
public weak var collectionView: UICollectionView?
private var dataSource: UICollectionViewDiffableDataSource<Section, AnyComponent>?
Expand All @@ -22,8 +22,8 @@ open class DiffableDataSource: DataSource {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ListKitCell.className, for: indexPath)
self?.configure(cell: cell)
if let wrapper = self?.layout?.sections[indexPath.section].components[indexPath.item], let contentView = wrapper.component.contentView() as? UIView {
cell.contentView.viewWithTag(Int.max)?.removeFromSuperview()
contentView.tag = Int.max
cell.contentView.viewWithTag(ListKit.componentContentViewTag)?.removeFromSuperview()
contentView.tag = ListKit.componentContentViewTag
cell.contentView.addSubview(contentView)

contentView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -45,8 +45,8 @@ open class DiffableDataSource: DataSource {
let view = collectionView.dequeueReusableSupplementaryView(ofKind: ListKitReusableView.className, withReuseIdentifier: ListKitReusableView.className, for: indexPath)
if let anySupplementaryComponent = SupplementaryComponentManager.shared[kind], let contentView = anySupplementaryComponent.contentView() as? UIView {

view.viewWithTag(Int.max)?.removeFromSuperview()
contentView.tag = Int.max
view.viewWithTag(ListKit.componentContentViewTag)?.removeFromSuperview()
contentView.tag = ListKit.componentContentViewTag
view.addSubview(contentView)

contentView.translatesAutoresizingMaskIntoConstraints = false
Expand Down
15 changes: 15 additions & 0 deletions Sources/ListKit/DataSource/ListKitDataSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// DataSource.swift
// ListKit
//
// Created by burt on 2021/09/11.
//

import UIKit

public protocol ListKitDataSource: ComponentQueryable {
/// UICollectionView that uses this DataSource
var collectionView: UICollectionView? { get set }
/// Configure UICollectionViewCell if needed
func configure(cell: UICollectionViewCell)
}
10 changes: 5 additions & 5 deletions Sources/ListKit/DataSource/PlainDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

open class PlainDataSource: NSObject, DataSource, UICollectionViewDataSource {
open class PlainDataSource: NSObject, ListKitDataSource, UICollectionViewDataSource {
public var layout: ComposeLayout?
public weak var collectionView: UICollectionView?

Expand All @@ -25,8 +25,8 @@ open class PlainDataSource: NSObject, DataSource, UICollectionViewDataSource {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ListKitCell.className, for: indexPath)
configure(cell: cell)
if let wrapper = layout?.sections[indexPath.section].components[indexPath.item], let contentView = wrapper.component.contentView() as? UIView {
cell.contentView.viewWithTag(Int.max)?.removeFromSuperview()
contentView.tag = Int.max
cell.contentView.viewWithTag(ListKit.componentContentViewTag)?.removeFromSuperview()
contentView.tag = ListKit.componentContentViewTag
cell.contentView.addSubview(contentView)

contentView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -48,8 +48,8 @@ open class PlainDataSource: NSObject, DataSource, UICollectionViewDataSource {
let view = collectionView.dequeueReusableSupplementaryView(ofKind: ListKitReusableView.className, withReuseIdentifier: ListKitReusableView.className, for: indexPath)
if let anySupplementaryComponent = SupplementaryComponentManager.shared[kind], let contentView = anySupplementaryComponent.contentView() as? UIView {

view.viewWithTag(Int.max)?.removeFromSuperview()
contentView.tag = Int.max
view.viewWithTag(ListKit.componentContentViewTag)?.removeFromSuperview()
contentView.tag = ListKit.componentContentViewTag
view.addSubview(contentView)

contentView.translatesAutoresizingMaskIntoConstraints = false
Expand Down
24 changes: 24 additions & 0 deletions Sources/ListKit/Delegate/ComponentLifeTimeTrackingDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ComponentLifeTimeTrackingDelegate.swift
// ListKit
//
// Created by burt on 2021/09/19.
//

import UIKit

open class ComponentLifeTimeTrackingDelegate: NSObject, ListKitDelegate, UICollectionViewDelegate {
public var layout: ComposeLayout?

open func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if let component = anyComponent(at: indexPath), let contentView = cell.contentView.viewWithTag(ListKit.componentContentViewTag) {
component.willDisplay(content: contentView)
}
}

open func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if let component = anyComponent(at: indexPath), let contentView = cell.contentView.viewWithTag(ListKit.componentContentViewTag) {
component.didEndDisplay(content: contentView)
}
}
}
12 changes: 12 additions & 0 deletions Sources/ListKit/Delegate/ListKitDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// ListKitDelegate.swift
// ListKit
//
// Created by burt on 2021/09/19.
//

import Foundation

public protocol ListKitDelegate: ComponentQueryable {

}
10 changes: 10 additions & 0 deletions Sources/ListKit/Layout/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public protocol Component: NSCollectionLayoutItemsConvertible, Hashable {
func contentInsets() -> NSDirectionalEdgeInsets
/// An array of the supplementary items attached to the component.
func supplementComponents() -> [AnySupplementaryComponent]
/// Component's content is about to be displayed in the collection view.
func willDisplay(content: Content)
/// Component's content was removed from the collection view.
func didEndDisplay(content: Content)
/// Render data to component's content view
func render(in content: Content)
}
Expand Down Expand Up @@ -52,6 +56,12 @@ extension Component {
return []
}

public func willDisplay(content: Content) {
}

public func didEndDisplay(content: Content) {
}

public func toNSCollectionLayoutItems() -> [NSCollectionLayoutItem] {
let registerable = supplementComponents()
registerable.forEach { SupplementaryComponentManager.shared.append($0) }
Expand Down
8 changes: 7 additions & 1 deletion Sources/ListKit/ListKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
// ListKit
//
// Created by burt on 2021/09/16.
//
//

import Foundation

public enum ListKit {
public static let componentContentViewTag = Int.max
}
Loading