Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,4 @@ struct VerticalLayoutItemComponent: Component {
func render(in content: VerticalLayoutItemView, coordinator: ()) {
content.viewModel = viewModel
}

var layoutMode: ContentLayoutMode {
.flexibleHeight(estimatedHeight: 54.0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@ final class VerticalLayoutListView: UIView {
)
}
}
.withSectionLayout(.vertical)
.withSectionLayout { context in
let size = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(44.0)
)
let item = NSCollectionLayoutItem(
layoutSize: size
)
let group = NSCollectionLayoutGroup.vertical(
layoutSize: size,
subitems: [item]
)

return NSCollectionLayoutSection(group: group)
}
}.onRefresh { [weak self] _ in
self?.resetViewModels()
}.onReachEnd(offsetFromEnd: .relativeToContainerSize(multiplier: 1.0)) { [weak self] _ in
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ struct ButtonComponent: Component {
func render(in content: Button, coordinator: Coordinator) {
content.configure(viewModel: viewModel)
}

var layoutMode: ContentLayoutMode {
.flexibleHeight(estimatedHeight: 44.0)
}
}
```

Expand Down Expand Up @@ -114,7 +110,20 @@ let list = List {
}
.withHeader(ButtonComponent(viewModel: .init(title: "Header")))
.withFooter(ButtonComponent(viewModel: .init(title: "Footer")))
.withSectionLayout(.vertical(spacing: 12.0))
.withSectionLayout { context in
let size = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(44.0)
)
let item = NSCollectionLayoutItem(
layoutSize: size
)
let group = NSCollectionLayoutGroup.vertical(
layoutSize: size,
subitems: [item]
)
return NSCollectionLayoutSection(group: group)
}
}

collectionViewAdapter.apply(
Expand Down Expand Up @@ -147,9 +156,6 @@ The size of a View is actually adjusted when the View is displayed on the screen
struct ButtonComponent: Component {
typealias Content = Button
// ...
var layoutMode: ContentLayoutMode {
.flexibleHeight(estimatedHeight: 44.0)
}
}

final class Button: UIControl {
Expand Down
24 changes: 0 additions & 24 deletions Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ final public class CollectionViewAdapter: NSObject {
completion: (() -> Void)?
)?

private var componentSizeStorage: ComponentSizeStorage = ComponentSizeStorageImpl()

var list: List?

private lazy var pullToRefreshControl: UIRefreshControl = {
Expand Down Expand Up @@ -351,10 +349,6 @@ extension CollectionViewAdapter: CollectionViewLayoutAdapterDataSource {
public func sectionItem(at index: Int) -> Section? {
list?.sections[safe: index]
}

public func sizeStorage() -> ComponentSizeStorage {
componentSizeStorage
}
}

// MARK: - UICollectionViewDelegate
Expand Down Expand Up @@ -697,12 +691,6 @@ extension CollectionViewAdapter: UICollectionViewDataSource {
return UICollectionViewCell()
}

cell.onSizeChanged = { [weak self] size in
self?.componentSizeStorage.setCellSize(
(size, item.component.viewModel),
for: item.id
)
}
cell.cancellables = prefetchingIndexPathOperations.removeValue(forKey: indexPath)
cell.render(component: item.component)

Expand Down Expand Up @@ -731,12 +719,6 @@ extension CollectionViewAdapter: UICollectionViewDataSource {
return UICollectionReusableView()
}

headerView.onSizeChanged = { [weak self] size in
self?.componentSizeStorage.setHeaderSize(
(size, header.component.viewModel),
for: section.id
)
}
headerView.render(component: header.component)

return headerView
Expand All @@ -757,12 +739,6 @@ extension CollectionViewAdapter: UICollectionViewDataSource {
return UICollectionReusableView()
}

footerView.onSizeChanged = { [weak self] size in
self?.componentSizeStorage.setFooterSize(
(size, footer.component.viewModel),
for: section.id
)
}
footerView.render(component: footer.component)

return footerView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public protocol CollectionViewLayoutAdapterDataSource: AnyObject {
/// - Parameter index: The index of the section to return.
/// - Returns: The section at the index.
func sectionItem(at index: Int) -> Section?

/// Returns the ComponentSizeStorage that managing the cached size information.
/// - Returns: The ComponentSizeStorage that managing the cached size information.
func sizeStorage() -> ComponentSizeStorage
}

/// The `CollectionViewLayoutAdaptable` interface serves as an adapter between the UICollectionViewCompositionalLayout logic and the `KarrotListKit` layout logic
Expand Down Expand Up @@ -83,8 +79,7 @@ public class CollectionViewLayoutAdapter: CollectionViewLayoutAdaptable {

return sectionItem.layout(
index: index,
environment: environment,
sizeStorage: dataSource.sizeStorage()
environment: environment
)
}
}
81 changes: 0 additions & 81 deletions Sources/KarrotListKit/Adapter/ComponentSizeStorage.swift

This file was deleted.

10 changes: 0 additions & 10 deletions Sources/KarrotListKit/Component/AnyComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ public struct AnyComponent: Component, Equatable {
box.base
}

/// The layout mode of the component's content.
public var layoutMode: ContentLayoutMode {
box.layoutMode
}

/// A reuse identifier for the component.
public var reuseIdentifier: String {
box.reuseIdentifier
Expand Down Expand Up @@ -116,7 +111,6 @@ private protocol ComponentBox {

var base: Base { get }
var reuseIdentifier: String { get }
var layoutMode: ContentLayoutMode { get }
var viewModel: Base.ViewModel { get }

func renderContent(coordinator: Any) -> UIView
Expand All @@ -135,10 +129,6 @@ private struct AnyComponentBox<Base: Component>: ComponentBox {
baseComponent.viewModel
}

var layoutMode: ContentLayoutMode {
baseComponent.layoutMode
}

var baseComponent: Base

var base: Base {
Expand Down
3 changes: 0 additions & 3 deletions Sources/KarrotListKit/Component/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public protocol Component {
/// A reuse identifier for the component.
var reuseIdentifier: String { get }

/// The layout mode of the component's content.
var layoutMode: ContentLayoutMode { get }

/// Creates the content object and configures its initial state.
///
/// - Parameter coordinator: The coordinator to use for rendering the content.
Expand Down
30 changes: 0 additions & 30 deletions Sources/KarrotListKit/Component/ContentLayoutMode.swift

This file was deleted.

Loading