Created
January 28, 2020 08:12
-
-
Save Mukeshawal/57ba102e51d5f54fab32a2e997480da0 to your computer and use it in GitHub Desktop.
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
override func didMoveToSuperview() { | |
super.didMoveToSuperview() | |
addObserver(.contentOffset) | |
addObserver(.panGesture) | |
} | |
//MARK: - observers | |
/// Add scroll view content y offset and scroll view panGesture observers | |
/// - Parameter observer: RefreshControl.Observer type | |
private func addObserver(_ observer : Observer){ | |
guard let scrollView = containerScrollView else {return} | |
switch observer { | |
case .contentOffset: | |
scrollView.rx.contentOffset.bind(onNext: {[weak self] offset in | |
self?.scrollViewContentYOffset = -offset.y | |
self?.setNeedsDisplay() | |
}).disposed(by: bag) | |
break | |
case .panGesture: | |
scrollView.panGestureRecognizer.rx.event.bind(onNext: {[weak self] panGesture in | |
self?.xPositionOfPan = panGesture.location(in: self?.containerScrollView).x | |
self?.setNeedsDisplay() | |
switch panGesture.state{ | |
case .cancelled,.failed,.ended: | |
if (self?.scrollViewContentYOffset)! > (self?.thresholdDrag)!{ | |
self?.refreshingStatus = true | |
self?.setNeedsDisplay() | |
self?.animateRefreshCircle() | |
self?.onRefreshing() | |
} | |
break | |
default: | |
break | |
} | |
}).disposed(by: bag) | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment