mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 13:38:21 +00:00
Fix autoscroll correction
This commit is contained in:
parent
f9ddb6ade8
commit
65f95b66ad
@ -90,13 +90,14 @@ private final class StickerPackContainer: ASDisplayNode {
|
|||||||
var expandProgress: CGFloat = 0.0
|
var expandProgress: CGFloat = 0.0
|
||||||
var expandScrollProgress: CGFloat = 0.0
|
var expandScrollProgress: CGFloat = 0.0
|
||||||
var modalProgress: CGFloat = 0.0
|
var modalProgress: CGFloat = 0.0
|
||||||
let expandProgressUpdated: (StickerPackContainer, ContainedViewLayoutTransition) -> Void
|
var isAnimatingAutoscroll: Bool = false
|
||||||
|
let expandProgressUpdated: (StickerPackContainer, ContainedViewLayoutTransition, ContainedViewLayoutTransition) -> Void
|
||||||
|
|
||||||
private var isDismissed: Bool = false
|
private var isDismissed: Bool = false
|
||||||
|
|
||||||
private let interaction: StickerPackPreviewInteraction
|
private let interaction: StickerPackPreviewInteraction
|
||||||
|
|
||||||
init(index: Int, context: AccountContext, presentationData: PresentationData, stickerPack: StickerPackReference, decideNextAction: @escaping (StickerPackContainer, StickerPackAction) -> StickerPackNextAction, requestDismiss: @escaping () -> Void, expandProgressUpdated: @escaping (StickerPackContainer, ContainedViewLayoutTransition) -> Void, presentInGlobalOverlay: @escaping (ViewController, Any?) -> Void, sendSticker: ((FileMediaReference, ASDisplayNode, CGRect) -> Bool)?) {
|
init(index: Int, context: AccountContext, presentationData: PresentationData, stickerPack: StickerPackReference, decideNextAction: @escaping (StickerPackContainer, StickerPackAction) -> StickerPackNextAction, requestDismiss: @escaping () -> Void, expandProgressUpdated: @escaping (StickerPackContainer, ContainedViewLayoutTransition, ContainedViewLayoutTransition) -> Void, presentInGlobalOverlay: @escaping (ViewController, Any?) -> Void, sendSticker: ((FileMediaReference, ASDisplayNode, CGRect) -> Bool)?) {
|
||||||
self.index = index
|
self.index = index
|
||||||
self.context = context
|
self.context = context
|
||||||
self.presentationData = presentationData
|
self.presentationData = presentationData
|
||||||
@ -201,7 +202,7 @@ private final class StickerPackContainer: ASDisplayNode {
|
|||||||
resetOffset = true
|
resetOffset = true
|
||||||
}
|
}
|
||||||
strongSelf.modalProgress = modalProgress
|
strongSelf.modalProgress = modalProgress
|
||||||
strongSelf.expandProgressUpdated(strongSelf, .animated(duration: 0.4, curve: .spring))
|
strongSelf.expandProgressUpdated(strongSelf, .animated(duration: 0.4, curve: .spring), .immediate)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resetOffset {
|
if resetOffset {
|
||||||
@ -228,7 +229,9 @@ private final class StickerPackContainer: ASDisplayNode {
|
|||||||
duration = 0.5
|
duration = 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strongSelf.isAnimatingAutoscroll = true
|
||||||
strongSelf.gridNode.autoscroll(toOffset: offset, duration: duration)
|
strongSelf.gridNode.autoscroll(toOffset: offset, duration: duration)
|
||||||
|
strongSelf.isAnimatingAutoscroll = false
|
||||||
}
|
}
|
||||||
updatedOffset = contentOffset
|
updatedOffset = contentOffset
|
||||||
}
|
}
|
||||||
@ -505,7 +508,13 @@ private final class StickerPackContainer: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let contentOffset = (1.0 - expandScrollProgress) * (-gridInsets.top)
|
let contentOffset = (1.0 - expandScrollProgress) * (-gridInsets.top)
|
||||||
self.gridNode.scrollView.setContentOffset(CGPoint(x: 0.0, y: contentOffset), animated: false)
|
if case let .animated(duration, _) = transition {
|
||||||
|
self.gridNode.autoscroll(toOffset: CGPoint(x: 0.0, y: contentOffset), duration: duration)
|
||||||
|
} else {
|
||||||
|
if expandScrollProgress.isZero {
|
||||||
|
}
|
||||||
|
self.gridNode.scrollView.setContentOffset(CGPoint(x: 0.0, y: contentOffset), animated: false)
|
||||||
|
}
|
||||||
|
|
||||||
self.expandScrollProgress = expandScrollProgress
|
self.expandScrollProgress = expandScrollProgress
|
||||||
self.expandProgress = expandProgress
|
self.expandProgress = expandProgress
|
||||||
@ -602,7 +611,7 @@ private final class StickerPackContainer: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if expandUpdated {
|
if expandUpdated {
|
||||||
self.expandProgressUpdated(self, expandProgressTransition)
|
self.expandProgressUpdated(self, expandProgressTransition, self.isAnimatingAutoscroll ? transition : .immediate)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !transition.isAnimated {
|
if !transition.isAnimated {
|
||||||
@ -742,10 +751,12 @@ private final class StickerPackScreenNode: ViewControllerTracingNode {
|
|||||||
if abs(indexOffset) <= 1 {
|
if abs(indexOffset) <= 1 {
|
||||||
let containerTransition: ContainedViewLayoutTransition
|
let containerTransition: ContainedViewLayoutTransition
|
||||||
let container: StickerPackContainer
|
let container: StickerPackContainer
|
||||||
|
var wasAdded = false
|
||||||
if let current = self.containers[i] {
|
if let current = self.containers[i] {
|
||||||
containerTransition = transition
|
containerTransition = transition
|
||||||
container = current
|
container = current
|
||||||
} else {
|
} else {
|
||||||
|
wasAdded = true
|
||||||
containerTransition = .immediate
|
containerTransition = .immediate
|
||||||
let index = i
|
let index = i
|
||||||
container = StickerPackContainer(index: index, context: context, presentationData: self.presentationData, stickerPack: self.stickerPacks[i], decideNextAction: { [weak self] container, action in
|
container = StickerPackContainer(index: index, context: context, presentationData: self.presentationData, stickerPack: self.stickerPacks[i], decideNextAction: { [weak self] container, action in
|
||||||
@ -782,17 +793,17 @@ private final class StickerPackScreenNode: ViewControllerTracingNode {
|
|||||||
return .navigatedNext
|
return .navigatedNext
|
||||||
}, requestDismiss: { [weak self] in
|
}, requestDismiss: { [weak self] in
|
||||||
self?.dismiss()
|
self?.dismiss()
|
||||||
}, expandProgressUpdated: { [weak self] container, transition in
|
}, expandProgressUpdated: { [weak self] container, transition, expandTransition in
|
||||||
guard let strongSelf = self, let layout = strongSelf.validLayout else {
|
guard let strongSelf = self, let layout = strongSelf.validLayout else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if index == strongSelf.selectedStickerPackIndex, let container = strongSelf.containers[strongSelf.selectedStickerPackIndex] {
|
if index == strongSelf.selectedStickerPackIndex, let container = strongSelf.containers[strongSelf.selectedStickerPackIndex] {
|
||||||
let modalProgress = container.modalProgress
|
let modalProgress = container.modalProgress
|
||||||
strongSelf.modalProgressUpdated(modalProgress, transition)
|
strongSelf.modalProgressUpdated(modalProgress, transition)
|
||||||
strongSelf.containerLayoutUpdated(layout, transition: .immediate)
|
strongSelf.containerLayoutUpdated(layout, transition: expandTransition)
|
||||||
for (otherIndex, otherContainer) in strongSelf.containers {
|
for (otherIndex, otherContainer) in strongSelf.containers {
|
||||||
if otherContainer !== container {
|
if otherContainer !== container {
|
||||||
otherContainer.syncExpandProgress(expandScrollProgress: container.expandScrollProgress, expandProgress: container.expandProgress, modalProgress: container.modalProgress, transition: .immediate)
|
otherContainer.syncExpandProgress(expandScrollProgress: container.expandScrollProgress, expandProgress: container.expandProgress, modalProgress: container.modalProgress, transition: expandTransition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -809,9 +820,11 @@ private final class StickerPackScreenNode: ViewControllerTracingNode {
|
|||||||
container.updateLayout(layout: layout, transition: containerTransition)
|
container.updateLayout(layout: layout, transition: containerTransition)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let selectedContainer = self.containers[self.selectedStickerPackIndex] {
|
if wasAdded {
|
||||||
if selectedContainer !== container {
|
if let selectedContainer = self.containers[self.selectedStickerPackIndex] {
|
||||||
container.syncExpandProgress(expandScrollProgress: selectedContainer.expandScrollProgress, expandProgress: selectedContainer.expandProgress, modalProgress: selectedContainer.modalProgress, transition: .immediate)
|
if selectedContainer !== container {
|
||||||
|
container.syncExpandProgress(expandScrollProgress: selectedContainer.expandScrollProgress, expandProgress: selectedContainer.expandProgress, modalProgress: selectedContainer.modalProgress, transition: .immediate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user