Skip to content

Commit 4e8b17f

Browse files
authored
Merge pull request #1 from lm2343635/develop/rxmenuview
Develop/rxmenuview
2 parents 023916f + 4700eb3 commit 4e8b17f

13 files changed

+625
-50
lines changed

RxPagingKit.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "RxPagingKit"
11-
s.version = "0.5"
11+
s.version = "0.5.1"
1212
s.summary = "Reactive Extension for PagingKit"
1313

1414
s.description = <<-DESC

RxPagingKit.xcodeproj/project.pbxproj

+22-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
2B4AE49E220E9710000E7178 /* PagingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2B4AE49B220E9710000E7178 /* PagingKit.framework */; };
2323
2B4AE49F220E9710000E7178 /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2B4AE49C220E9710000E7178 /* RxSwift.framework */; };
2424
7716933922BA0E8F00140179 /* RxRelay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7716933822BA0E8F00140179 /* RxRelay.framework */; };
25+
7716934422C3214100140179 /* PagingMenuViewDataSourceProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7716934322C3214100140179 /* PagingMenuViewDataSourceProxy.swift */; };
26+
7716934622C3218300140179 /* RxPagingMenuViewDataSourceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7716934522C3218300140179 /* RxPagingMenuViewDataSourceType.swift */; };
27+
7716934822C321D800140179 /* PagingMenuView+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7716934722C321D800140179 /* PagingMenuView+Rx.swift */; };
28+
7716934C22C3772E00140179 /* PagingMenuViewDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7716934B22C3772E00140179 /* PagingMenuViewDelegateProxy.swift */; };
2529
/* End PBXBuildFile section */
2630

2731
/* Begin PBXContainerItemProxy section */
@@ -53,6 +57,10 @@
5357
2B4AE49B220E9710000E7178 /* PagingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PagingKit.framework; path = Carthage/Build/iOS/PagingKit.framework; sourceTree = "<group>"; };
5458
2B4AE49C220E9710000E7178 /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/iOS/RxSwift.framework; sourceTree = "<group>"; };
5559
7716933822BA0E8F00140179 /* RxRelay.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxRelay.framework; path = Carthage/Build/iOS/RxRelay.framework; sourceTree = "<group>"; };
60+
7716934322C3214100140179 /* PagingMenuViewDataSourceProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingMenuViewDataSourceProxy.swift; sourceTree = "<group>"; };
61+
7716934522C3218300140179 /* RxPagingMenuViewDataSourceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxPagingMenuViewDataSourceType.swift; sourceTree = "<group>"; };
62+
7716934722C321D800140179 /* PagingMenuView+Rx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PagingMenuView+Rx.swift"; sourceTree = "<group>"; };
63+
7716934B22C3772E00140179 /* PagingMenuViewDelegateProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingMenuViewDelegateProxy.swift; sourceTree = "<group>"; };
5664
/* End PBXFileReference section */
5765

5866
/* Begin PBXFrameworksBuildPhase section */
@@ -100,16 +108,20 @@
100108
2B4AE46A220E9044000E7178 /* RxPagingKit */ = {
101109
isa = PBXGroup;
102110
children = (
103-
2B4AE46B220E9044000E7178 /* RxPagingKit.h */,
104-
2B4AE482220E9059000E7178 /* PagingMenuViewController+Rx.swift */,
111+
2B4AE46C220E9044000E7178 /* Info.plist */,
105112
2B4AE486220E9059000E7178 /* PagingContentViewController+Rx.swift */,
106113
2B4AE489220E905A000E7178 /* PagingContentViewControllerDataSourceProxy.swift */,
107-
2B4AE487220E9059000E7178 /* RxPagingContentViewControllerDataSourceType.swift */,
114+
2B4AE485220E9059000E7178 /* PagingContentViewControllerDelegateProxy.swift */,
115+
7716934722C321D800140179 /* PagingMenuView+Rx.swift */,
116+
2B4AE482220E9059000E7178 /* PagingMenuViewController+Rx.swift */,
108117
2B4AE488220E905A000E7178 /* PagingMenuViewControllerDataSourceProxy.swift */,
109-
2B4AE484220E9059000E7178 /* RxPagingMenuViewControllerDataSourceType.swift */,
110118
2B4AE483220E9059000E7178 /* PagingMenuViewControllerDelegateProxy.swift */,
111-
2B4AE485220E9059000E7178 /* PagingContentViewControllerDelegateProxy.swift */,
112-
2B4AE46C220E9044000E7178 /* Info.plist */,
119+
7716934322C3214100140179 /* PagingMenuViewDataSourceProxy.swift */,
120+
7716934B22C3772E00140179 /* PagingMenuViewDelegateProxy.swift */,
121+
2B4AE487220E9059000E7178 /* RxPagingContentViewControllerDataSourceType.swift */,
122+
2B4AE46B220E9044000E7178 /* RxPagingKit.h */,
123+
2B4AE484220E9059000E7178 /* RxPagingMenuViewControllerDataSourceType.swift */,
124+
7716934522C3218300140179 /* RxPagingMenuViewDataSourceType.swift */,
113125
);
114126
path = RxPagingKit;
115127
sourceTree = "<group>";
@@ -271,13 +283,17 @@
271283
isa = PBXSourcesBuildPhase;
272284
buildActionMask = 2147483647;
273285
files = (
286+
7716934822C321D800140179 /* PagingMenuView+Rx.swift in Sources */,
274287
2B4AE491220E905A000E7178 /* PagingContentViewControllerDataSourceProxy.swift in Sources */,
275288
2B4AE490220E905A000E7178 /* PagingMenuViewControllerDataSourceProxy.swift in Sources */,
276289
2B4AE48C220E905A000E7178 /* RxPagingMenuViewControllerDataSourceType.swift in Sources */,
277290
2B4AE48A220E905A000E7178 /* PagingMenuViewController+Rx.swift in Sources */,
278291
2B4AE48D220E905A000E7178 /* PagingContentViewControllerDelegateProxy.swift in Sources */,
292+
7716934622C3218300140179 /* RxPagingMenuViewDataSourceType.swift in Sources */,
279293
2B4AE48E220E905A000E7178 /* PagingContentViewController+Rx.swift in Sources */,
280294
2B4AE48B220E905A000E7178 /* PagingMenuViewControllerDelegateProxy.swift in Sources */,
295+
7716934C22C3772E00140179 /* PagingMenuViewDelegateProxy.swift in Sources */,
296+
7716934422C3214100140179 /* PagingMenuViewDataSourceProxy.swift in Sources */,
281297
2B4AE48F220E905A000E7178 /* RxPagingContentViewControllerDataSourceType.swift in Sources */,
282298
);
283299
runOnlyForDeploymentPostprocessing = 0;

RxPagingKit/PagingMenuView+Rx.swift

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// PagingMenuView+Rx.swift
3+
// RxPagingKit
4+
//
5+
// Created by Meng Li on 2019/06/26.
6+
// Copyright © 2019 Kazuhiro Hayashi. All rights reserved.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
26+
import UIKit
27+
import RxSwift
28+
import RxCocoa
29+
import PagingKit
30+
31+
extension Reactive where Base: PagingMenuView {
32+
33+
public func items<Item, O: ObservableType>
34+
(_ source: O) ->
35+
(_ cellFactory: @escaping (PagingMenuView, Int, Item) -> PagingMenuViewCell) -> Disposable
36+
where O.Element == [(Item, CGFloat)] {
37+
return { cellFactory in
38+
let dataSource = RxPagingMenuViewReactiveArrayDataSource<Item>(cellFactory: cellFactory)
39+
return self.items(dataSource: dataSource)(source)
40+
}
41+
}
42+
43+
public func items<Item, Cell: PagingMenuViewCell, O: ObservableType>
44+
(cellIdentifier: String, cellType: Cell.Type = Cell.self) ->
45+
(_ source: O) ->
46+
(_ configureCell: @escaping (Int, Item, Cell) -> Void) -> Disposable
47+
where O.Element == [(Item, CGFloat)] {
48+
49+
return { source in
50+
return { configureCell in
51+
let dataSource = RxPagingMenuViewReactiveArrayDataSource<Item> { view, index, item in
52+
let cell = view.dequeue(with: cellIdentifier) as! Cell
53+
configureCell(index, item, cell)
54+
return cell
55+
}
56+
return self.items(dataSource: dataSource)(source)
57+
}
58+
}
59+
}
60+
61+
public func items<DataSource: PagingMenuViewDataSource & RxPagingMenuViewDataSourceType, O: ObservableType>
62+
(dataSource: DataSource)
63+
-> (_ source: O) -> Disposable where O.Element == DataSource.Element {
64+
RxPagingMenuViewDataSourceProxy.setCurrentDelegate(nil, to: base)
65+
66+
return { [base] source in
67+
RxPagingMenuViewDataSourceProxy.setCurrentDelegate(dataSource, to: base)
68+
69+
let subscription = source
70+
.asObservable()
71+
.observeOn(MainScheduler())
72+
.catchError { _ in
73+
return Observable.empty()
74+
}
75+
.concat(Observable.never())
76+
.takeUntil(base.rx.deallocated)
77+
.subscribe { (event) in
78+
dataSource.pagingView(base, observedEvent: event)
79+
}
80+
81+
return Disposables.create { [weak base] in
82+
guard let base = base else { return }
83+
subscription.dispose()
84+
base.layoutIfNeeded()
85+
//TODO: - dispose delegate with unregisterDelegate
86+
87+
RxPagingMenuViewDataSourceProxy.setCurrentDelegate(nil, to: base)
88+
}
89+
}
90+
}
91+
92+
public var itemSelected: ControlEvent<Int> {
93+
return menuDelegate.didSelect
94+
}
95+
96+
public var willAnimateFocusView: ControlEvent<(Int, PagingMenuFocusViewAnimationCoordinator)> {
97+
return menuDelegate.willAnimateFocusView
98+
}
99+
100+
public var willDisplayCell: ControlEvent<(PagingMenuViewCell, Int)> {
101+
return menuDelegate.willDisplayCell
102+
}
103+
104+
public var scroll: Binder<Int> {
105+
return Binder(self.base) { menuView, index in
106+
menuView.scroll(index: index)
107+
}
108+
}
109+
110+
private var menuDelegate: RxPagingMenuViewDelegateProxy {
111+
return RxPagingMenuViewDelegateProxy.proxy(for: base)
112+
}
113+
114+
}

RxPagingKit/PagingMenuViewControllerDataSourceProxy.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
// THE SOFTWARE.
24+
2425
import UIKit
2526
import RxSwift
2627
import RxCocoa
@@ -30,7 +31,8 @@ extension PagingMenuViewController: HasDataSource {
3031
public typealias DataSource = PagingMenuViewControllerDataSource
3132
}
3233

33-
class RxPagingMenuViewControllerDataSourceProxy: DelegateProxy<PagingMenuViewController, PagingMenuViewControllerDataSource>, DelegateProxyType, PagingMenuViewControllerDataSource {
34+
class RxPagingMenuViewControllerDataSourceProxy: DelegateProxy<PagingMenuViewController, PagingMenuViewControllerDataSource>, DelegateProxyType {
35+
3436
init(pagingMenuViewController: PagingMenuViewController) {
3537
super.init(parentObject: pagingMenuViewController, delegateProxy: RxPagingMenuViewControllerDataSourceProxy.self)
3638
}
@@ -39,6 +41,10 @@ class RxPagingMenuViewControllerDataSourceProxy: DelegateProxy<PagingMenuViewCon
3941
self.register { RxPagingMenuViewControllerDataSourceProxy(pagingMenuViewController: $0) }
4042
}
4143

44+
}
45+
46+
extension RxPagingMenuViewControllerDataSourceProxy: PagingMenuViewControllerDataSource {
47+
4248
func numberOfItemsForMenuViewController(viewController: PagingMenuViewController) -> Int {
4349
return forwardToDelegate()?.numberOfItemsForMenuViewController(viewController: viewController) ?? 0
4450
}
@@ -50,4 +56,5 @@ class RxPagingMenuViewControllerDataSourceProxy: DelegateProxy<PagingMenuViewCon
5056
func menuViewController(viewController: PagingMenuViewController, widthForItemAt index: Int) -> CGFloat {
5157
return forwardToDelegate()!.menuViewController(viewController: viewController, widthForItemAt: index)
5258
}
59+
5360
}

RxPagingKit/PagingMenuViewControllerDelegateProxy.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension PagingMenuViewController: HasDelegate {
3131
public typealias Delegate = PagingMenuViewControllerDelegate
3232
}
3333

34-
class RxPagingMenuViewControllerDelegateProxy: DelegateProxy<PagingMenuViewController, PagingMenuViewControllerDelegate>, DelegateProxyType, PagingMenuViewControllerDelegate {
34+
class RxPagingMenuViewControllerDelegateProxy: DelegateProxy<PagingMenuViewController, PagingMenuViewControllerDelegate> {
3535

3636
let (didSelectSubject, didSelect): (PublishSubject<(Int, Int)>, ControlEvent<(Int, Int)>) = {
3737
let subject = PublishSubject<(Int, Int)>()
@@ -53,7 +53,6 @@ class RxPagingMenuViewControllerDelegateProxy: DelegateProxy<PagingMenuViewContr
5353
return (subject, ControlEvent<(PagingMenuViewCell, Int)>(events: subject.asObserver()))
5454
}()
5555

56-
5756
init(pagingMenuViewController: PagingMenuViewController) {
5857
super.init(parentObject: pagingMenuViewController, delegateProxy: RxPagingMenuViewControllerDelegateProxy.self)
5958
}
@@ -62,23 +61,28 @@ class RxPagingMenuViewControllerDelegateProxy: DelegateProxy<PagingMenuViewContr
6261
self.register { RxPagingMenuViewControllerDelegateProxy(pagingMenuViewController: $0) }
6362
}
6463

65-
// MARK:- PagingContentViewControllerDelegate
64+
}
65+
66+
extension RxPagingMenuViewControllerDelegateProxy: DelegateProxyType {}
67+
68+
extension RxPagingMenuViewControllerDelegateProxy: PagingMenuViewControllerDelegate {
6669

6770
func menuViewController(viewController: PagingMenuViewController, focusViewDidEndTransition focusView: PagingMenuFocusView) {
6871
focusViewTransitionedSubject.onNext(focusView)
6972
}
7073

71-
74+
7275
func menuViewController(viewController: PagingMenuViewController, didSelect page: Int, previousPage: Int) {
7376
didSelectSubject.onNext((page, previousPage))
7477
}
7578

76-
79+
7780
func menuViewController(viewController: PagingMenuViewController, willAnimateFocusViewTo index: Int, with coordinator: PagingMenuFocusViewAnimationCoordinator) {
7881
willAnimateFocusViewSubject.onNext((index, coordinator))
7982
}
80-
83+
8184
func menuViewController(viewController: PagingMenuViewController, willDisplay cell: PagingMenuViewCell, forItemAt index: Int) {
8285
willDisplayCellSubject.onNext((cell, index))
8386
}
87+
8488
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// PagingMenuViewDataSourceProxy.swift
3+
// RxPagingKit
4+
//
5+
// Created by Meng Li on 2019/06/26.
6+
// Copyright © 2019 Kazuhiro Hayashi. All rights reserved.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
26+
import UIKit
27+
import RxSwift
28+
import RxCocoa
29+
import PagingKit
30+
31+
extension PagingMenuView: HasDataSource {
32+
public typealias DataSource = PagingMenuViewDataSource
33+
}
34+
35+
class RxPagingMenuViewDataSourceProxy: DelegateProxy<PagingMenuView, PagingMenuViewDataSource>, DelegateProxyType {
36+
37+
init(pagingMenuView: PagingMenuView) {
38+
super.init(parentObject: pagingMenuView, delegateProxy: RxPagingMenuViewDataSourceProxy.self)
39+
}
40+
41+
static func registerKnownImplementations() {
42+
self.register { RxPagingMenuViewDataSourceProxy(pagingMenuView: $0) }
43+
}
44+
45+
}
46+
47+
extension RxPagingMenuViewDataSourceProxy: PagingMenuViewDataSource {
48+
49+
func numberOfItemForPagingMenuView() -> Int {
50+
return forwardToDelegate()!.numberOfItemForPagingMenuView()
51+
}
52+
53+
func pagingMenuView(pagingMenuView: PagingMenuView, cellForItemAt index: Int) -> PagingMenuViewCell {
54+
return forwardToDelegate()!.pagingMenuView(pagingMenuView: pagingMenuView, cellForItemAt: index)
55+
}
56+
57+
func pagingMenuView(pagingMenuView: PagingMenuView, widthForItemAt index: Int) -> CGFloat {
58+
return forwardToDelegate()!.pagingMenuView(pagingMenuView: pagingMenuView, widthForItemAt: index)
59+
}
60+
61+
}

0 commit comments

Comments
 (0)