mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
Sparse message list improvements
This commit is contained in:
@@ -336,6 +336,11 @@ public final class SparseItemGridScrollingArea: ASDisplayNode {
|
||||
private var activityTimer: SwiftSignalKit.Timer?
|
||||
|
||||
public var beginScrolling: (() -> UIScrollView?)?
|
||||
public var openCurrentDate: (() -> Void)?
|
||||
|
||||
private var offsetBarTimer: SwiftSignalKit.Timer?
|
||||
private var beganAtDateIndicator = false
|
||||
private let hapticFeedback = HapticFeedback()
|
||||
|
||||
private struct ProjectionData {
|
||||
var minY: CGFloat
|
||||
@@ -354,6 +359,9 @@ public final class SparseItemGridScrollingArea: ASDisplayNode {
|
||||
|
||||
super.init()
|
||||
|
||||
self.dateIndicator.isUserInteractionEnabled = false
|
||||
self.lineIndicator.isUserInteractionEnabled = false
|
||||
|
||||
self.view.addSubview(self.dateIndicator)
|
||||
self.view.addSubview(self.lineIndicator)
|
||||
|
||||
@@ -362,8 +370,11 @@ public final class SparseItemGridScrollingArea: ASDisplayNode {
|
||||
guard let strongSelf = self else {
|
||||
return false
|
||||
}
|
||||
if !strongSelf.dateIndicator.frame.contains(point) {
|
||||
return false
|
||||
|
||||
if strongSelf.dateIndicator.frame.contains(point) {
|
||||
strongSelf.beganAtDateIndicator = true
|
||||
} else {
|
||||
strongSelf.beganAtDateIndicator = false
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -372,13 +383,19 @@ public final class SparseItemGridScrollingArea: ASDisplayNode {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
let transition: ContainedViewLayoutTransition = .animated(duration: 0.1, curve: .easeInOut)
|
||||
transition.updateSublayerTransformOffset(layer: strongSelf.dateIndicator.layer, offset: CGPoint(x: -80.0, y: 0.0))
|
||||
|
||||
let offsetBarTimer = SwiftSignalKit.Timer(timeout: 0.2, repeat: false, completion: {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.performOffsetBarTimerEvent()
|
||||
}, queue: .mainQueue())
|
||||
strongSelf.offsetBarTimer?.invalidate()
|
||||
strongSelf.offsetBarTimer = offsetBarTimer
|
||||
offsetBarTimer.start()
|
||||
|
||||
strongSelf.isDragging = true
|
||||
|
||||
strongSelf.updateLineIndicator(transition: transition)
|
||||
|
||||
if let scrollView = strongSelf.beginScrolling?() {
|
||||
strongSelf.draggingScrollView = scrollView
|
||||
strongSelf.scrollingInitialOffset = scrollView.contentOffset.y
|
||||
@@ -393,6 +410,13 @@ public final class SparseItemGridScrollingArea: ASDisplayNode {
|
||||
}
|
||||
strongSelf.draggingScrollView = nil
|
||||
|
||||
if strongSelf.offsetBarTimer != nil {
|
||||
strongSelf.offsetBarTimer?.invalidate()
|
||||
strongSelf.offsetBarTimer = nil
|
||||
|
||||
strongSelf.openCurrentDate?()
|
||||
}
|
||||
|
||||
let transition: ContainedViewLayoutTransition = .animated(duration: 0.2, curve: .easeInOut)
|
||||
transition.updateSublayerTransformOffset(layer: strongSelf.dateIndicator.layer, offset: CGPoint(x: 0.0, y: 0.0))
|
||||
|
||||
@@ -413,6 +437,12 @@ public final class SparseItemGridScrollingArea: ASDisplayNode {
|
||||
return
|
||||
}
|
||||
|
||||
if strongSelf.offsetBarTimer != nil {
|
||||
strongSelf.offsetBarTimer?.invalidate()
|
||||
strongSelf.offsetBarTimer = nil
|
||||
strongSelf.performOffsetBarTimerEvent()
|
||||
}
|
||||
|
||||
let indicatorArea = projectionData.maxY - projectionData.minY
|
||||
let scrollFraction = projectionData.scrollableHeight / indicatorArea
|
||||
|
||||
@@ -434,6 +464,15 @@ public final class SparseItemGridScrollingArea: ASDisplayNode {
|
||||
self.view.addGestureRecognizer(dragGesture)
|
||||
}
|
||||
|
||||
private func performOffsetBarTimerEvent() {
|
||||
self.hapticFeedback.impact()
|
||||
self.offsetBarTimer = nil
|
||||
|
||||
let transition: ContainedViewLayoutTransition = .animated(duration: 0.1, curve: .easeInOut)
|
||||
transition.updateSublayerTransformOffset(layer: self.dateIndicator.layer, offset: self.beganAtDateIndicator ? CGPoint(x: -80.0, y: 0.0) : CGPoint(x: -3.0, y: 0.0))
|
||||
self.updateLineIndicator(transition: transition)
|
||||
}
|
||||
|
||||
public func update(
|
||||
containerSize: CGSize,
|
||||
containerInsets: UIEdgeInsets,
|
||||
@@ -556,6 +595,13 @@ public final class SparseItemGridScrollingArea: ASDisplayNode {
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
|
||||
if self.lineIndicator.alpha <= 0.01 {
|
||||
return nil
|
||||
}
|
||||
if self.lineIndicator.frame.insetBy(dx: -4.0, dy: -2.0).contains(point) {
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user