1- //
2- // PagingCollectionViewCell.swift
3- // CollectionViewPagingLayout
4- //
5- // Created by Amir on 20/03/2021.
6- // Copyright © 2021 Amir Khorsandi. All rights reserved.
7- //
8-
9- #if canImport(SwiftUI) && canImport(Combine)
10- import UIKit
111import SwiftUI
2+ import UIKit
123
13- @available ( iOS 13 . 0 , * )
144class PagingCollectionViewCell < ValueType: Identifiable , Content: View > : UICollectionViewCell {
15-
165 typealias Parent = PagingCollectionViewController < ValueType , Content >
176
187 // MARK: Properties
@@ -29,7 +18,7 @@ class PagingCollectionViewCell<ValueType: Identifiable, Content: View>: UICollec
2918
3019 func update( value: ValueType , index: IndexPath , parent: Parent ) {
3120 self . parent = parent
32- self . viewBuilder = parent. pageViewBuilder
21+ viewBuilder = parent. pageViewBuilder
3322 self . value = value
3423 self . index = index
3524 if hostingController != nil {
@@ -53,7 +42,6 @@ class PagingCollectionViewCell<ValueType: Identifiable, Content: View>: UICollec
5342 }
5443 }
5544
56-
5745 // MARK: Private functions
5846
5947 @discardableResult private func updateView( progress: CGFloat ? = nil ) -> Content ? {
@@ -77,7 +65,8 @@ class PagingCollectionViewCell<ValueType: Identifiable, Content: View>: UICollec
7765 func constraint< T> ( _ first: NSLayoutAnchor < T > ,
7866 _ second: NSLayoutAnchor < T > ,
7967 _ paddingKeyPath: KeyPath < PagePadding , PagePadding . Padding ? > ,
80- _ inside: Bool ) {
68+ _ inside: Bool )
69+ {
8170 let padding = parent. modifierData? . pagePadding ? [ keyPath: paddingKeyPath] ?? . absolute( 0 )
8271 let constant : CGFloat
8372 switch padding {
@@ -90,7 +79,8 @@ class PagingCollectionViewCell<ValueType: Identifiable, Content: View>: UICollec
9079 }
9180 let identifier = " pagePaddingConstraint_ \( inside) _ \( T . self) "
9281 if let constraint = contentView. constraints. first ( where: { $0. identifier == identifier } ) ??
93- viewController. view. constraints. first ( where: { $0. identifier == identifier } ) {
82+ viewController. view. constraints. first ( where: { $0. identifier == identifier } )
83+ {
9484 constraint. constant = constant * ( inside ? 1 : - 1 )
9585 } else {
9686 let constraint = first. constraint ( equalTo: second, constant: constant * ( inside ? 1 : - 1 ) )
@@ -106,13 +96,11 @@ class PagingCollectionViewCell<ValueType: Identifiable, Content: View>: UICollec
10696 }
10797}
10898
109-
110- @available ( iOS 13 . 0 , * )
11199extension PagingCollectionViewCell : TransformableView ,
112- ScaleTransformView ,
113- StackTransformView ,
114- SnapshotTransformView {
115-
100+ ScaleTransformView ,
101+ StackTransformView ,
102+ SnapshotTransformView
103+ {
116104 var scalableView : UIView {
117105 hostingController? . view ?? contentView
118106 }
@@ -132,9 +120,11 @@ extension PagingCollectionViewCell: TransformableView,
132120 var scaleOptions : ScaleTransformViewOptions {
133121 parent? . modifierData? . scaleOptions ?? . init( )
134122 }
123+
135124 var stackOptions : StackTransformViewOptions {
136125 parent? . modifierData? . stackOptions ?? . init( )
137126 }
127+
138128 var snapshotOptions : SnapshotTransformViewOptions {
139129 parent? . modifierData? . snapshotOptions ?? . init( )
140130 }
@@ -183,4 +173,3 @@ extension PagingCollectionViewCell: TransformableView,
183173 return snapshot. snapshotSize == targetView. bounds. size
184174 }
185175}
186- #endif
0 commit comments