mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 05:51:42 +00:00
Fix chart theme application
This commit is contained in:
parent
ed2218f17d
commit
c5d39df2b3
@ -32,7 +32,8 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
|||||||
var titleLabel: UILabel!
|
var titleLabel: UILabel!
|
||||||
var backButton: UIButton!
|
var backButton: UIButton!
|
||||||
|
|
||||||
var controller: BaseChartController!
|
var controller: BaseChartController?
|
||||||
|
var theme: ChartTheme?
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
sectionContainerView = UIView()
|
sectionContainerView = UIView()
|
||||||
@ -82,6 +83,8 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func apply(theme: ChartTheme, animated: Bool) {
|
func apply(theme: ChartTheme, animated: Bool) {
|
||||||
|
self.theme = theme
|
||||||
|
|
||||||
UIView.perform(animated: animated && self.isVisibleInWindow) {
|
UIView.perform(animated: animated && self.isVisibleInWindow) {
|
||||||
self.backgroundColor = theme.tableBackgroundColor
|
self.backgroundColor = theme.tableBackgroundColor
|
||||||
|
|
||||||
@ -100,12 +103,13 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
|||||||
if rangeView.isVisibleInWindow || chartView.isVisibleInWindow {
|
if rangeView.isVisibleInWindow || chartView.isVisibleInWindow {
|
||||||
chartView.loadDetailsViewIfNeeded()
|
chartView.loadDetailsViewIfNeeded()
|
||||||
chartView.apply(theme: theme, animated: animated && chartView.isVisibleInWindow)
|
chartView.apply(theme: theme, animated: animated && chartView.isVisibleInWindow)
|
||||||
controller.apply(theme: theme, animated: animated)
|
controller?.apply(theme: theme, animated: animated)
|
||||||
rangeView.apply(theme: theme, animated: animated && rangeView.isVisibleInWindow)
|
rangeView.apply(theme: theme, animated: animated && rangeView.isVisibleInWindow)
|
||||||
} else {
|
} else {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + TimeInterval.random(in: 0...0.1)) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + TimeInterval.random(in: 0...0.1)) {
|
||||||
self.chartView.loadDetailsViewIfNeeded()
|
self.chartView.loadDetailsViewIfNeeded()
|
||||||
self.controller.apply(theme: theme, animated: false)
|
|
||||||
|
self.controller?.apply(theme: theme, animated: false)
|
||||||
self.chartView.apply(theme: theme, animated: false)
|
self.chartView.apply(theme: theme, animated: false)
|
||||||
self.rangeView.apply(theme: theme, animated: false)
|
self.rangeView.apply(theme: theme, animated: false)
|
||||||
}
|
}
|
||||||
@ -115,7 +119,7 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc private func didTapBackButton() {
|
@objc private func didTapBackButton() {
|
||||||
controller.didTapZoomOut()
|
self.controller?.didTapZoomOut()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setBackButtonVisible(_ visible: Bool, animated: Bool) {
|
func setBackButtonVisible(_ visible: Bool, animated: Bool) {
|
||||||
@ -124,6 +128,10 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateToolViews(animated: Bool) {
|
func updateToolViews(animated: Bool) {
|
||||||
|
guard let controller = self.controller else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
rangeView.setRange(controller.currentChartHorizontalRangeFraction, animated: animated)
|
rangeView.setRange(controller.currentChartHorizontalRangeFraction, animated: animated)
|
||||||
rangeView.setRangePaging(enabled: controller.isChartRangePagingEnabled,
|
rangeView.setRangePaging(enabled: controller.isChartRangePagingEnabled,
|
||||||
minimumSize: controller.minimumSelectedChartRange)
|
minimumSize: controller.minimumSelectedChartRange)
|
||||||
@ -156,14 +164,16 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
|||||||
|
|
||||||
func setup(controller: BaseChartController, title: String) {
|
func setup(controller: BaseChartController, title: String) {
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
|
if let theme = self.theme {
|
||||||
// Chart
|
controller.apply(theme: theme, animated: false)
|
||||||
chartView.renderers = controller.mainChartRenderers
|
|
||||||
chartView.userDidSelectCoordinateClosure = { [unowned self] point in
|
|
||||||
self.controller.chartInteractionDidBegin(point: point)
|
|
||||||
}
|
}
|
||||||
chartView.userDidDeselectCoordinateClosure = { [unowned self] in
|
|
||||||
self.controller.chartInteractionDidEnd()
|
self.chartView.renderers = controller.mainChartRenderers
|
||||||
|
self.chartView.userDidSelectCoordinateClosure = { [unowned self] point in
|
||||||
|
self.controller?.chartInteractionDidBegin(point: point)
|
||||||
|
}
|
||||||
|
self.chartView.userDidDeselectCoordinateClosure = { [unowned self] in
|
||||||
|
self.controller?.chartInteractionDidEnd()
|
||||||
}
|
}
|
||||||
controller.cartViewBounds = { [unowned self] in
|
controller.cartViewBounds = { [unowned self] in
|
||||||
return self.chartView.bounds
|
return self.chartView.bounds
|
||||||
@ -191,12 +201,11 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
|||||||
self.updateToolViews(animated: animated)
|
self.updateToolViews(animated: animated)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Range view
|
self.rangeView.chartView.renderers = controller.navigationRenderers
|
||||||
rangeView.chartView.renderers = controller.navigationRenderers
|
self.rangeView.rangeDidChangeClosure = { range in
|
||||||
rangeView.rangeDidChangeClosure = { range in
|
|
||||||
controller.updateChartRange(range)
|
controller.updateChartRange(range)
|
||||||
}
|
}
|
||||||
rangeView.touchedOutsideClosure = {
|
self.rangeView.touchedOutsideClosure = {
|
||||||
controller.cancelChartInteraction()
|
controller.cancelChartInteraction()
|
||||||
}
|
}
|
||||||
controller.chartRangeUpdatedClosure = { [unowned self] (range, animated) in
|
controller.chartRangeUpdatedClosure = { [unowned self] (range, animated) in
|
||||||
@ -205,18 +214,15 @@ class ChartStackSection: UIView, ChartThemeContainer {
|
|||||||
controller.chartRangePagingClosure = { [unowned self] (isEnabled, pageSize) in
|
controller.chartRangePagingClosure = { [unowned self] (isEnabled, pageSize) in
|
||||||
self.rangeView.setRangePaging(enabled: isEnabled, minimumSize: pageSize)
|
self.rangeView.setRangePaging(enabled: isEnabled, minimumSize: pageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visibility view
|
self.visibilityView.selectionCallbackClosure = { [unowned self] visibility in
|
||||||
visibilityView.selectionCallbackClosure = { [unowned self] visibility in
|
self.controller?.updateChartsVisibility(visibility: visibility, animated: true)
|
||||||
self.controller.updateChartsVisibility(visibility: visibility, animated: true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.initializeChart()
|
controller.initializeChart()
|
||||||
updateToolViews(animated: false)
|
updateToolViews(animated: false)
|
||||||
|
|
||||||
rangeView.setRange(0.8...1.0, animated: false)
|
rangeView.setRange(0.8...1.0, animated: false)
|
||||||
// TimeInterval.animationDurationMultipler = 0.00001
|
|
||||||
controller.updateChartRange(0.8...1.0, animated: false)
|
controller.updateChartRange(0.8...1.0, animated: false)
|
||||||
// TimeInterval.animationDurationMultipler = 1.0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user