Update loop count

This commit is contained in:
Ali 2021-02-11 19:26:29 +04:00
parent 3a8ded1639
commit 1cbe7cdd29
2 changed files with 20 additions and 2 deletions

View File

@ -60,6 +60,7 @@ public enum AnimatedStickerPlaybackPosition {
public enum AnimatedStickerPlaybackMode {
case once
case count(Int)
case loop
case still(AnimatedStickerPlaybackPosition)
}
@ -757,6 +758,7 @@ public final class AnimatedStickerNode: ASDisplayNode {
private var renderer: (AnimationRenderer & ASDisplayNode)?
public var isPlaying: Bool = false
private var currentLoopCount: Int = 0
private var canDisplayFirstFrame: Bool = false
private var playbackMode: AnimatedStickerPlaybackMode = .loop
@ -910,8 +912,14 @@ public final class AnimatedStickerNode: ASDisplayNode {
private var isSetUpForPlayback = false
public func play(firstFrame: Bool = false) {
if case .once = self.playbackMode {
switch self.playbackMode {
case .once:
self.isPlaying = true
case .count:
self.currentLoopCount = 0
self.isPlaying = true
default:
break
}
if self.isSetUpForPlayback {
let directData = self.directData
@ -976,6 +984,11 @@ public final class AnimatedStickerNode: ASDisplayNode {
var stopNow = false
if case .once = strongSelf.playbackMode {
stopNow = true
} else if case let .count(count) = strongSelf.playbackMode {
strongSelf.currentLoopCount += 1
if count <= strongSelf.currentLoopCount {
stopNow = true
}
} else if strongSelf.stopAtNearestLoop {
stopNow = true
}
@ -1061,6 +1074,11 @@ public final class AnimatedStickerNode: ASDisplayNode {
var stopNow = false
if case .once = strongSelf.playbackMode {
stopNow = true
} else if case let .count(count) = strongSelf.playbackMode {
strongSelf.currentLoopCount += 1
if count <= strongSelf.currentLoopCount {
stopNow = true
}
} else if strongSelf.stopAtNearestLoop {
stopNow = true
}

View File

@ -126,7 +126,7 @@ class ChatListFilterSettingsHeaderItemNode: ListViewItemNode {
animationName = "MessageAutoRemove"
size = 260
insetDifference = 120
playbackMode = .once
playbackMode = .count(2)
additionalBottomInset = isHidden ? 8.0 : 16.0
}