From 798e2dda429d112e856e743bcae943f25a21f406 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Sat, 2 Mar 2019 00:01:24 +0400 Subject: [PATCH] ListView: added generalScrollDirectionUpdated --- Display/ListView.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Display/ListView.swift b/Display/ListView.swift index 06cbd5a42d..80a85dca70 100644 --- a/Display/ListView.swift +++ b/Display/ListView.swift @@ -116,6 +116,11 @@ public struct ListViewKeepTopItemOverscrollBackground { } } +public enum GeneralScrollDirection { + case up + case down +} + open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGestureRecognizerDelegate { private final let scroller: ListViewScroller private final var visibleSize: CGSize = CGSize() @@ -228,6 +233,9 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture public final var beganInteractiveDragging: () -> 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 = { _, _, _ in return .single(false) } private final var animations: [ListViewAnimation] = [] @@ -602,6 +610,8 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture self.updateScrollViewDidScroll(scrollView, synchronous: false) } + private var generalAccumulatedDeltaY: CGFloat = 0.0 + private func updateScrollViewDidScroll(_ scrollView: UIScrollView, synchronous: Bool) { if self.ignoreScrollingEvents || scroller !== self.scroller { return @@ -611,6 +621,15 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture //CATransaction.setDisableActions(true) 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 if !self.lastContentOffsetTimestamp.isZero {