Skip to content

Commit 1ccbec7

Browse files
committed
Format code and add comments
1 parent 811f1d4 commit 1ccbec7

File tree

6 files changed

+206
-132
lines changed

6 files changed

+206
-132
lines changed

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 93 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RxIGListKit/Classes/IGListAdapter+Rx.swift

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ import IGListKit
1010
import RxCocoa
1111
import RxSwift
1212

13-
public typealias RxListSingleSectionCellConfigureBlock<E: ListDiffable, Cell: UICollectionViewCell> = (E, Cell) -> Void
14-
public typealias RxListSingleSectionCellSizeBlock<E: ListDiffable> = (E, ListCollectionContext?) -> CGSize
15-
1613
extension Reactive where Base == ListAdapter {
14+
/**
15+
Binds sequences of elements to adapter objects using a custom reactive data used to perform the transformation.
16+
In case `source` observable sequence terminates successfully, the data source will present latest element
17+
until the subscription isn't disposed.
18+
19+
- parameter dataSource: Data source used to transform elements to adapter sections.
20+
- parameter source: Observable sequence of items.
21+
- returns: Disposable object that can be used to unbind.
22+
*/
1723
public func objects<DataSource: ListAdapterDataSource & RxListAdapterDataSourceType, O: ObservableType>(dataSource: DataSource) ->
1824
(_ source: O) -> Disposable
1925
where DataSource.Element == O.Element {
@@ -28,6 +34,16 @@ extension Reactive where Base == ListAdapter {
2834
}
2935
}
3036

37+
/// Binds sequences of elements to adapter objects using a custom reactive data used to perform the transformation for IGListSingleSectionController.
38+
///
39+
/// - Parameters:
40+
/// - cellClass: Type of collection view cell.
41+
/// - selectionDelegate: ListSingleSectionControllerDelegate
42+
/// - source: Observable sequence of objects.
43+
/// - configureBlock: Transform between sequence elements and view cells.
44+
/// - sizeBlock: The size for the cells.
45+
/// - emptyViewProvider: The empty view for the collection view.
46+
/// - Returns: Disposable object that can be used to unbind.
3147
public func objects<S: Sequence, Cell: UICollectionViewCell, O: ObservableType>(cellClass: Cell.Type, selectionDelegate: ListSingleSectionControllerDelegate? = nil)
3248
-> (_ source: O)
3349
-> (_ configureBlock: @escaping RxListSingleSectionCellConfigureBlock<S.Element, Cell>)
@@ -49,41 +65,79 @@ extension Reactive where Base == ListAdapter {
4965
}
5066
}
5167

68+
/// Binds sequences of elements to adapter objects using a custom reactive data used to perform the transformation for IGListSingleSectionController.
69+
///
70+
/// - Parameters:
71+
/// - storyboardCellIdentifier: StoryboardIdentifier used to dequeue cells.
72+
/// - cellClass: Type of collection view cell.
73+
/// - selectionDelegate: ListSingleSectionControllerDelegate
74+
/// - source: Observable sequence of objects.
75+
/// - configureBlock: Transform between sequence elements and view cells.
76+
/// - sizeBlock: The size for the cells.
77+
/// - emptyViewProvider: The empty view for the collection view.
78+
/// - Returns: Disposable object that can be used to unbind.
5279
public func objects<S: Sequence, Cell: UICollectionViewCell, O: ObservableType>(storyboardCellIdentifier: String, cellClass: Cell.Type, selectionDelegate: ListSingleSectionControllerDelegate? = nil)
5380
-> (_ source: O)
5481
-> (_ configureBlock: @escaping RxListSingleSectionCellConfigureBlock<S.Element, Cell>)
5582
-> (_ sizeBlock: @escaping RxListSingleSectionCellSizeBlock<S.Element>)
5683
-> (_ emptyViewProvider: EmptyViewProvider?)
5784
-> Disposable where O.Element == S, S.Element: ListDiffable {
58-
return { source in
59-
{ configureBlock1 in
60-
{ sizeBlock in
61-
{ emptyViewProvider in
62-
let dataSource = RxListAdapterSingleSectionDataSourceSequenceWrapper<S, Cell>(dequeueWay: .storyboard(id: storyboardCellIdentifier), configureBlock: { obj, cell in
63-
configureBlock1(obj, cell)
64-
}, sizeBlock: sizeBlock, emptyViewProvider: emptyViewProvider)
65-
dataSource.delegate = selectionDelegate
66-
return self.objects(dataSource: dataSource)(source)
67-
}
85+
return { source in
86+
{ configureBlock1 in
87+
{ sizeBlock in
88+
{ emptyViewProvider in
89+
let dataSource = RxListAdapterSingleSectionDataSourceSequenceWrapper<S, Cell>(dequeueWay: .storyboard(id: storyboardCellIdentifier), configureBlock: { obj, cell in
90+
configureBlock1(obj, cell)
91+
}, sizeBlock: sizeBlock, emptyViewProvider: emptyViewProvider)
92+
dataSource.delegate = selectionDelegate
93+
return self.objects(dataSource: dataSource)(source)
6894
}
6995
}
7096
}
97+
}
7198
}
7299

73-
100+
/// Binds sequences of elements to adapter objects using a custom reactive data used to perform the transformation for IGListSingleSectionController.
101+
///
102+
/// - Parameters:
103+
/// - nibName: Nib name used to dequeue cells.
104+
/// - bundle: Bundle of the nib.
105+
/// - cellClass: Type of collection view cell.
106+
/// - selectionDelegate: ListSingleSectionControllerDelegate
107+
/// - source: Observable sequence of objects.
108+
/// - configureBlock: Transform between sequence elements and view cells.
109+
/// - sizeBlock: The size for the cells.
110+
/// - emptyViewProvider: The empty view for the collection view.
111+
/// - Returns: Disposable object that can be used to unbind.
112+
public func objects<S: Sequence, Cell: UICollectionViewCell, O: ObservableType>(nibName: String, bundle: Bundle?, cellClass: Cell.Type, selectionDelegate: ListSingleSectionControllerDelegate? = nil)
113+
-> (_ source: O)
114+
-> (_ configureBlock: @escaping RxListSingleSectionCellConfigureBlock<S.Element, Cell>)
115+
-> (_ sizeBlock: @escaping RxListSingleSectionCellSizeBlock<S.Element>)
116+
-> (_ emptyViewProvider: EmptyViewProvider?)
117+
-> Disposable where O.Element == S, S.Element: ListDiffable {
118+
return { source in
119+
{ configureBlock1 in
120+
{ sizeBlock in
121+
{ emptyViewProvider in
122+
let dataSource = RxListAdapterSingleSectionDataSourceSequenceWrapper<S, Cell>(dequeueWay: .nib(name: nibName, bundle: bundle), configureBlock: { obj, cell in
123+
configureBlock1(obj, cell)
124+
}, sizeBlock: sizeBlock, emptyViewProvider: emptyViewProvider)
125+
dataSource.delegate = selectionDelegate
126+
return self.objects(dataSource: dataSource)(source)
127+
}
128+
}
129+
}
130+
}
131+
}
74132
}
75133

76-
public typealias WillDisplayObjectEvent = (object: ListDiffable, index: NSInteger)
77-
public typealias DidEndDisplayingObjectEvent = (object: ListDiffable, index: NSInteger)
78-
public typealias MoveObjectEvent = (object: ListDiffable, from: [ListDiffable], to: [ListDiffable])
79-
80134
extension Reactive where Base == ListAdapter {
81135
var delegate: DelegateProxy<ListAdapter, IGListAdapterDelegate> {
82136
return RxListAdapterDelegateProxy.proxy(for: base)
83137
}
84138

85139
/**
86-
Reactive wrapper for `delegate` message `listAdapter:(IGListAdapter *)listAdapter willDisplayObject:(id)object atIndex:(NSInteger)index`.
140+
Reactive wrapper for `delegate` message `listAdapter:willDisplayObject:atIndex:`.
87141
*/
88142
public var willDisplayObject: ControlEvent<WillDisplayObjectEvent> {
89143
let source = RxListAdapterDelegateProxy.proxy(for: base).willDisplaySubject.map { (obj, idx) -> WillDisplayObjectEvent in
@@ -93,7 +147,7 @@ extension Reactive where Base == ListAdapter {
93147
}
94148

95149
/**
96-
Reactive wrapper for `delegate` message `- (void)listAdapter:(IGListAdapter *)listAdapter didEndDisplayingObject:(id)object atIndex:(NSInteger)index;`.
150+
Reactive wrapper for `delegate` message `listAdapter:didEndDisplayingObject:atIndex:`.
97151
*/
98152
public var didEndDisplayingObject: ControlEvent<DidEndDisplayingObjectEvent> {
99153
let source = RxListAdapterDelegateProxy.proxy(for: base).didEndDisplayingSubject.map { (obj, idx) -> WillDisplayObjectEvent in
@@ -103,7 +157,7 @@ extension Reactive where Base == ListAdapter {
103157
}
104158

105159
/**
106-
Reactive wrapper for `moveDelegate` message ``.
160+
Reactive wrapper for `moveDelegate` message `listAdapter:moveObject:from:to:`.
107161
*/
108162
@available(iOS 9.0, *)
109163
public func moveObject(_ delegate: ListAdapterMoving) -> ControlEvent<MoveObjectEvent> {
@@ -117,13 +171,17 @@ extension Reactive where Base == ListAdapter {
117171
return ControlEvent(events: source)
118172
}
119173

174+
/**
175+
Reactive wrapper for `delegate` message `collectionView(_:didSelectItemAtIndexPath:)`.
176+
*/
120177
public var itemSelected: ControlEvent<IndexPath> {
121178
guard let view = base.collectionView else { fatalError() }
122179
return view.rx.itemSelected
123180
}
124181

125-
public typealias ListWillEndDraggingEvent = (view: UICollectionView, velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
126-
182+
/**
183+
Reactive wrapper for delegate method `scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)`
184+
*/
127185
public var willEndDragging: ControlEvent<ListWillEndDraggingEvent> {
128186
guard let view = base.collectionView else { fatalError() }
129187
let source = view.rx.willEndDragging.map({ (v, targetContentOffset) -> ListWillEndDraggingEvent in

RxIGListKit/Classes/RxListAdapterMoveDataSource.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77

88
import Foundation
9-
import RxSwift
109
import IGListKit
10+
import RxSwift
1111

1212
public protocol ListAdapterMoving: AnyObject {
1313
var moving: Bool { get set }
@@ -21,10 +21,9 @@ extension ListAdapterMoving {
2121
}
2222

2323
public final class RxListAdapterMoveDataSource<E: SectionModelType>: RxListAdapterDataSource<E>, ListAdapterMoving {
24-
2524
public var moving: Bool = false
2625

27-
override public func listAdapter(_ adapter: ListAdapter, observedEvent: Event<[E]>) {
26+
public override func listAdapter(_ adapter: ListAdapter, observedEvent: Event<[E]>) {
2827
switch observedEvent {
2928
case .next(let e):
3029
objects = e

RxIGListKit/Classes/RxListAdapterMoveDelegateProxy.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77

88
import Foundation
99
import IGListKit
10-
import RxSwift
1110
import RxCocoa
11+
import RxSwift
1212

1313
fileprivate let listAdapterMoveDelegateNotSet = ListAdapterMoveDelegateNotSet()
1414

1515
fileprivate final class ListAdapterMoveDelegateNotSet: NSObject, ListAdapterMoveDelegate {
16-
func listAdapter(_ listAdapter: ListAdapter, move object: Any, from previousObjects: [Any], to objects: [Any]) {
17-
}
16+
func listAdapter(_ listAdapter: ListAdapter, move object: Any, from previousObjects: [Any], to objects: [Any]) {}
1817
}
1918

2019
@available(iOS 9.0, *)
21-
final class RxListAdapterMoveDelegateProxy: DelegateProxy<ListAdapter, ListAdapterMoveDelegate>, DelegateProxyType, ListAdapterMoveDelegate{
20+
final class RxListAdapterMoveDelegateProxy: DelegateProxy<ListAdapter, ListAdapterMoveDelegate>, DelegateProxyType, ListAdapterMoveDelegate {
2221
static func currentDelegate(for object: ListAdapter) -> ListAdapterMoveDelegate? {
2322
return object.moveDelegate
2423
}
@@ -52,7 +51,7 @@ final class RxListAdapterMoveDelegateProxy: DelegateProxy<ListAdapter, ListAdapt
5251
}
5352

5453
func listAdapter(_ listAdapter: ListAdapter, move object: Any, from previousObjects: [Any], to objects: [Any]) {
55-
_moveSubject?.onNext((object,previousObjects,objects))
54+
_moveSubject?.onNext((object, previousObjects, objects))
5655
_requiredMethodsDelegate?.listAdapter(listAdapter, move: object, from: previousObjects, to: objects)
5756
}
5857

@@ -64,5 +63,4 @@ final class RxListAdapterMoveDelegateProxy: DelegateProxy<ListAdapter, ListAdapt
6463
deinit {
6564
_moveSubject?.onCompleted()
6665
}
67-
6866
}

RxIGListKit/Classes/RxListAdapterSingleSectionDataSource.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ class RxListAdapterSingleSectionDataSourceSequenceWrapper<S: Sequence, Cell: UIC
4343
print(observedEvent)
4444
}
4545
}
46-
4746
}
4847

4948
protocol RxListSingleSectionControllerDelegate: AnyObject {
50-
associatedtype E: ListDiffable;
49+
associatedtype E: ListDiffable
5150
func didSelect(_ sectionController: ListSingleSectionController, with object: E)
5251
func didDeselect(_ sectionController: ListSingleSectionController, with object: E)
5352
}
@@ -67,8 +66,8 @@ class RxListAdapterSingleSectionDataSource<E: ListDiffable, Cell: UICollectionVi
6766
let emptyViewProvider: EmptyViewProvider?
6867

6968
init(dequeueWay: CellDequeueWay,
70-
configureBlock: @escaping RxListSingleSectionCellConfigureBlock<E, Cell>,
71-
sizeBlock: @escaping RxListSingleSectionCellSizeBlock<E>,
69+
configureBlock: @escaping RxListSingleSectionCellConfigureBlock<E, Cell>,
70+
sizeBlock: @escaping RxListSingleSectionCellSizeBlock<E>,
7271
emptyViewProvider: EmptyViewProvider? = nil) {
7372
self.dequeueWay = dequeueWay
7473
self.configureBlock = configureBlock
@@ -87,37 +86,36 @@ class RxListAdapterSingleSectionDataSource<E: ListDiffable, Cell: UICollectionVi
8786
public override func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController {
8887
switch dequeueWay {
8988
case .cellClass(let cellClass):
90-
let sc = ListSingleSectionController(cellClass: cellClass, configureBlock: { (obj, cell) in
89+
let sc = ListSingleSectionController(cellClass: cellClass, configureBlock: { obj, cell in
9190
self.configureBlock(obj as!
9291
E, cell as! Cell)
9392
}, sizeBlock: { (obj, context) -> CGSize in
9493
self.sizeBlock(obj as! E, context)
9594
})
96-
sc.selectionDelegate = self.delegate
95+
sc.selectionDelegate = delegate
9796
return sc
9897
case .nib(let name, let bundle):
99-
let sc = ListSingleSectionController(nibName: name, bundle: bundle, configureBlock: { (obj, cell) in
98+
let sc = ListSingleSectionController(nibName: name, bundle: bundle, configureBlock: { obj, cell in
10099
self.configureBlock(obj as!
101100
E, cell as! Cell)
102101
}, sizeBlock: { (obj, context) -> CGSize in
103102
self.sizeBlock(obj as! E, context)
104103
})
105-
sc.selectionDelegate = self.delegate
104+
sc.selectionDelegate = delegate
106105
return sc
107106
case .storyboard(let id):
108-
let sc = ListSingleSectionController(storyboardCellIdentifier: id, configureBlock: { (obj, cell) in
107+
let sc = ListSingleSectionController(storyboardCellIdentifier: id, configureBlock: { obj, cell in
109108
self.configureBlock(obj as!
110109
E, cell as! Cell)
111110
}, sizeBlock: { (obj, context) -> CGSize in
112111
self.sizeBlock(obj as! E, context)
113112
})
114-
sc.selectionDelegate = self.delegate
113+
sc.selectionDelegate = delegate
115114
return sc
116115
}
117116
}
118117

119118
public override func emptyView(for listAdapter: ListAdapter) -> UIView? {
120119
return emptyViewProvider?(listAdapter)
121120
}
122-
123121
}

RxIGListKit/Classes/Typealias.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Typealias.swift
3+
// RxIGListKit
4+
//
5+
// Created by gxy on 2019/5/3.
6+
//
7+
8+
import Foundation
9+
import IGListKit.IGListDiffable
10+
11+
public typealias RxListSingleSectionCellConfigureBlock<E: ListDiffable, Cell: UICollectionViewCell> = (E, Cell) -> Void
12+
public typealias RxListSingleSectionCellSizeBlock<E: ListDiffable> = (E, ListCollectionContext?) -> CGSize
13+
14+
public typealias WillDisplayObjectEvent = (object: ListDiffable, index: NSInteger)
15+
public typealias DidEndDisplayingObjectEvent = (object: ListDiffable, index: NSInteger)
16+
public typealias MoveObjectEvent = (object: ListDiffable, from: [ListDiffable], to: [ListDiffable])
17+
public typealias ListWillEndDraggingEvent = (view: UICollectionView, velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)

0 commit comments

Comments
 (0)