mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-09 07:41:40 +00:00
ListView: added generalScrollDirectionUpdated
This commit is contained in:
parent
124cc24059
commit
798e2dda42
@ -116,6 +116,11 @@ public struct ListViewKeepTopItemOverscrollBackground {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum GeneralScrollDirection {
|
||||||
|
case up
|
||||||
|
case down
|
||||||
|
}
|
||||||
|
|
||||||
open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGestureRecognizerDelegate {
|
open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGestureRecognizerDelegate {
|
||||||
private final let scroller: ListViewScroller
|
private final let scroller: ListViewScroller
|
||||||
private final var visibleSize: CGSize = CGSize()
|
private final var visibleSize: CGSize = CGSize()
|
||||||
@ -228,6 +233,9 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
|
|||||||
public final var beganInteractiveDragging: () -> Void = { }
|
public final var beganInteractiveDragging: () -> Void = { }
|
||||||
public final var didEndScrolling: (() -> Void)?
|
public final var didEndScrolling: (() -> Void)?
|
||||||
|
|
||||||
|
private var currentGeneralScrollDirection: GeneralScrollDirection?
|
||||||
|
public final var generalScrollDirectionUpdated: (GeneralScrollDirection) -> Void = { _ in }
|
||||||
|
|
||||||
public final var reorderItem: (Int, Int, Any?) -> Signal<Bool, NoError> = { _, _, _ in return .single(false) }
|
public final var reorderItem: (Int, Int, Any?) -> Signal<Bool, NoError> = { _, _, _ in return .single(false) }
|
||||||
|
|
||||||
private final var animations: [ListViewAnimation] = []
|
private final var animations: [ListViewAnimation] = []
|
||||||
@ -602,6 +610,8 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
|
|||||||
self.updateScrollViewDidScroll(scrollView, synchronous: false)
|
self.updateScrollViewDidScroll(scrollView, synchronous: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var generalAccumulatedDeltaY: CGFloat = 0.0
|
||||||
|
|
||||||
private func updateScrollViewDidScroll(_ scrollView: UIScrollView, synchronous: Bool) {
|
private func updateScrollViewDidScroll(_ scrollView: UIScrollView, synchronous: Bool) {
|
||||||
if self.ignoreScrollingEvents || scroller !== self.scroller {
|
if self.ignoreScrollingEvents || scroller !== self.scroller {
|
||||||
return
|
return
|
||||||
@ -611,6 +621,15 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
|
|||||||
//CATransaction.setDisableActions(true)
|
//CATransaction.setDisableActions(true)
|
||||||
|
|
||||||
let deltaY = scrollView.contentOffset.y - self.lastContentOffset.y
|
let deltaY = scrollView.contentOffset.y - self.lastContentOffset.y
|
||||||
|
self.generalAccumulatedDeltaY += deltaY
|
||||||
|
if abs(self.generalAccumulatedDeltaY) > 14.0 {
|
||||||
|
let direction: GeneralScrollDirection = self.generalAccumulatedDeltaY < 0 ? .up : .down
|
||||||
|
self.generalAccumulatedDeltaY = 0.0
|
||||||
|
if self.currentGeneralScrollDirection != direction {
|
||||||
|
self.currentGeneralScrollDirection = direction
|
||||||
|
self.generalScrollDirectionUpdated(direction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.lastContentOffset = scrollView.contentOffset
|
self.lastContentOffset = scrollView.contentOffset
|
||||||
if !self.lastContentOffsetTimestamp.isZero {
|
if !self.lastContentOffsetTimestamp.isZero {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user