diff --git a/Sources/CommonAppleKit/CAListView.swift b/Sources/CommonAppleKit/CAListView.swift index fbcf2b7..bba71d0 100644 --- a/Sources/CommonAppleKit/CAListView.swift +++ b/Sources/CommonAppleKit/CAListView.swift @@ -30,11 +30,20 @@ open class CAListView, CellRootView, CellData } #endif - public init(frame: CGRect, itemSize: CGSize, cellId: String = .init(describing: Cell.self), cellDelegate: CAListViewCellDelegate? = nil) { + public init( + frame: CGRect, + itemSize: CGSize, + minimumInteritemSpacing: CGFloat = 0, + minimumLineSpacing: CGFloat = 0, + cellId: String = .init(describing: Cell.self), + cellDelegate: CAListViewCellDelegate? = nil + ) { self.cellId = cellId self.cellDelegate = cellDelegate let layout = CACollectionViewFlowLayout() layout.itemSize = itemSize + layout.minimumInteritemSpacing = minimumInteritemSpacing + layout.minimumLineSpacing = minimumLineSpacing #if canImport(AppKit) super.init(frame: frame) collectionViewLayout = layout @@ -72,7 +81,7 @@ open class CAListView, CellRootView, CellData } #elseif canImport(UIKit) public func collectionView(_ collectionView: CACollectionView, didSelectItemAt indexPath: IndexPath) { - + cellDelegate?.onCellTap(data: content[indexPath.item]) } public func collectionView(_ collectionView: CACollectionView, cellForItemAt indexPath: IndexPath) -> CACollectionViewCell { diff --git a/Sources/CommonAppleKit/CAListViewCell.swift b/Sources/CommonAppleKit/CAListViewCell.swift index 9a72123..1a11395 100644 --- a/Sources/CommonAppleKit/CAListViewCell.swift +++ b/Sources/CommonAppleKit/CAListViewCell.swift @@ -9,6 +9,7 @@ import Foundation public protocol CAListViewCellDelegate: AnyObject { + func onCellTap(data: Any?) func onAction(data: Any?) } diff --git a/Sources/CommonAppleKit/CommonAppleKit.swift b/Sources/CommonAppleKit/CommonAppleKit.swift index 94745a2..274b1b3 100644 --- a/Sources/CommonAppleKit/CommonAppleKit.swift +++ b/Sources/CommonAppleKit/CommonAppleKit.swift @@ -37,6 +37,7 @@ public typealias CAFont = UIFont public typealias CAEdgeInsets = UIEdgeInsets public typealias CAStackView = UIStackView + public typealias CAImageView = UIImageView public extension CALabel { var stringValue: String { @@ -139,6 +140,7 @@ public typealias CAFont = NSFont public typealias CAEdgeInsets = NSEdgeInsets public typealias CAStackView = NSStackView + public typealias CAImageView = NSImageView public extension CAImage { @available(macOS 11.0, *)