ListView: fix snapToBounds animation when preserving the current offset

CachedPeerDataTable: don't remove cached data from the cache
This commit is contained in:
Peter 2019-06-18 14:10:15 +01:00
parent 125835872a
commit ea8cbbd7bc
3 changed files with 18 additions and 16 deletions

View File

@ -759,7 +759,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
return additionalInverseTopInset return additionalInverseTopInset
} }
private func snapToBounds(snapTopItem: Bool, stackFromBottom: Bool, updateSizeAndInsets: ListViewUpdateSizeAndInsets? = nil, scrollToItem: ListViewScrollToItem? = nil) -> (snappedTopInset: CGFloat, offset: CGFloat) { private func snapToBounds(snapTopItem: Bool, stackFromBottom: Bool, updateSizeAndInsets: ListViewUpdateSizeAndInsets? = nil, scrollToItem: ListViewScrollToItem? = nil, isExperimentalSnapToScrollToItem: Bool = false) -> (snappedTopInset: CGFloat, offset: CGFloat) {
if self.itemNodes.count == 0 { if self.itemNodes.count == 0 {
return (0.0, 0.0) return (0.0, 0.0)
} }
@ -819,7 +819,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
var transition: ContainedViewLayoutTransition = .immediate var transition: ContainedViewLayoutTransition = .immediate
if let updateSizeAndInsets = updateSizeAndInsets { if let updateSizeAndInsets = updateSizeAndInsets {
if !updateSizeAndInsets.duration.isZero { if !updateSizeAndInsets.duration.isZero && !isExperimentalSnapToScrollToItem {
switch updateSizeAndInsets.curve { switch updateSizeAndInsets.curve {
case let .Spring(duration): case let .Spring(duration):
transition = .animated(duration: duration, curve: .spring) transition = .animated(duration: duration, curve: .spring)
@ -828,15 +828,17 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
} }
} }
} else if let scrollToItem = scrollToItem { } else if let scrollToItem = scrollToItem {
switch scrollToItem.curve { if scrollToItem.animated {
case let .Spring(duration): switch scrollToItem.curve {
transition = .animated(duration: duration, curve: .spring) case let .Spring(duration):
case let .Default(duration): transition = .animated(duration: duration, curve: .spring)
if let duration = duration, duration.isZero { case let .Default(duration):
transition = .immediate if let duration = duration, duration.isZero {
} else { transition = .immediate
transition = .animated(duration: duration ?? 0.3, curve: .easeInOut) } else {
} transition = .animated(duration: duration ?? 0.3, curve: .easeInOut)
}
}
} }
} }
@ -2484,7 +2486,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
itemNode.position = CGPoint(x: position.x, y: position.y + offsetFix) itemNode.position = CGPoint(x: position.x, y: position.y + offsetFix)
} }
let (snappedTopInset, snapToBoundsOffset) = self.snapToBounds(snapTopItem: scrollToItem != nil, stackFromBottom: self.stackFromBottom, updateSizeAndInsets: updateSizeAndInsets) let (snappedTopInset, snapToBoundsOffset) = self.snapToBounds(snapTopItem: scrollToItem != nil, stackFromBottom: self.stackFromBottom, updateSizeAndInsets: updateSizeAndInsets, isExperimentalSnapToScrollToItem: isExperimentalSnapToScrollToItem)
if !snappedTopInset.isZero && (previousVisibleSize.height.isZero || previousApparentFrames.isEmpty) { if !snappedTopInset.isZero && (previousVisibleSize.height.isZero || previousApparentFrames.isEmpty) {
offsetFix += snappedTopInset offsetFix += snappedTopInset
@ -2504,7 +2506,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
sizeAndInsetsOffset = offsetFix sizeAndInsetsOffset = offsetFix
completeOffset += snapToBoundsOffset completeOffset += snapToBoundsOffset
if !updateSizeAndInsets.duration.isZero { if !updateSizeAndInsets.duration.isZero && !isExperimentalSnapToScrollToItem {
let animation: CABasicAnimation let animation: CABasicAnimation
switch updateSizeAndInsets.curve { switch updateSizeAndInsets.curve {
case let .Spring(duration): case let .Spring(duration):

View File

@ -54,6 +54,5 @@ final class CachedPeerDataTable: Table {
} }
self.updatedPeerIds.removeAll() self.updatedPeerIds.removeAll()
self.cachedDatas.removeAll()
} }
} }

View File

@ -143,7 +143,6 @@ private final class HistoryPreloadViewContext {
private enum ChatHistoryPreloadEntity: Hashable { private enum ChatHistoryPreloadEntity: Hashable {
case peer(PeerId) case peer(PeerId)
//case group(PeerGroupId)
} }
private struct ChatHistoryPreloadIndex { private struct ChatHistoryPreloadIndex {
@ -317,7 +316,9 @@ final class ChatHistoryPreloadManager {
return return
} }
#if DEBUG #if DEBUG
//return; if true {
//return
}
#endif #endif
var indices: [(ChatHistoryPreloadIndex, Bool, Bool)] = [] var indices: [(ChatHistoryPreloadIndex, Bool, Bool)] = []
for entry in view.0.entries { for entry in view.0.entries {