diff --git a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift index 73a80f914e..1027606cd9 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift @@ -1044,7 +1044,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo case .groupReference: gesture?.cancel() } - }, present: { [weak self] c in + }, present: { c in present(c) }) self.interaction = interaction diff --git a/submodules/GraphCore/Sources/Charts Reader/ChartVisibilityItem.swift b/submodules/GraphCore/Sources/Charts Reader/ChartVisibilityItem.swift index b2cffc70c8..ec9e9395a7 100644 --- a/submodules/GraphCore/Sources/Charts Reader/ChartVisibilityItem.swift +++ b/submodules/GraphCore/Sources/Charts Reader/ChartVisibilityItem.swift @@ -78,15 +78,17 @@ public struct ChartDetailsViewModel { public internal(set) var title: String public internal(set) var showArrow: Bool public internal(set) var showPrefixes: Bool + public internal(set) var isLoading: Bool public internal(set) var values: [Value] public internal(set) var totalValue: Value? public internal(set) var tapAction: (() -> Void)? public internal(set) var hideAction: (() -> Void)? - static let blank = ChartDetailsViewModel(title: "", showArrow: false, showPrefixes: false, values: [], totalValue: nil, tapAction: nil, hideAction: nil) + static let blank = ChartDetailsViewModel(title: "", showArrow: false, showPrefixes: false, isLoading: false, values: [], totalValue: nil, tapAction: nil, hideAction: nil) public init(title: String, showArrow: Bool, showPrefixes: Bool, + isLoading: Bool, values: [Value], totalValue: Value?, tapAction: (() -> Void)?, @@ -94,6 +96,7 @@ public struct ChartDetailsViewModel { self.title = title self.showArrow = showArrow self.showPrefixes = showPrefixes + self.isLoading = isLoading self.values = values self.totalValue = totalValue self.tapAction = tapAction diff --git a/submodules/GraphCore/Sources/Charts Reader/ChartsCollection.swift b/submodules/GraphCore/Sources/Charts Reader/ChartsCollection.swift index 0ad76449d0..81f6629113 100644 --- a/submodules/GraphCore/Sources/Charts Reader/ChartsCollection.swift +++ b/submodules/GraphCore/Sources/Charts Reader/ChartsCollection.swift @@ -36,7 +36,7 @@ public struct ChartsCollection { } public extension ChartsCollection { - public init(from decodedData: [String: Any]) throws { + init(from decodedData: [String: Any]) throws { guard let columns = decodedData["columns"] as? [[Any]] else { throw ChartsError.generalConversion("Unable to get columns from: \(decodedData)") } diff --git a/submodules/GraphCore/Sources/Charts/Controllers/BaseChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/BaseChartController.swift index bb067c7d8d..ff198f35f6 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/BaseChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/BaseChartController.swift @@ -137,7 +137,7 @@ public class BaseChartController: ChartThemeContainer { } public var isChartRangePagingEnabled: Bool = false - public var minimumSelectedChartRange: CGFloat = 0.05 + public var minimumSelectedChartRange: CGFloat = 0.085 public var chartRangePagingClosure: ((Bool, CGFloat) -> Void)? // isEnabled, PageSize public func setChartRangePagingEnabled(isEnabled: Bool, minimumSelectionSize: CGFloat) { isChartRangePagingEnabled = isEnabled @@ -178,7 +178,7 @@ public class BaseChartController: ChartThemeContainer { public var setBackButtonVisibilityClosure: ((Bool, Bool) -> Void)? public var refreshChartToolsClosure: ((Bool) -> Void)? - public func didTapZoomIn(date: Date) { + public func didTapZoomIn(date: Date, pointIndex: Int) { fatalError("Abstract") } diff --git a/submodules/GraphCore/Sources/Charts/Controllers/GeneralChartComponentController.swift b/submodules/GraphCore/Sources/Charts/Controllers/GeneralChartComponentController.swift index b908e547f8..f9258e0b25 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/GeneralChartComponentController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/GeneralChartComponentController.swift @@ -24,6 +24,7 @@ class GeneralChartComponentController: ChartThemeContainer { var lastChartInteractionPoint: CGPoint = .zero var isChartInteractionBegun: Bool = false var isChartInteracting: Bool = false + var ignoreInteraction: Bool = false let isZoomed: Bool var isZoomable = true @@ -169,6 +170,14 @@ class GeneralChartComponentController: ChartThemeContainer { } func chartInteractionDidBegin(point: CGPoint) { + guard !ignoreInteraction else { + return + } + if !isChartInteractionBegun && detailsVisible { + self.hideDetailsView(animated: true) + ignoreInteraction = true + return + } let chartFrame = self.chartFrame() guard chartFrame.width > 0 else { return } let horizontalRange = currentHorizontalMainChartRange @@ -185,19 +194,24 @@ class GeneralChartComponentController: ChartThemeContainer { showDetailsView(at: chartValue, detailsViewPosition: detailsViewPosition, dataIndex: minIndex, date: closestDate, animted: chartWasInteracting) } + var detailsVisible = false func showDetailsView(at chartPosition: CGFloat, detailsViewPosition: CGFloat, dataIndex: Int, date: Date, animted: Bool) { setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: dataIndex), animted) setDetailsChartVisibleClosure?(true, true) setDetailsViewPositionClosure?(detailsViewPosition) + detailsVisible = true } func chartInteractionDidEnd() { + isChartInteractionBegun = false isChartInteracting = false + ignoreInteraction = false } func hideDetailsView(animated: Bool) { isChartInteractionBegun = false setDetailsChartVisibleClosure?(false, animated) + detailsVisible = false } var visibleDetailsChartValues: [ChartsCollection.Chart] { @@ -323,13 +337,13 @@ class GeneralChartComponentController: ChartThemeContainer { let viewModel = ChartDetailsViewModel(title: dateString, showArrow: self.isZoomable && !self.isZoomed, showPrefixes: false, + isLoading: false, values: values, totalValue: nil, tapAction: { [weak self] in self?.zoomInOnDateClosure?(closestDate) }, hideAction: { [weak self] in self?.setDetailsChartVisibleClosure?(false, true) - }) return viewModel } @@ -338,11 +352,11 @@ class GeneralChartComponentController: ChartThemeContainer { let fromDate = Date(timeIntervalSince1970: TimeInterval(currentHorizontalMainChartRange.lowerBound) + 1) let toDate = Date(timeIntervalSince1970: TimeInterval(currentHorizontalMainChartRange.upperBound)) if Calendar.utc.startOfDay(for: fromDate) == Calendar.utc.startOfDay(for: toDate) { - let stirng = BaseConstants.headerFullZoomedFormatter.string(from: fromDate) - self.setChartTitleClosure?(stirng, animated) + let string = BaseConstants.headerFullZoomedFormatter.string(from: fromDate) + self.setChartTitleClosure?(string, animated) } else { - let stirng = "\(BaseConstants.headerMediumRangeFormatter.string(from: fromDate)) - \(BaseConstants.headerMediumRangeFormatter.string(from: toDate))" - self.setChartTitleClosure?(stirng, animated) + let string = "\(BaseConstants.headerMediumRangeFormatter.string(from: fromDate)) - \(BaseConstants.headerMediumRangeFormatter.string(from: toDate))" + self.setChartTitleClosure?(string, animated) } } } diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Lines/BaseLinesChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Lines/BaseLinesChartController.swift index 659acd35bb..5c11096d38 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Lines/BaseLinesChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Lines/BaseLinesChartController.swift @@ -18,6 +18,7 @@ public class BaseLinesChartController: BaseChartController { var zoomChartVisibility: [Bool] var lastChartInteractionPoint: CGPoint = .zero var isChartInteractionBegun: Bool = false + var ignoreInteraction: Bool = false var initialChartRange: ClosedRange = BaseConstants.defaultRange var zoomedChartRange: ClosedRange = BaseConstants.defaultRange @@ -71,7 +72,8 @@ public class BaseLinesChartController: BaseChartController { } public override func chartInteractionDidEnd() { - + isChartInteractionBegun = false + ignoreInteraction = false } public override func cancelChartInteraction() { @@ -98,7 +100,7 @@ public class BaseLinesChartController: BaseChartController { } - func chartDetailsViewModel(closestDate: Date, pointIndex: Int) -> ChartDetailsViewModel { + func chartDetailsViewModel(closestDate: Date, pointIndex: Int, loading: Bool) -> ChartDetailsViewModel { let values: [ChartDetailsViewModel.Value] = actualChartsCollection.chartValues.enumerated().map { arg in let (index, component) = arg return ChartDetailsViewModel.Value(prefix: nil, @@ -118,20 +120,25 @@ public class BaseLinesChartController: BaseChartController { let viewModel = ChartDetailsViewModel(title: dateString, showArrow: total > 0 && self.isZoomable && !self.isZoomed, showPrefixes: false, + isLoading: loading, values: values, totalValue: nil, - tapAction: { [weak self] in self?.didTapZoomIn(date: closestDate) }, - hideAction: { [weak self] in - self?.setDetailsChartVisibleClosure?(false, true) + tapAction: { [weak self] in + self?.didTapZoomIn(date: closestDate, pointIndex: pointIndex) + }, hideAction: { [weak self] in + self?.cancelChartInteraction() }) return viewModel } - public override func didTapZoomIn(date: Date) { + public override func didTapZoomIn(date: Date, pointIndex: Int) { guard isZoomed == false else { return } - cancelChartInteraction() + + setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: pointIndex, loading: true), false) + self.getDetailsData?(date, { updatedCollection in if let updatedCollection = updatedCollection { + self.cancelChartInteraction() self.initialChartRange = self.currentHorizontalRange if let startDate = updatedCollection.axisValues.first, let endDate = updatedCollection.axisValues.last { diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Lines/GeneralLinesChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Lines/GeneralLinesChartController.swift index e3de9d1f45..2cd79e5f55 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Lines/GeneralLinesChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Lines/GeneralLinesChartController.swift @@ -122,14 +122,22 @@ public class GeneralLinesChartController: BaseLinesChartController { } public override func chartInteractionDidBegin(point: CGPoint) { + guard !ignoreInteraction else { + return + } + if !isChartInteractionBegun && !self.verticalLineRenderer.values.isEmpty { + self.cancelChartInteraction() + ignoreInteraction = true + return + } let horizontalRange = mainLinesRenderer.horizontalRange.current let chartFrame = self.chartFrame() guard chartFrame.width > 0 else { return } - let chartInteractionWasBegin = isChartInteractionBegun let dateToFind = Date(timeIntervalSince1970: TimeInterval(horizontalRange.distance * point.x + horizontalRange.lowerBound)) guard let (closestDate, minIndex) = findClosestDateTo(dateToFind: dateToFind) else { return } + let chartInteractionWasBegin = isChartInteractionBegun super.chartInteractionDidBegin(point: point) self.lineBulletsRenderer.bullets = chartLines.compactMap { chart in @@ -139,7 +147,7 @@ public class GeneralLinesChartController: BaseLinesChartController { let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970) let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX - self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex), chartInteractionWasBegin) + self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex, loading: false), chartInteractionWasBegin) self.setDetailsChartVisibleClosure?(true, true) self.setDetailsViewPositionClosure?(detailsViewPosition) self.verticalLineRenderer.values = [chartValue] diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Lines/TwoAxisLinesChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Lines/TwoAxisLinesChartController.swift index 145662acb1..2e6984bbeb 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Lines/TwoAxisLinesChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Lines/TwoAxisLinesChartController.swift @@ -149,6 +149,14 @@ public class TwoAxisLinesChartController: BaseLinesChartController { } public override func chartInteractionDidBegin(point: CGPoint) { + guard !ignoreInteraction else { + return + } + if !isChartInteractionBegun && !self.verticalLineRenderer.values.isEmpty { + self.cancelChartInteraction() + ignoreInteraction = true + return + } let horizontalRange = currentHorizontalRange let chartFrame = self.chartFrame() guard chartFrame.width > 0 else { return } @@ -168,7 +176,7 @@ public class TwoAxisLinesChartController: BaseLinesChartController { let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970) let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX - self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex), chartInteractionWasBegin) + self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex, loading: false), chartInteractionWasBegin) self.setDetailsChartVisibleClosure?(true, true) self.setDetailsViewPositionClosure?(detailsViewPosition) self.verticalLineRenderer.values = [chartValue] diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentChartComponentController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentChartComponentController.swift index 74e653ed86..2b723dc748 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentChartComponentController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentChartComponentController.swift @@ -153,6 +153,7 @@ class PercentChartComponentController: GeneralChartComponentController { let viewModel = ChartDetailsViewModel(title: dateString, showArrow: total > 0 && self.isZoomable && !self.isZoomed, showPrefixes: true, + isLoading: false, values: values, totalValue: nil, tapAction: { [weak self] in diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentPieChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentPieChartController.swift index ba15c7dc2b..fd1c00c333 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentPieChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentPieChartController.swift @@ -48,7 +48,7 @@ public class PercentPieChartController: BaseChartController { controller.chartFrame = { [unowned self] in self.chartFrame() } controller.cartViewBounds = { [unowned self] in self.cartViewBounds() } controller.zoomInOnDateClosure = { [unowned self] date in - self.didTapZoomIn(date: date) + self.didTapZoomIn(date: date, pointIndex: 0) } controller.setChartTitleClosure = { [unowned self] (title, animated) in self.setChartTitleClosure?(title, animated) @@ -272,7 +272,7 @@ public class PercentPieChartController: BaseChartController { switchToChart(chartsCollection: newCollection, isZoomed: true, animated: true) } - public override func didTapZoomIn(date: Date) { + public override func didTapZoomIn(date: Date, pointIndex: Int) { self.didTapZoomIn(date: date, animated: true) } diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PieChartComponentController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PieChartComponentController.swift index 1cd7aa4ce4..325925d78f 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PieChartComponentController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PieChartComponentController.swift @@ -150,6 +150,7 @@ class PieChartComponentController: GeneralChartComponentController { let viewModel = ChartDetailsViewModel(title: "", showArrow: false, showPrefixes: false, + isLoading: false, values: [ChartDetailsViewModel.Value(prefix: nil, title: title, value: valueString, diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/DailyBarsChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/DailyBarsChartController.swift index a2a66b00f5..33853a86f6 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/DailyBarsChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/DailyBarsChartController.swift @@ -40,7 +40,7 @@ public class DailyBarsChartController: BaseChartController { controller.chartFrame = { [unowned self] in self.chartFrame() } controller.cartViewBounds = { [unowned self] in self.cartViewBounds() } controller.zoomInOnDateClosure = { [unowned self] date in - self.didTapZoomIn(date: date) + self.didTapZoomIn(date: date, pointIndex: 0) } controller.setChartTitleClosure = { [unowned self] (title, animated) in self.setChartTitleClosure?(title, animated) @@ -205,7 +205,7 @@ public class DailyBarsChartController: BaseChartController { } } - public override func didTapZoomIn(date: Date) { + public override func didTapZoomIn(date: Date, pointIndex: Int) { guard isZoomed == false else { return } if isZoomed { return linesController.hideDetailsView(animated: true) diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StackedBarsChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StackedBarsChartController.swift index ef9784db36..394b5785b3 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StackedBarsChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StackedBarsChartController.swift @@ -43,7 +43,7 @@ public class StackedBarsChartController: BaseChartController { controller.chartFrame = { [unowned self] in self.chartFrame() } controller.cartViewBounds = { [unowned self] in self.cartViewBounds() } controller.zoomInOnDateClosure = { [unowned self] date in - self.didTapZoomIn(date: date) + self.didTapZoomIn(date: date, pointIndex: 0) } controller.setChartTitleClosure = { [unowned self] (title, animated) in self.setChartTitleClosure?(title, animated) @@ -220,7 +220,7 @@ public class StackedBarsChartController: BaseChartController { } } - public override func didTapZoomIn(date: Date) { + public override func didTapZoomIn(date: Date, pointIndex: Int) { guard isZoomed == false else { return } if isZoomed { return zoomedBarsController.hideDetailsView(animated: true) diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StepBarsChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StepBarsChartController.swift index 3780448886..6bd1e79a55 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StepBarsChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StepBarsChartController.swift @@ -43,7 +43,7 @@ public class StepBarsChartController: BaseChartController { controller.chartFrame = { [unowned self] in self.chartFrame() } controller.cartViewBounds = { [unowned self] in self.cartViewBounds() } controller.zoomInOnDateClosure = { [unowned self] date in - self.didTapZoomIn(date: date) + self.didTapZoomIn(date: date, pointIndex: 0) } controller.setChartTitleClosure = { [unowned self] (title, animated) in self.setChartTitleClosure?("", animated) @@ -228,7 +228,7 @@ public class StepBarsChartController: BaseChartController { } } - public override func didTapZoomIn(date: Date) { + public override func didTapZoomIn(date: Date, pointIndex: Int) { guard isZoomed == false else { return } if isZoomed { return zoomedBarsController.hideDetailsView(animated: true) diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift index a1483a51ab..06aec2b00d 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/TwoAxisStepBarsChartController.swift @@ -152,6 +152,15 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController { } public override func chartInteractionDidBegin(point: CGPoint) { + guard !ignoreInteraction else { + return + } + if !isChartInteractionBegun && !self.verticalLineRenderer.values.isEmpty { + self.cancelChartInteraction() + ignoreInteraction = true + return + } + let horizontalRange = currentHorizontalRange let chartFrame = self.chartFrame() guard chartFrame.width > 0 else { return } @@ -183,8 +192,8 @@ public class TwoAxisStepBarsChartController: BaseLinesChartController { } let chartValue: CGFloat = CGFloat(closestDate.timeIntervalSince1970) - let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX - self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex), chartInteractionWasBegin) + let detailsViewPosition = (chartValue - horizontalRange.lowerBound) / horizontalRange.distance * chartFrame.width + chartFrame.minX + barOffset + self.setDetailsViewModel?(chartDetailsViewModel(closestDate: closestDate, pointIndex: minIndex, loading: false), chartInteractionWasBegin) self.setDetailsChartVisibleClosure?(true, true) self.setDetailsViewPositionClosure?(detailsViewPosition) self.verticalLineRenderer.values = [chartValue] diff --git a/submodules/GraphCore/Sources/Charts/Renderes/PieChartRenderer.swift b/submodules/GraphCore/Sources/Charts/Renderes/PieChartRenderer.swift index 8385be2e0e..54d1d193aa 100644 --- a/submodules/GraphCore/Sources/Charts/Renderes/PieChartRenderer.swift +++ b/submodules/GraphCore/Sources/Charts/Renderes/PieChartRenderer.swift @@ -39,6 +39,9 @@ class PieChartRenderer: BaseChartRenderer { } private(set) var selectedSegment: Int? func selectSegmentAt(at indexToSelect: Int?, animated: Bool) { + guard selectedSegment != indexToSelect else { + return + } selectedSegment = indexToSelect for (index, animator) in setlectedSegmentsAnimators.enumerated() { let fraction: CGFloat = (index == indexToSelect) ? 1.0 : 0.0 diff --git a/submodules/GraphUI/Sources/ChartDetailsView.swift b/submodules/GraphUI/Sources/ChartDetailsView.swift index 43ca2f5d38..b0f8cfc1f8 100644 --- a/submodules/GraphUI/Sources/ChartDetailsView.swift +++ b/submodules/GraphUI/Sources/ChartDetailsView.swift @@ -49,6 +49,7 @@ class ChartDetailsView: UIControl { addSubview(titleLabel) addSubview(arrowView) addSubview(arrowButton) + addSubview(activityIndicator) } required init?(coder aDecoder: NSCoder) { @@ -60,21 +61,32 @@ class ChartDetailsView: UIControl { titleLabel.setText(viewModel.title, animated: false) titleLabel.setVisible(!viewModel.title.isEmpty, animated: false) - arrowView.setVisible(viewModel.showArrow, animated: false) - arrowButton.isUserInteractionEnabled = viewModel.showArrow + arrowView.setVisible(viewModel.showArrow && !viewModel.isLoading, animated: false) + arrowButton.isUserInteractionEnabled = viewModel.showArrow && !viewModel.isLoading + self.isEnabled = !viewModel.isLoading + + if viewModel.isLoading { + activityIndicator.isHidden = false + activityIndicator.startAnimating() + } else { + activityIndicator.isHidden = true + activityIndicator.stopAnimating() + } let width: CGFloat = margin * 2 + (viewModel.showPrefixes ? (prefixLabelWidth + margin) : 0) + textLabelWidth + valueLabelWidth var y: CGFloat = verticalMargins if (!viewModel.title.isEmpty || viewModel.showArrow) { titleLabel.frame = CGRect(x: margin, y: y, width: width, height: labelHeight) - arrowView.frame = CGRect(x: width - 6 - margin, y: margin, width: 6, height: 10) + arrowView.frame = CGRect(x: width - 6 - margin, y: margin + 2, width: 6, height: 10) + + activityIndicator.transform = CGAffineTransform(scaleX: 0.65, y: 0.65) + activityIndicator.center = CGPoint(x: width - 3 - margin, y: 16.0) + y += labelHeight } let labelsCount: Int = viewModel.values.count + ((viewModel.totalValue == nil) ? 0 : 1) - arrowButton.frame = CGRect(x: 0.0, y: 0.0, width: width, height: 30.0) - setLabelsCount(array: &prefixViews, count: viewModel.showPrefixes ? labelsCount : 0, font: UIFont.systemFont(ofSize: 12, weight: .bold)) @@ -143,12 +155,13 @@ class ChartDetailsView: UIControl { } }) self.textHeight = textHeight + + arrowButton.frame = CGRect(x: 0.0, y: 0.0, width: width, height: y) } override var intrinsicContentSize: CGSize { if let viewModel = viewModel { var height = ((!viewModel.title.isEmpty || viewModel.showArrow) ? labelHeight : 0) + -// (CGFloat(viewModel.values.filter({ $0.visible }).count) * labelHeight) + (viewModel.totalValue?.visible == true ? labelHeight : 0) + verticalMargins * 2 @@ -206,6 +219,7 @@ extension ChartDetailsView: ChartThemeContainer { } UIView.perform(animated: animated) { self.arrowView.tintColor = theme.chartDetailsArrowColor + self.activityIndicator.color = theme.chartDetailsArrowColor self.backgroundColor = theme.chartDetailsViewColor } } diff --git a/submodules/GraphUI/Sources/ChartNode.swift b/submodules/GraphUI/Sources/ChartNode.swift index d6aee1cc89..60f68dc6ce 100644 --- a/submodules/GraphUI/Sources/ChartNode.swift +++ b/submodules/GraphUI/Sources/ChartNode.swift @@ -57,7 +57,7 @@ public extension ChartTheme { context.addLine(to: CGPoint(x: 110.0, y: 21.0)) context.addLine(to: CGPoint(x: 107.0, y: 25.0)) context.strokePath() - })?.resizableImage(withCapInsets: UIEdgeInsets(top: 15.0, left: 15.0, bottom: 15.0, right: 15.0), resizingMode: .stretch) + })?.resizableImage(withCapInsets: UIEdgeInsets(top: 15.0, left: 11.0, bottom: 15.0, right: 11.0), resizingMode: .stretch) self.init(chartTitleColor: presentationTheme.list.itemPrimaryTextColor, actionButtonColor: presentationTheme.list.itemAccentColor, chartBackgroundColor: presentationTheme.list.itemBlocksBackgroundColor, chartLabelsColor: presentationTheme.chart.labelsColor, chartHelperLinesColor: presentationTheme.chart.helperLinesColor, chartStrongLinesColor: presentationTheme.chart.strongLinesColor, barChartStrongLinesColor: presentationTheme.chart.barStrongLinesColor, chartDetailsTextColor: presentationTheme.chart.detailsTextColor, chartDetailsArrowColor: presentationTheme.chart.detailsArrowColor, chartDetailsViewColor: presentationTheme.chart.detailsViewColor, rangeViewFrameColor: rangeViewFrameColor, rangeViewTintColor: presentationTheme.list.blocksBackgroundColor.withAlphaComponent(0.5), rangeViewMarkerColor: rangeViewMarkerColor, rangeCropImage: rangeImage) } @@ -124,6 +124,10 @@ public final class ChartNode: ASDisplayNode { }) } + required public init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + public func setupTheme(_ theme: ChartTheme) { self.chartView.apply(theme: theme, animated: false) } @@ -136,11 +140,7 @@ public final class ChartNode: ASDisplayNode { self.chartView.setup(controller: controller, displayRange: displayRange) } - public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { - return super.hitTest(point, with: event) - } - - required public init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") + public func resetInteraction() { + self.chartView.resetDetailsView() } } diff --git a/submodules/GraphUI/Sources/ChartStackSection.swift b/submodules/GraphUI/Sources/ChartStackSection.swift index ddca56442d..842b2cb643 100644 --- a/submodules/GraphUI/Sources/ChartStackSection.swift +++ b/submodules/GraphUI/Sources/ChartStackSection.swift @@ -83,6 +83,10 @@ class ChartStackSection: UIView, ChartThemeContainer { backButton.setVisible(false, animated: false) } + public func resetDetailsView() { + controller?.cancelChartInteraction() + } + func apply(theme: ChartTheme, animated: Bool) { self.theme = theme diff --git a/submodules/GraphUI/Sources/ChartView.swift b/submodules/GraphUI/Sources/ChartView.swift index ea4d0730c9..d720ff7b4c 100644 --- a/submodules/GraphUI/Sources/ChartView.swift +++ b/submodules/GraphUI/Sources/ChartView.swift @@ -123,12 +123,12 @@ class ChartView: UIControl { let detailsViewSize = detailsView.intrinsicContentSize maxDetailsViewWidth = max(maxDetailsViewWidth, detailsViewSize.width) if maxDetailsViewWidth + detailsTableLeftOffset > detailsViewPosition { - detailsView.frame = CGRect(x: min(detailsViewPosition + detailsTableLeftOffset, bounds.width - maxDetailsViewWidth), + detailsView.frame = CGRect(x: min(detailsViewPosition + detailsTableLeftOffset, bounds.width - maxDetailsViewWidth - detailsTableLeftOffset), y: chartInsets.top + detailsTableTopOffset, width: maxDetailsViewWidth, height: detailsViewSize.height) } else { - detailsView.frame = CGRect(x: detailsViewPosition - maxDetailsViewWidth - detailsTableLeftOffset, + detailsView.frame = CGRect(x: min(detailsViewPosition - maxDetailsViewWidth - detailsTableLeftOffset, bounds.width - maxDetailsViewWidth - detailsTableLeftOffset), y: chartInsets.top + detailsTableTopOffset, width: maxDetailsViewWidth, height: detailsViewSize.height) diff --git a/submodules/GraphUI/Sources/RangeChartView.swift b/submodules/GraphUI/Sources/RangeChartView.swift index 09188269c0..4f4fec2ba6 100644 --- a/submodules/GraphUI/Sources/RangeChartView.swift +++ b/submodules/GraphUI/Sources/RangeChartView.swift @@ -10,9 +10,9 @@ import GraphCore import AppBundle private enum Constants { - static let cropIndocatorLineWidth: CGFloat = 1 + static let cropIndicatorLineWidth: CGFloat = 1 static let markerSelectionRange: CGFloat = 25 - static let defaultMinimumRangeDistance: CGFloat = 0.05 + static let defaultMinimumRangeDistance: CGFloat = 0.1 static let titntAreaWidth: CGFloat = 10 static let horizontalContentMargin: CGFloat = 16 static let cornerRadius: CGFloat = 5 @@ -56,9 +56,9 @@ class RangeChartView: UIControl { override init(frame: CGRect) { super.init(frame: frame) - layoutMargins = UIEdgeInsets(top: Constants.cropIndocatorLineWidth, + layoutMargins = UIEdgeInsets(top: Constants.cropIndicatorLineWidth, left: Constants.horizontalContentMargin, - bottom: Constants.cropIndocatorLineWidth, + bottom: Constants.cropIndicatorLineWidth, right: Constants.horizontalContentMargin) self.setup() @@ -289,9 +289,9 @@ private extension RangeChartView { func layoutViews() { cropFrameView.frame = CGRect(x: locationInView(for: lowerBound), - y: contentFrame.minY - Constants.cropIndocatorLineWidth, + y: contentFrame.minY - Constants.cropIndicatorLineWidth, width: locationInView(for: upperBound) - locationInView(for: lowerBound), - height: contentFrame.height + Constants.cropIndocatorLineWidth * 2) + height: contentFrame.height + Constants.cropIndicatorLineWidth * 2) if chartView.frame != contentFrame { chartView.frame = contentFrame diff --git a/submodules/StatisticsUI/Sources/StatsController.swift b/submodules/StatisticsUI/Sources/StatsController.swift index 8c8c6d2f76..513720f14e 100644 --- a/submodules/StatisticsUI/Sources/StatsController.swift +++ b/submodules/StatisticsUI/Sources/StatsController.swift @@ -501,6 +501,13 @@ public func channelStatsController(context: AccountContext, peerId: PeerId, cach } let controller = ItemListController(context: context, state: signal) + controller.contentOffsetChanged = { [weak controller] _, _ in + controller?.forEachItemNode({ itemNode in + if let itemNode = itemNode as? StatsGraphItemNode { + itemNode.resetInteraction() + } + }) + } controller.didDisappear = { [weak controller] _ in controller?.clearItemNodesHighlight(animated: true) } diff --git a/submodules/StatisticsUI/Sources/StatsGraphItem.swift b/submodules/StatisticsUI/Sources/StatsGraphItem.swift index 29a8b095c0..967c67c7a8 100644 --- a/submodules/StatisticsUI/Sources/StatsGraphItem.swift +++ b/submodules/StatisticsUI/Sources/StatsGraphItem.swift @@ -114,6 +114,10 @@ class StatsGraphItemNode: ListViewItemNode { } } + func resetInteraction() { + self.chartNode.resetInteraction() + } + func asyncLayout() -> (_ item: StatsGraphItem, _ params: ListViewItemLayoutParams, _ insets: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) { let currentItem = self.item let currentVisibilityHeight = self.visibilityHeight diff --git a/submodules/TelegramCallsUI/Sources/CallFeedbackController.swift b/submodules/TelegramCallsUI/Sources/CallFeedbackController.swift index 92ef6fe615..e5a3e665e7 100644 --- a/submodules/TelegramCallsUI/Sources/CallFeedbackController.swift +++ b/submodules/TelegramCallsUI/Sources/CallFeedbackController.swift @@ -166,13 +166,13 @@ private enum CallFeedbackControllerEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! CallFeedbackControllerArguments switch self { - case let .reasonsHeader(theme, text): + case let .reasonsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .reason(theme, reason, title, value): + case let .reason(_, reason, title, value): return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, maximumNumberOfLines: 2, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleReason(reason, value) }) - case let .comment(theme, text, placeholder): + case let .comment(_, text, placeholder): return ItemListMultilineInputItem(presentationData: presentationData, text: text, placeholder: placeholder, maxLength: nil, sectionId: self.section, style: .blocks, textUpdated: { updatedText in arguments.updateComment(updatedText) }, updatedFocus: { focused in @@ -180,11 +180,11 @@ private enum CallFeedbackControllerEntry: ItemListNodeEntry { arguments.scrollToComment() } }, tag: CallFeedbackControllerEntryTag.comment) - case let .includeLogs(theme, title, value): + case let .includeLogs(_, title, value): return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleIncludeLogs(value) }) - case let .includeLogsInfo(theme, text): + case let .includeLogsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -312,7 +312,6 @@ public func callFeedbackController(sharedContext: SharedAccountContext, account: } var resultItemNode: ListViewItemNode? - let state = stateValue.with({ $0 }) let _ = controller.frameForItemNode({ itemNode in if let itemNode = itemNode as? ItemListItemNode { if let tag = itemNode.tag, tag.isEqual(to: targetTag) { diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift index 6b3e87ef20..61fcdb4f75 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift @@ -427,7 +427,6 @@ public func customizeDefaultDarkTintedPresentationTheme(theme: PresentationTheme helperLinesColor: accentColor?.withMultiplied(hue: 1.037, saturation: 0.271, brightness: 0.671).withAlphaComponent(0.35), strongLinesColor: accentColor?.withMultiplied(hue: 1.037, saturation: 0.271, brightness: 0.671).withAlphaComponent(0.35), barStrongLinesColor: accentColor?.withMultiplied(hue: 1.033, saturation: 0.211, brightness: 0.882).withAlphaComponent(0.45), - detailsArrowColor: accentColor?.withMultiplied(hue: 1.051, saturation: 0.254, brightness: 0.376), detailsViewColor: accentColor?.withMultiplied(hue: 1.035, saturation: 0.571, brightness: 0.184), rangeViewFrameColor: accentColor?.withMultiplied(hue: 1.030, saturation: 0.494, brightness: 0.349) ) @@ -808,7 +807,7 @@ public func makeDefaultDarkTintedPresentationTheme(extendingThemeReference: Pres strongLinesColor: UIColor(rgb: 0xbacce1, alpha: 0.35), barStrongLinesColor: UIColor(rgb: 0xbacce1, alpha: 0.45), detailsTextColor: UIColor(rgb: 0xffffff), - detailsArrowColor: UIColor(rgb: 0x4c5460), + detailsArrowColor: UIColor(rgb: 0xffffff), detailsViewColor: UIColor(rgb: 0x19232f), rangeViewFrameColor: UIColor(rgb: 0x354659), rangeViewMarkerColor: UIColor(rgb: 0xffffff) diff --git a/submodules/TelegramUI/Images.xcassets/Chart/arrow_right.imageset/Contents.json b/submodules/TelegramUI/Images.xcassets/Chart/arrow_right.imageset/Contents.json index 78b05b5e2a..d5a1147c2e 100644 --- a/submodules/TelegramUI/Images.xcassets/Chart/arrow_right.imageset/Contents.json +++ b/submodules/TelegramUI/Images.xcassets/Chart/arrow_right.imageset/Contents.json @@ -8,5 +8,8 @@ "info" : { "version" : 1, "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "template" } } \ No newline at end of file diff --git a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift index 3641f1b203..81528c58b2 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift @@ -300,8 +300,6 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { } } } - } else if let animationNode = self.animationNode as? ManagedDiceAnimationNode { - } }