@@ -9,62 +9,57 @@ import Foundation
99import LithoOperators
1010import Prelude
1111
12- open class FlexModelItem < T, C> : ConcreteFlexDataSourceItem < C > where C: UITableViewCell {
12+ open class FlexModelItem < T, C> : ConcreteFlexDataSourceItem < C > , Tappable , Swipable where C: UITableViewCell {
1313 open var model : T
1414 open var configurer : ( C ) -> Void
15+ public var onTap : ( ( ) -> Void ) ?
16+ public var onSwipe : ( ( ) -> Void ) ?
17+ public var gestureRecognizer : UIGestureRecognizer ?
18+ public var onGesture : ( ( T , UIGestureRecognizer ? ) -> Void ) ?
1519
1620 public init ( _ model: T , _ configurer: @escaping ( T , C ) -> Void ) {
1721 self . model = model
1822 self . configurer = model *-> configurer
1923 super. init ( identifier: String ( describing: C . self) )
2024 }
2125
22- override open func configureCell( _ cell: UITableViewCell ) {
23- if let cell = cell as? C {
24- configurer ( cell)
25- }
26- }
27- }
28-
29- open class FlexTappableModelItem < T, C> : FlexModelItem < T , C > , Tappable where C: UITableViewCell {
30- public var onTap : ( ) -> Void = { }
31-
3226 public init ( model: T , configurer: @escaping ( T , C ) -> Void , tap: @escaping ( T ) -> Void ) {
3327 self . onTap = voidCurry ( model, tap)
34- super. init ( model, configurer)
28+ self . model = model
29+ self . configurer = model *-> configurer
30+ super. init ( identifier: String ( describing: C . self) )
3531 }
36- }
37-
38- open class FlexSwipeTapModelItem < T, C> : FlexTappableModelItem < T , C > , Swipable where C: UITableViewCell {
39- public var onSwipe : ( ) -> Void
4032
4133 public init ( model: T ,
4234 configurer: @escaping ( T , C ) -> Void ,
4335 tap: @escaping ( T ) -> Void ,
4436 swipe: @escaping ( ) -> Void ) {
4537 self . onSwipe = swipe
46- super. init ( model: model, configurer: configurer, tap: tap)
38+ self . onTap = voidCurry ( model, tap)
39+ self . model = model
40+ self . configurer = model *-> configurer
41+ super. init ( identifier: String ( describing: C . self) )
4742 }
4843
4944 public init ( model: T ,
5045 configurer: @escaping ( T , C ) -> Void ,
5146 tap: @escaping ( T ) -> Void ,
5247 swipe: @escaping ( T ) -> Void ) {
5348 self . onSwipe = voidCurry ( model, swipe)
54- super. init ( model: model, configurer: configurer, tap: tap)
49+ self . onTap = voidCurry ( model, tap)
50+ self . model = model
51+ self . configurer = model *-> configurer
52+ super. init ( identifier: String ( describing: C . self) )
5553 }
56- }
57-
58- open class FlexGestureModelItem < T, C> : FlexModelItem < T , C > where C: UITableViewCell {
59- public var gestureRecognizer : UIGestureRecognizer ?
60- public var onGesture : ( ( T , UIGestureRecognizer ? ) -> Void ) ?
6154
6255 override open func configureCell( _ cell: UITableViewCell ) {
6356 if let recognizer = gestureRecognizer {
6457 cell. contentView. removeGestureRecognizer ( recognizer)
6558 cell. contentView. addGestureRecognizer ( recognizer)
6659 }
67- super. configureCell ( cell)
60+ if let cell = cell as? C {
61+ configurer ( cell)
62+ }
6863 }
6964
7065 @objc open func gesturePerformed( ) {
@@ -76,10 +71,10 @@ public func modelItem<T, U: UITableViewCell>(_ configurer: @escaping (T, U) -> V
7671 return configurer -*> FlexModelItem . init
7772}
7873
79- public func tappableModelItem< T, U: UITableViewCell > ( _ configurer: @escaping ( T , U ) -> Void , onTap: @escaping ( T ) -> Void ) -> ( T ) -> FlexTappableModelItem < T , U > {
80- return ( configurer, onTap) -**> FlexTappableModelItem . init
74+ public func tappableModelItem< T, U: UITableViewCell > ( _ configurer: @escaping ( T , U ) -> Void , onTap: @escaping ( T ) -> Void ) -> ( T ) -> FlexModelItem < T , U > {
75+ return ( configurer, onTap) -**> FlexModelItem . init
8176}
8277
83- public func swipeTappableModelItem< T, U: UITableViewCell > ( _ configurer: @escaping ( T , U ) -> Void , onTap: @escaping ( T ) -> Void , onSwipe: @escaping ( T ) -> Void ) -> ( T ) -> FlexSwipeTapModelItem < T , U > {
84- return ( configurer, onTap, onSwipe) -***> FlexSwipeTapModelItem . init
78+ public func swipeTappableModelItem< T, U: UITableViewCell > ( _ configurer: @escaping ( T , U ) -> Void , onTap: @escaping ( T ) -> Void , onSwipe: @escaping ( T ) -> Void ) -> ( T ) -> FlexModelItem < T , U > {
79+ return ( configurer, onTap, onSwipe) -***> FlexModelItem . init
8580}
0 commit comments