Skip to content

Commit

Permalink
Default cellId
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPodymov committed Dec 14, 2023
1 parent 1dfa5dc commit 0d1a3cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Sources/CommonAppleKit/CAListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ open class CAListView<Cell: CAListViewCell<CellRootView>, CellRootView>: CAColle
}
#endif

public init(frame: CGRect, itemSize: CGSize, cellId: String) {
public init(frame: CGRect, itemSize: CGSize, cellId: String = String(describing: Cell.self)) {
self.cellId = cellId
let layout = CACollectionViewFlowLayout()
layout.itemSize = itemSize
Expand Down Expand Up @@ -57,7 +57,7 @@ open class CAListView<Cell: CAListViewCell<CellRootView>, CellRootView>: CAColle

public func collectionView(_ collectionView: CACollectionView, cellForItemAt indexPath: IndexPath) -> CACollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
(cell as? CAListViewCell)?.representedObject = content[indexPath.item]
(cell as? Cell)?.representedObject = content[indexPath.item]
return cell
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions Sources/CommonAppleKit/CAListViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import Foundation
open class CAListViewCell<RootView: CAView>: CACollectionViewCell {
public unowned var rootView: RootView!

open func createRootView() -> RootView {
RootView(frame: .zero)
open func createRootView(frame: CARect) -> RootView {
RootView(frame: frame)
}

#if canImport(AppKit)
open override func loadView() {
let rootView = createRootView()
let rootView = createRootView(frame: frame)
view = rootView
self.rootView = rootView
}
Expand All @@ -27,7 +27,7 @@ open class CAListViewCell<RootView: CAView>: CACollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)

let rootView = createRootView()
let rootView = createRootView(frame: frame)
contentView.addSubview(rootView)
self.rootView = rootView
rootView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true
Expand Down
2 changes: 1 addition & 1 deletion Tests/CommonAppleKitTests/CommonAppleKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ final class CommonAppleKitTests: XCTestCase {
}

func testScrollableListView() {
let listView = CAScrollableListView<CellA, CellARootView>(frame: .zero, itemSize: .init(width: 200, height: 100), cellId: "id")
let listView = CAScrollableListView<CellA, CellARootView>(frame: .zero, itemSize: .init(width: 200, height: 100))
listView.content = []
}
}
Expand Down

0 comments on commit 0d1a3cc

Please sign in to comment.