Use velocity when switching sticker packs in preview

This commit is contained in:
Ali 2019-12-07 01:06:17 +04:00
parent a9e36a8c55
commit a5a87436dd

View File

@ -639,9 +639,13 @@ private final class StickerPackScreenNode: ViewControllerTracingNode {
} }
case .ended, .cancelled: case .ended, .cancelled:
let translation = recognizer.translation(in: self.view) let translation = recognizer.translation(in: self.view)
let velocity = recognizer.velocity(in: self.view)
if abs(translation.x) > 30.0 { if abs(translation.x) > 30.0 {
let deltaIndex = translation.x > 0 ? -1 : 1 let deltaIndex = translation.x > 0 ? -1 : 1
self.selectedStickerPackIndex = max(0, min(self.containers.count - 1, Int(self.selectedStickerPackIndex + deltaIndex))) self.selectedStickerPackIndex = max(0, min(self.containers.count - 1, Int(self.selectedStickerPackIndex + deltaIndex)))
} else if abs(velocity.x) > 100.0 {
let deltaIndex = velocity.x > 0 ? -1 : 1
self.selectedStickerPackIndex = max(0, min(self.containers.count - 1, Int(self.selectedStickerPackIndex + deltaIndex)))
} }
self.relativeToSelectedStickerPackTransition = 0.0 self.relativeToSelectedStickerPackTransition = 0.0
if let layout = self.validLayout { if let layout = self.validLayout {