This commit is contained in:
Ilya Laktyushin 2020-03-26 03:08:02 +04:00
parent 16d3b66f64
commit 25f654389a
3 changed files with 50 additions and 28 deletions

View File

@ -158,7 +158,9 @@ class PieChartComponentController: GeneralChartComponentController {
visible: true)], visible: true)],
totalValue: nil, totalValue: nil,
tapAction: nil, tapAction: nil,
hideAction: nil) hideAction: { [weak self] in
self?.deselectSegment(completion: {})
})
return viewModel return viewModel
} }

View File

@ -205,7 +205,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
if let telegramDice = self.telegramDice, let diceNode = self.animationNode as? ManagedDiceAnimationNode { if let telegramDice = self.telegramDice, let diceNode = self.animationNode as? ManagedDiceAnimationNode {
if let value = telegramDice.value { if let value = telegramDice.value {
diceNode.setState(value == 0 ? .rolling : .value(value)) diceNode.setState(value == 0 ? .rolling : .value(value, true))
} else { } else {
diceNode.setState(.rolling) diceNode.setState(.rolling)
} }
@ -1169,6 +1169,13 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
super.animateInsertion(currentTimestamp, duration: duration, short: short) super.animateInsertion(currentTimestamp, duration: duration, short: short)
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
if let telegramDice = self.telegramDice, let diceNode = self.animationNode as? ManagedDiceAnimationNode, let item = self.item, item.message.effectivelyIncoming(item.context.account.peerId) {
if let value = telegramDice.value, value != 0 {
diceNode.setState(.rolling)
diceNode.setState(.value(value, false))
}
}
} }
override func animateRemoved(_ currentTimestamp: Double, duration: Double) { override func animateRemoved(_ currentTimestamp: Double, duration: Double) {

View File

@ -10,7 +10,7 @@ import ManagedAnimationNode
enum ManagedDiceAnimationState: Equatable { enum ManagedDiceAnimationState: Equatable {
case rolling case rolling
case value(Int32) case value(Int32, Bool)
} }
final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStickerNode { final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStickerNode {
@ -25,8 +25,6 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
self.emojis = emojis self.emojis = emojis
super.init(size: CGSize(width: 184.0, height: 184.0)) super.init(size: CGSize(width: 184.0, height: 184.0))
self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true))
} }
deinit { deinit {
@ -41,7 +39,7 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
switch previousState { switch previousState {
case .rolling: case .rolling:
switch diceState { switch diceState {
case let .value(value): case let .value(value, _):
guard self.emojis.count == 6 else { guard self.emojis.count == 6 else {
return return
} }
@ -65,7 +63,7 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
} }
} }
self.disposable.set(sticker.start(next: { [weak self] data in self.disposable.set((sticker |> deliverOnMainQueue).start(next: { [weak self] data in
if let strongSelf = self { if let strongSelf = self {
strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0)) strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0))
} }
@ -83,11 +81,21 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
} }
} else { } else {
switch diceState { switch diceState {
case let .value(value): case let .value(value, immediate):
guard self.emojis.count == 6 else { guard self.emojis.count == 6 else {
return return
} }
let file = self.emojis[Int(value) - 1] let file = self.emojis[Int(value) - 1]
if let _ = self.context.account.postbox.mediaBox.completedResourcePath(file.resource) {
if immediate {
self.trackTo(item: ManagedAnimationItem(source: .resource(self.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 180, endFrame: 180), duration: 0.0))
} else {
self.trackTo(item: ManagedAnimationItem(source: .resource(self.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0))
}
} else {
self.setState(.rolling)
let dimensions = file.dimensions ?? PixelDimensions(width: 512, height: 512) let dimensions = file.dimensions ?? PixelDimensions(width: 512, height: 512)
let fittedSize = dimensions.cgSize.aspectFilled(CGSize(width: 384.0, height: 384.0)) let fittedSize = dimensions.cgSize.aspectFilled(CGSize(width: 384.0, height: 384.0))
@ -107,11 +115,16 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick
} }
} }
self.disposable.set(sticker.start(next: { [weak self] data in self.disposable.set((sticker |> deliverOnMainQueue).start(next: { [weak self] data in
if let strongSelf = self { if let strongSelf = self {
if immediate {
strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 180, endFrame: 180), duration: 0.0))
} else {
strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0)) strongSelf.trackTo(item: ManagedAnimationItem(source: .resource(strongSelf.context.account.postbox.mediaBox, file.resource), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0))
} }
}
})) }))
}
case .rolling: case .rolling:
self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true)) self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true))
} }