Merge pull request #500 from j-f1/scroll-discovery-to-top
Add support for scrolling the discovery tab to the top/first tab
This commit is contained in:
commit
9c9edcb717
|
@ -14,6 +14,12 @@ protocol ScrollViewContainer: UIViewController {
|
||||||
|
|
||||||
extension ScrollViewContainer {
|
extension ScrollViewContainer {
|
||||||
func scrollToTop(animated: Bool) {
|
func scrollToTop(animated: Bool) {
|
||||||
scrollView.scrollRectToVisible(CGRect(origin: .zero, size: CGSize(width: 1, height: 1)), animated: animated)
|
scrollView.scrollToTop(animated: animated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension UIScrollView {
|
||||||
|
func scrollToTop(animated: Bool) {
|
||||||
|
scrollRectToVisible(CGRect(origin: .zero, size: CGSize(width: 1, height: 1)), animated: animated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,6 +131,13 @@ extension DiscoveryViewController: ScrollViewContainer {
|
||||||
var scrollView: UIScrollView {
|
var scrollView: UIScrollView {
|
||||||
return (currentViewController as? ScrollViewContainer)?.scrollView ?? UIScrollView()
|
return (currentViewController as? ScrollViewContainer)?.scrollView ?? UIScrollView()
|
||||||
}
|
}
|
||||||
|
func scrollToTop(animated: Bool) {
|
||||||
|
if scrollView.contentOffset.y <= 0 {
|
||||||
|
scrollToPage(.first, animated: animated)
|
||||||
|
} else {
|
||||||
|
scrollView.scrollToTop(animated: animated)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DiscoveryViewController {
|
extension DiscoveryViewController {
|
||||||
|
|
|
@ -190,6 +190,16 @@ extension SearchViewController: UISearchControllerDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - ScrollViewContainer
|
||||||
|
extension SearchViewController: ScrollViewContainer {
|
||||||
|
var scrollView: UIScrollView {
|
||||||
|
discoveryViewController?.scrollView ?? UIScrollView()
|
||||||
|
}
|
||||||
|
func scrollToTop(animated: Bool) {
|
||||||
|
discoveryViewController?.scrollToTop(animated: animated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - UICollectionViewDelegate
|
// MARK: - UICollectionViewDelegate
|
||||||
//extension SearchViewController: UICollectionViewDelegate {
|
//extension SearchViewController: UICollectionViewDelegate {
|
||||||
// func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
// func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
|
|
Loading…
Reference in New Issue