Skip to content

Commit 5b0595a

Browse files
author
sergey
committed
WIP adapter first version
1 parent edd39e2 commit 5b0595a

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

RxDataSources.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
9FF3014B1C4AA6D1007376BD /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FF301491C4AA6D1007376BD /* RxSwift.framework */; };
3333
9FF3014E1C4AA6DA007376BD /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FF3014C1C4AA6DA007376BD /* RxCocoa.framework */; };
3434
9FF301501C4AA6DA007376BD /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FF3014D1C4AA6DA007376BD /* RxSwift.framework */; };
35+
A5FFBC311F0B922C0074D147 /* RxPickerViewAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FFBC301F0B922C0074D147 /* RxPickerViewAdapter.swift */; };
36+
A5FFBC321F0B922C0074D147 /* RxPickerViewAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FFBC301F0B922C0074D147 /* RxPickerViewAdapter.swift */; };
37+
A5FFBC331F0B922C0074D147 /* RxPickerViewAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5FFBC301F0B922C0074D147 /* RxPickerViewAdapter.swift */; };
3538
C814E8F51D29DB4F00837FE1 /* String+IdentifiableType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C814E8F41D29DB4F00837FE1 /* String+IdentifiableType.swift */; };
3639
C814E8F61D29DB4F00837FE1 /* String+IdentifiableType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C814E8F41D29DB4F00837FE1 /* String+IdentifiableType.swift */; };
3740
C814E8F71D29DB4F00837FE1 /* String+IdentifiableType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C814E8F41D29DB4F00837FE1 /* String+IdentifiableType.swift */; };
@@ -213,6 +216,7 @@
213216
9FF301491C4AA6D1007376BD /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/tvOS/RxSwift.framework; sourceTree = "<group>"; };
214217
9FF3014C1C4AA6DA007376BD /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = Carthage/Build/iOS/RxCocoa.framework; sourceTree = "<group>"; };
215218
9FF3014D1C4AA6DA007376BD /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/iOS/RxSwift.framework; sourceTree = "<group>"; };
219+
A5FFBC301F0B922C0074D147 /* RxPickerViewAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxPickerViewAdapter.swift; sourceTree = "<group>"; };
216220
A66428182C504F0369D6A3F2 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
217221
B472785F652B32605A7A6838 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = "<group>"; };
218222
C814E8F41D29DB4F00837FE1 /* String+IdentifiableType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+IdentifiableType.swift"; sourceTree = "<group>"; };
@@ -457,6 +461,7 @@
457461
C85EE5531C36F1FC0090614D /* RxCollectionViewSectionedReloadDataSource.swift */,
458462
C85EE5541C36F1FC0090614D /* RxTableViewSectionedAnimatedDataSource.swift */,
459463
C85EE5551C36F1FC0090614D /* RxTableViewSectionedReloadDataSource.swift */,
464+
A5FFBC301F0B922C0074D147 /* RxPickerViewAdapter.swift */,
460465
);
461466
path = "DataSources+Rx";
462467
sourceTree = "<group>";
@@ -955,6 +960,7 @@
955960
9FCDA16E1C3AF4A2000F5F94 /* Differentiator.swift in Sources */,
956961
C8477FBB1D29DBC90074454A /* IntegerType+IdentifiableType.swift in Sources */,
957962
9FCDA1771C3AF4A2000F5F94 /* RxTableViewSectionedReloadDataSource.swift in Sources */,
963+
A5FFBC331F0B922C0074D147 /* RxPickerViewAdapter.swift in Sources */,
958964
9FCDA16C1C3AF4A2000F5F94 /* CollectionViewSectionedDataSource.swift in Sources */,
959965
9FCDA1721C3AF4A2000F5F94 /* TableViewSectionedDataSource.swift in Sources */,
960966
9FCDA1741C3AF4A2000F5F94 /* RxCollectionViewSectionedAnimatedDataSource.swift in Sources */,
@@ -1001,6 +1007,7 @@
10011007
C85EE55A1C36F1FC0090614D /* Differentiator.swift in Sources */,
10021008
C8477FBA1D29DBC90074454A /* IntegerType+IdentifiableType.swift in Sources */,
10031009
C85EE5631C36F1FC0090614D /* RxTableViewSectionedReloadDataSource.swift in Sources */,
1010+
A5FFBC321F0B922C0074D147 /* RxPickerViewAdapter.swift in Sources */,
10041011
C85EE5581C36F1FC0090614D /* CollectionViewSectionedDataSource.swift in Sources */,
10051012
C85EE55E1C36F1FC0090614D /* TableViewSectionedDataSource.swift in Sources */,
10061013
C85EE5601C36F1FC0090614D /* RxCollectionViewSectionedAnimatedDataSource.swift in Sources */,
@@ -1076,6 +1083,7 @@
10761083
C8BB76691C4C3E53002B21C8 /* Differentiator.swift in Sources */,
10771084
C8477FB91D29DBC90074454A /* IntegerType+IdentifiableType.swift in Sources */,
10781085
C8BB766C1C4C3E53002B21C8 /* RxTableViewSectionedReloadDataSource.swift in Sources */,
1086+
A5FFBC311F0B922C0074D147 /* RxPickerViewAdapter.swift in Sources */,
10791087
C8BB766D1C4C3E53002B21C8 /* CollectionViewSectionedDataSource.swift in Sources */,
10801088
C8BB766E1C4C3E53002B21C8 /* TableViewSectionedDataSource.swift in Sources */,
10811089
C8BB766F1C4C3E53002B21C8 /* RxCollectionViewSectionedAnimatedDataSource.swift in Sources */,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// RxPickerViewAdapter.swift
3+
// RxDataSources
4+
//
5+
// Created by Sergey Shulga on 04/07/2017.
6+
// Copyright © 2017 kzaher. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
#if !RX_NO_MODULE
12+
import RxSwift
13+
import RxCocoa
14+
#endif
15+
16+
17+
open class RxPickerViewDataSource<T>: NSObject, UIPickerViewDataSource {
18+
public typealias NumberOfComponentsProvider = (RxPickerViewDataSource, UIPickerView, T) -> Int
19+
public typealias NumberOfRowsInComponentProvider = (RxPickerViewDataSource, UIPickerView, T, Int) -> Int
20+
21+
fileprivate var components: T
22+
23+
init(components: T) {
24+
self.components = components
25+
super.init()
26+
}
27+
28+
var numberOfComponentsProvider: NumberOfComponentsProvider!
29+
var numberOfRowsInComponentProvider: NumberOfRowsInComponentProvider!
30+
31+
//MARK: UIPickerViewDataSource
32+
33+
public func numberOfComponents(in pickerView: UIPickerView) -> Int {
34+
return numberOfComponentsProvider(self, pickerView, components)
35+
}
36+
37+
public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
38+
return numberOfRowsInComponentProvider(self, pickerView, components, component)
39+
}
40+
}
41+
42+
open class RxPickerViewStringAdapter<T>: RxPickerViewDataSource<T>, UIPickerViewDelegate {
43+
public typealias TitleForRowProvider = (RxPickerViewStringAdapter<T>, UIPickerView, T,Int, Int) -> String?
44+
45+
public var titleForRowProvider: TitleForRowProvider! = nil
46+
47+
open func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
48+
return titleForRowProvider(self, pickerView, components, row, component)
49+
}
50+
}
51+
52+
open class RxPickerViewAttributedStringAdapter<T>: RxPickerViewDataSource<T>, UIPickerViewDelegate {
53+
public typealias AttributedTitleForRowProvider = (RxPickerViewAttributedStringAdapter<T>, UIPickerView, T, Int, Int) -> NSAttributedString?
54+
55+
public var attributedTitleForRowProvider: AttributedTitleForRowProvider! = nil
56+
57+
open func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
58+
return attributedTitleForRowProvider(self, pickerView, components, row, component)
59+
}
60+
}
61+
62+
open class RxPickerViewViewAdapter<T>: RxPickerViewDataSource<T>, UIPickerViewDelegate {
63+
public typealias ViewForRowProvider = (RxPickerViewViewAdapter<T>, UIPickerView, T, Int, Int, UIView?) -> UIView
64+
65+
public var viewForRowProvider: ViewForRowProvider!
66+
67+
open func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
68+
return viewForRowProvider(self, pickerView, components,row, component, view)
69+
}
70+
}

0 commit comments

Comments
 (0)