Component.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // TSComponent.swift
  3. // ClockWidget
  4. //
  5. // Created by TSYH on 2023/10/7.
  6. //
  7. import UIKit
  8. public protocol TSComponent {}
  9. public protocol TSComponentView {
  10. // UI 渲染
  11. func renderView(with object: Any?, component: TSCollectionViewComponent, attributes: [String: Any]?)
  12. }
  13. public protocol TSCollectionViewSectionComponent: TSComponent {
  14. var cells: [TSCollectionViewCellComponent] { get }
  15. var headerComponent: TSCollectionViewReuseViewComponent? { get }
  16. var footerComponent: TSCollectionViewReuseViewComponent? { get }
  17. var sectionInset: UIEdgeInsets { get }
  18. var lineSpacing: CGFloat { get }
  19. var itemSpacing: CGFloat { get }
  20. }
  21. public extension TSCollectionViewSectionComponent {
  22. public var headerComponent: TSCollectionViewReuseViewComponent? { return nil }
  23. public var footerComponent: TSCollectionViewReuseViewComponent? { return nil }
  24. public var sectionInset: UIEdgeInsets {
  25. return UIEdgeInsets(top: 10, left: 16, bottom: 10, right: 16)
  26. }
  27. public var lineSpacing: CGFloat {
  28. return 12.0
  29. }
  30. public var itemSpacing: CGFloat {
  31. return 12.0
  32. }
  33. }
  34. public enum TSCollectionViewReuseViewType {
  35. case header
  36. case footer
  37. }
  38. public protocol TSCollectionViewReuseViewComponent: TSComponent {
  39. var viewClass: UICollectionReusableView.Type { get }
  40. var viewType: TSCollectionViewReuseViewType { get }
  41. var viewSize: CGSize { get }
  42. var reuseIdentifier: String { get }
  43. }
  44. public extension TSCollectionViewReuseViewComponent {
  45. var reuseIdentifier: String{
  46. return viewClass.description()
  47. }
  48. }
  49. public protocol TSCollectionViewCellComponent: TSComponent {
  50. var cellClass: UICollectionViewCell.Type { get }
  51. func cellSize(with attrubites: [String: Any]?) -> CGSize
  52. }