Skip to content

Commit

Permalink
ListViewCell
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPodymov committed Oct 18, 2023
1 parent 6d72b39 commit f1ca1a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/CommonAppleKit/ListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import Foundation

public final class ListView<Cell: CACollectionViewCell>: CACollectionView, CACollectionViewDataSource {
public final class ListView<Cell: ListViewCell>: CACollectionView, CACollectionViewDataSource {
private let cellId: String

#if canImport(UIKit)
var content: [Any] = [] {
didSet {
Expand All @@ -18,6 +20,7 @@ public final class ListView<Cell: CACollectionViewCell>: CACollectionView, CACol
#endif

public init(frame: CGRect, itemSize: CGSize, cellId: String) {
self.cellId = cellId
let layout = CACollectionViewFlowLayout()
layout.itemSize = itemSize
#if canImport(AppKit)
Expand Down Expand Up @@ -48,7 +51,9 @@ public final class ListView<Cell: CACollectionViewCell>: CACollectionView, CACol
}
#elseif canImport(UIKit)
public func collectionView(_ collectionView: CACollectionView, cellForItemAt indexPath: IndexPath) -> CACollectionViewCell {
fatalError()
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
(cell as? ListViewCell)?.representedObject = content[indexPath.item]
return cell
}
#endif
}
13 changes: 13 additions & 0 deletions Sources/CommonAppleKit/ListViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ListViewCell.swift
// CommonAppleKit
//
// Created by Roman Podymov on 18/10/2023.
// Copyright © 2023 CommonAppleKit. All rights reserved.
//

import Foundation

open class ListViewCell: CACollectionViewCell {
open var representedObject: Any?
}

0 comments on commit f1ca1a6

Please sign in to comment.