diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift index 301911f640..83807f7af9 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift @@ -57,33 +57,40 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController { super.setupChartCollection(chartsCollection: chartsCollection, animated: animated, isZoomed: isZoomed) for (index, controller) in self.graphControllers.enumerated() { - let chart = chartsCollection.chartValues[index] - let initialComponents = [BarChartRenderer.BarsData.Component(color: chart.color, - values: chart.values.map { CGFloat($0) })] - let (width, chartBars, totalHorizontalRange, totalVerticalRange) = BarChartRenderer.BarsData.initialComponents(chartsCollection: chartsCollection, separate: true, initialComponents: initialComponents) - controller.chartBars = chartBars - controller.verticalScalesRenderer.labelsColor = chart.color - controller.barsWidth = width - controller.totalVerticalRange = totalVerticalRange - self.totalHorizontalRange = totalHorizontalRange - - var bullets: [LineBulletsRenderer.Bullet] = [] - if let component = chartBars.components.first { - for i in 0 ..< chartBars.locations.count { - let location = chartBars.locations[i] - let value = component.values[i] - bullets.append(LineBulletsRenderer.Bullet(coordinate: CGPoint(x: location, y: value), offset: .zero, color: component.color)) + if index < chartsCollection.chartValues.count { + let chart = chartsCollection.chartValues[index] + let initialComponents = [BarChartRenderer.BarsData.Component(color: chart.color, + values: chart.values.map { CGFloat($0) })] + let (width, chartBars, totalHorizontalRange, totalVerticalRange) = BarChartRenderer.BarsData.initialComponents(chartsCollection: chartsCollection, separate: true, initialComponents: initialComponents) + controller.chartBars = chartBars + controller.verticalScalesRenderer.labelsColor = chart.color + controller.barsWidth = width + controller.totalVerticalRange = totalVerticalRange + self.totalHorizontalRange = totalHorizontalRange + + var bullets: [LineBulletsRenderer.Bullet] = [] + if let component = chartBars.components.first { + for i in 0 ..< chartBars.locations.count { + let location = chartBars.locations[i] + let value = component.values[i] + bullets.append(LineBulletsRenderer.Bullet(coordinate: CGPoint(x: location, y: value), offset: .zero, color: component.color)) + } } + + controller.lineBulletsRenderer.bullets = bullets + controller.previewBarsRenderer.setup(horizontalRange: self.totalHorizontalRange, animated: animated) + controller.previewBarsRenderer.setup(verticalRange: controller.totalVerticalRange, animated: animated) + controller.mainBarsRenderer.bars = chartBars + controller.previewBarsRenderer.bars = chartBars + + controller.verticalScalesRenderer.setHorizontalLinesVisible((index == 0), animated: animated) + controller.verticalScalesRenderer.isRightAligned = (index != 0) + controller.verticalScalesRenderer.isEnabled = true + } else { + controller.mainBarsRenderer.bars = BarChartRenderer.BarsData(barWidth: 0.0, locations: [], components: []) + controller.previewBarsRenderer.bars = BarChartRenderer.BarsData(barWidth: 0.0, locations: [], components: []) + controller.verticalScalesRenderer.setHorizontalLinesVisible(false, animated: animated) } - - controller.lineBulletsRenderer.bullets = bullets - controller.previewBarsRenderer.setup(horizontalRange: self.totalHorizontalRange, animated: animated) - controller.previewBarsRenderer.setup(verticalRange: controller.totalVerticalRange, animated: animated) - controller.mainBarsRenderer.bars = chartBars - controller.previewBarsRenderer.bars = chartBars - - controller.verticalScalesRenderer.setHorizontalLinesVisible((index == 0), animated: animated) - controller.verticalScalesRenderer.isRightAligned = (index != 0) } self.prevoiusHorizontalStrideInterval = -1 @@ -149,7 +156,9 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController { let chartFrame = self.chartFrame() guard chartFrame.width > 0 else { return } - let dateToFind = Date(timeIntervalSince1970: TimeInterval(horizontalRange.distance * point.x + horizontalRange.lowerBound)) + let barsWidth = graphControllers.first?.barsWidth ?? 0.0 + + let dateToFind = Date(timeIntervalSince1970: TimeInterval(horizontalRange.distance * point.x + horizontalRange.lowerBound + barsWidth / 2.0)) guard let (closestDate, minIndex) = findClosestDateTo(dateToFind: dateToFind) else { return } let chartInteractionWasBegin = isChartInteractionBegun diff --git a/submodules/ManagedAnimationNode/Sources/ManagedAnimationNode.swift b/submodules/ManagedAnimationNode/Sources/ManagedAnimationNode.swift index b339250107..e9648d979c 100644 --- a/submodules/ManagedAnimationNode/Sources/ManagedAnimationNode.swift +++ b/submodules/ManagedAnimationNode/Sources/ManagedAnimationNode.swift @@ -220,8 +220,13 @@ open class ManagedAnimationNode: ASDisplayNode { state.relativeTime += animationAdvancement if state.relativeTime >= duration && !self.didTryAdvancingState { - self.didTryAdvancingState = true - self.advanceState() + if state.item.loop && self.trackStack.isEmpty { + state.frameIndex = nil + state.relativeTime = 0.0 + } else { + self.didTryAdvancingState = true + self.advanceState() + } } } diff --git a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift index 48e6b8bf9a..e7fe454efd 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift @@ -148,7 +148,12 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { } private func setupNode(item: ChatMessageItem) { - if let telegramDice = self.telegramDice, let diceEmojis = item.associatedData.animatedEmojiStickers["🎲"] { + guard self.animationNode == nil else { + return + } + + if let _ = self.telegramDice { + let diceEmojis = item.associatedData.animatedEmojiStickers["🎲"] ?? [] let animationNode = ManagedDiceAnimationNode(context: item.context, emojis: diceEmojis.map { $0.file }) self.animationNode = animationNode } else { diff --git a/submodules/TelegramUI/Sources/ManagedDiceAnimationNode.swift b/submodules/TelegramUI/Sources/ManagedDiceAnimationNode.swift index 36e1169c7a..969a7d0a84 100644 --- a/submodules/TelegramUI/Sources/ManagedDiceAnimationNode.swift +++ b/submodules/TelegramUI/Sources/ManagedDiceAnimationNode.swift @@ -26,7 +26,7 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick super.init(size: CGSize(width: 136.0, height: 136.0)) - self.trackTo(item: ManagedAnimationItem(source: .local("DiceRolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 0), duration: 0.3)) + self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true)) } deinit { @@ -42,6 +42,9 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick case .rolling: switch diceState { case let .value(value): + guard self.emojis.count == 6 else { + return + } let file = self.emojis[Int(value) - 1] let dimensions = file.dimensions ?? PixelDimensions(width: 512, height: 512) let fittedSize = dimensions.cgSize.aspectFilled(CGSize(width: 384.0, height: 384.0)) @@ -73,7 +76,7 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick case let .value(currentValue): switch diceState { case .rolling: - self.trackTo(item: ManagedAnimationItem(source: .local("DiceRolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 180), duration: 3.0, loop: true)) + self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true)) case let .value(value): break } @@ -81,6 +84,9 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick } else { switch diceState { case let .value(value): + guard self.emojis.count == 6 else { + return + } let file = self.emojis[Int(value) - 1] let dimensions = file.dimensions ?? PixelDimensions(width: 512, height: 512) let fittedSize = dimensions.cgSize.aspectFilled(CGSize(width: 384.0, height: 384.0)) @@ -107,7 +113,7 @@ final class ManagedDiceAnimationNode: ManagedAnimationNode, GenericAnimatedStick } })) case .rolling: - self.trackTo(item: ManagedAnimationItem(source: .local("DiceRolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 0), duration: 0.3, loop: true)) + self.trackTo(item: ManagedAnimationItem(source: .local("Dice_Rolling"), frames: ManagedAnimationFrameRange(startFrame: 0, endFrame: 60), duration: 1.0, loop: true)) } } }