-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fbb837
commit 03e9dbd
Showing
8 changed files
with
96 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// Proxy.swift | ||
// InfiniteLayout | ||
// | ||
// Created by Arnaud Dorgans on 20/12/2017. | ||
// | ||
|
||
import UIKit | ||
import CocoaProxy | ||
|
||
class InfiniteCollectionViewProxy<T: NSObjectProtocol>: CocoaProxy { | ||
|
||
var collectionView: InfiniteCollectionView! { | ||
get { return self.proxies.first as? InfiniteCollectionView } | ||
set { | ||
if !self.proxies.isEmpty { | ||
self.proxies.removeFirst() | ||
} | ||
self.proxies.insert(newValue, at: 0) | ||
} | ||
} | ||
|
||
var delegate: T? { | ||
get { | ||
guard self.proxies.count > 1 else { | ||
return nil | ||
} | ||
return self.proxies.last as? T | ||
} set { | ||
while self.proxies.count > 1 { | ||
self.proxies.removeLast() | ||
} | ||
guard let delegate = newValue else { | ||
return | ||
} | ||
self.proxies.append(delegate) | ||
} | ||
} | ||
|
||
override func proxies(for aSelector: Selector) -> [NSObjectProtocol] { | ||
return super.proxies(for: aSelector).reversed() | ||
} | ||
|
||
init(collectionView: InfiniteCollectionView) { | ||
super.init(proxies: []) | ||
self.collectionView = collectionView | ||
} | ||
} | ||
|
||
class InfiniteCollectionViewDelegateProxy: InfiniteCollectionViewProxy<UICollectionViewDelegate>, UICollectionViewDelegate { | ||
|
||
override func proxies(for aSelector: Selector) -> [NSObjectProtocol] { | ||
return super.proxies(for: aSelector) | ||
.first { proxy in | ||
guard !(aSelector == #selector(UIScrollViewDelegate.scrollViewDidScroll(_:)) || | ||
aSelector == #selector(UIScrollViewDelegate.scrollViewWillEndDragging(_:withVelocity:targetContentOffset:))) else { | ||
return proxy is InfiniteCollectionView | ||
} | ||
return true | ||
}.flatMap { [$0] } ?? [] | ||
} | ||
} | ||
|
||
class InfiniteCollectionViewDataSourceProxy: InfiniteCollectionViewProxy<UICollectionViewDataSource>, UICollectionViewDataSource { | ||
|
||
override func proxies(for aSelector: Selector) -> [NSObjectProtocol] { | ||
return super.proxies(for: aSelector) | ||
.first { proxy in | ||
guard !(aSelector == #selector(UICollectionViewDataSource.numberOfSections(in:)) || | ||
aSelector == #selector(UICollectionViewDataSource.collectionView(_:numberOfItemsInSection:))) else { | ||
return proxy is InfiniteCollectionView | ||
} | ||
return true | ||
}.flatMap { [$0] } ?? [] | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
return self.collectionView.collectionView(collectionView, numberOfItemsInSection: section) | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
return self.delegate?.collectionView(collectionView, cellForItemAt: indexPath) ?? | ||
self.collectionView.collectionView(collectionView, cellForItemAt: indexPath) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.