mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Add optional scrolling cancellation
This commit is contained in:
parent
3f46aeac43
commit
b8130348ab
@ -847,6 +847,7 @@ public final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDele
|
|||||||
previousItemNode.listNode.contentOffsetChanged = nil
|
previousItemNode.listNode.contentOffsetChanged = nil
|
||||||
previousItemNode.listNode.contentScrollingEnded = nil
|
previousItemNode.listNode.contentScrollingEnded = nil
|
||||||
previousItemNode.listNode.endedInteractiveDragging = { _ in }
|
previousItemNode.listNode.endedInteractiveDragging = { _ in }
|
||||||
|
previousItemNode.listNode.shouldStopScrolling = nil
|
||||||
previousItemNode.listNode.activateChatPreview = nil
|
previousItemNode.listNode.activateChatPreview = nil
|
||||||
previousItemNode.listNode.openStories = nil
|
previousItemNode.listNode.openStories = nil
|
||||||
previousItemNode.listNode.addedVisibleChatsWithPeerIds = nil
|
previousItemNode.listNode.addedVisibleChatsWithPeerIds = nil
|
||||||
@ -976,8 +977,13 @@ public final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDele
|
|||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let _ = self
|
self.endedInteractiveDragging?(self.currentItemNode)
|
||||||
//let _ = self.contentScrollingEnded?(self.currentItemNode)
|
}
|
||||||
|
itemNode.listNode.shouldStopScrolling = { [weak self] velocity in
|
||||||
|
guard let self else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return self.shouldStopScrolling?(self.currentItemNode, velocity) ?? false
|
||||||
}
|
}
|
||||||
itemNode.listNode.contentScrollingEnded = { [weak self] listView in
|
itemNode.listNode.contentScrollingEnded = { [weak self] listView in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
@ -1066,6 +1072,8 @@ public final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDele
|
|||||||
var contentOffset: ListViewVisibleContentOffset?
|
var contentOffset: ListViewVisibleContentOffset?
|
||||||
public var contentOffsetChanged: ((ListViewVisibleContentOffset) -> Void)?
|
public var contentOffsetChanged: ((ListViewVisibleContentOffset) -> Void)?
|
||||||
public var contentScrollingEnded: ((ListView) -> Bool)?
|
public var contentScrollingEnded: ((ListView) -> Bool)?
|
||||||
|
var endedInteractiveDragging: ((ListView) -> Void)?
|
||||||
|
var shouldStopScrolling: ((ListView, CGFloat) -> Bool)?
|
||||||
var activateChatPreview: ((ChatListItem, Int64?, ASDisplayNode, ContextGesture?, CGPoint?) -> Void)?
|
var activateChatPreview: ((ChatListItem, Int64?, ASDisplayNode, ContextGesture?, CGPoint?) -> Void)?
|
||||||
var openStories: ((EnginePeer.Id, ASDisplayNode?) -> Void)?
|
var openStories: ((EnginePeer.Id, ASDisplayNode?) -> Void)?
|
||||||
var addedVisibleChatsWithPeerIds: (([EnginePeer.Id]) -> Void)?
|
var addedVisibleChatsWithPeerIds: (([EnginePeer.Id]) -> Void)?
|
||||||
@ -1732,6 +1740,12 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
|
|||||||
self.mainContainerNode.contentScrollingEnded = { [weak self] listView in
|
self.mainContainerNode.contentScrollingEnded = { [weak self] listView in
|
||||||
return self?.contentScrollingEnded(listView: listView, isPrimary: true) ?? false
|
return self?.contentScrollingEnded(listView: listView, isPrimary: true) ?? false
|
||||||
}
|
}
|
||||||
|
self.mainContainerNode.endedInteractiveDragging = { [weak self] listView in
|
||||||
|
self?.endedInteractiveDragging(listView: listView, isPrimary: true)
|
||||||
|
}
|
||||||
|
self.mainContainerNode.shouldStopScrolling = { [weak self] listView, velocity in
|
||||||
|
return self?.shouldStopScrolling(listView: listView, velocity: velocity, isPrimary: true) ?? false
|
||||||
|
}
|
||||||
|
|
||||||
self.addSubnode(self.debugListView)
|
self.addSubnode(self.debugListView)
|
||||||
|
|
||||||
@ -2335,6 +2349,31 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func shouldStopScrolling(listView: ListView, velocity: CGFloat, isPrimary: Bool) -> Bool {
|
||||||
|
if !isPrimary || self.inlineStackContainerNode == nil {
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let navigationBarComponentView = self.navigationBarView.view as? ChatListNavigationBar.View else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if let clippedScrollOffset = navigationBarComponentView.clippedScrollOffset {
|
||||||
|
let searchScrollOffset = clippedScrollOffset
|
||||||
|
if searchScrollOffset > 0.0 && searchScrollOffset < ChatListNavigationBar.searchScrollHeight {
|
||||||
|
return true
|
||||||
|
} else if clippedScrollOffset < 0.0 && clippedScrollOffset > -listView.tempTopInset {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private func endedInteractiveDragging(listView: ListView, isPrimary: Bool) {
|
||||||
|
}
|
||||||
|
|
||||||
private func contentScrollingEnded(listView: ListView, isPrimary: Bool) -> Bool {
|
private func contentScrollingEnded(listView: ListView, isPrimary: Bool) -> Bool {
|
||||||
if !isPrimary || self.inlineStackContainerNode == nil {
|
if !isPrimary || self.inlineStackContainerNode == nil {
|
||||||
} else {
|
} else {
|
||||||
@ -2403,6 +2442,12 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
|
|||||||
inlineStackContainerNode.contentOffsetChanged = { [weak self] offset in
|
inlineStackContainerNode.contentOffsetChanged = { [weak self] offset in
|
||||||
self?.contentOffsetChanged(offset: offset, isPrimary: false)
|
self?.contentOffsetChanged(offset: offset, isPrimary: false)
|
||||||
}
|
}
|
||||||
|
inlineStackContainerNode.endedInteractiveDragging = { [weak self] listView in
|
||||||
|
self?.endedInteractiveDragging(listView: listView, isPrimary: false)
|
||||||
|
}
|
||||||
|
inlineStackContainerNode.shouldStopScrolling = { [weak self] listView, velocity in
|
||||||
|
return self?.shouldStopScrolling(listView: listView, velocity: velocity, isPrimary: false) ?? false
|
||||||
|
}
|
||||||
inlineStackContainerNode.contentScrollingEnded = { [weak self] listView in
|
inlineStackContainerNode.contentScrollingEnded = { [weak self] listView in
|
||||||
return self?.contentScrollingEnded(listView: listView, isPrimary: false) ?? false
|
return self?.contentScrollingEnded(listView: listView, isPrimary: false) ?? false
|
||||||
}
|
}
|
||||||
|
@ -256,6 +256,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
|
|||||||
public final var updateFloatingHeaderOffset: ((CGFloat, ContainedViewLayoutTransition) -> Void)?
|
public final var updateFloatingHeaderOffset: ((CGFloat, ContainedViewLayoutTransition) -> Void)?
|
||||||
public final var didScrollWithOffset: ((CGFloat, ContainedViewLayoutTransition, ListViewItemNode?, Bool) -> Void)?
|
public final var didScrollWithOffset: ((CGFloat, ContainedViewLayoutTransition, ListViewItemNode?, Bool) -> Void)?
|
||||||
public final var addContentOffset: ((CGFloat, ListViewItemNode?) -> Void)?
|
public final var addContentOffset: ((CGFloat, ListViewItemNode?) -> Void)?
|
||||||
|
public final var shouldStopScrolling: ((CGFloat) -> Bool)?
|
||||||
|
|
||||||
public final var updateScrollingIndicator: ((ScrollingIndicatorState?, ContainedViewLayoutTransition) -> Void)?
|
public final var updateScrollingIndicator: ((ScrollingIndicatorState?, ContainedViewLayoutTransition) -> Void)?
|
||||||
|
|
||||||
@ -855,6 +856,12 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
|
||||||
|
if let shouldStopScrolling = self.shouldStopScrolling, shouldStopScrolling(velocity.y) {
|
||||||
|
targetContentOffset.pointee.y = scrollView.contentOffset.y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
|
public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
|
||||||
self.isDragging = false
|
self.isDragging = false
|
||||||
if decelerate {
|
if decelerate {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user