Various fixes

This commit is contained in:
Ilya Laktyushin 2026-04-15 23:12:53 +02:00
parent a4e9b0468e
commit 8f1e024aef
36 changed files with 1978 additions and 1373 deletions

View file

@ -109,6 +109,7 @@ public final class StatsGraphItemNode: ListViewItemNode {
let chartNode: ChartNode
private let activityIndicator: ActivityIndicator
private let errorTextNode: TextNode
private var item: StatsGraphItem?
private var visibilityHeight: CGFloat?
@ -134,11 +135,15 @@ public final class StatsGraphItemNode: ListViewItemNode {
self.chartNode = ChartNode()
self.activityIndicator = ActivityIndicator(type: ActivityIndicatorType.custom(.black, 16.0, 2.0, false))
self.activityIndicator.isHidden = true
self.errorTextNode = TextNode()
self.errorTextNode.isUserInteractionEnabled = false
self.errorTextNode.isHidden = true
super.init(layerBacked: false)
self.chartContainerNode.addSubnode(self.chartNode)
self.chartContainerNode.addSubnode(self.activityIndicator)
self.chartContainerNode.addSubnode(self.errorTextNode)
}
public override func didLoad() {
@ -154,12 +159,14 @@ public final class StatsGraphItemNode: ListViewItemNode {
}
func asyncLayout() -> (_ item: StatsGraphItem, _ params: ListViewItemLayoutParams, _ insets: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) {
let makeErrorTextLayout = TextNode.asyncLayout(self.errorTextNode)
let currentItem = self.item
let currentVisibilityHeight = self.visibilityHeight
return { item, params, neighbors in
let leftInset = params.leftInset
let rightInset: CGFloat = params.rightInset
let errorTextFont = Font.regular(item.presentationData.fontSize.itemListBaseLabelFontSize / 14.0 * 16.0)
var updatedTheme: PresentationTheme?
var updatedGraph: StatsGraph?
var updatedController: BaseChartController?
@ -197,6 +204,27 @@ public final class StatsGraphItemNode: ListViewItemNode {
contentSize = CGSize(width: params.width, height: 361.0)
insets = itemListNeighborsGroupedInsets(neighbors, params)
}
let errorText: String
if case let .Failed(text) = item.graph {
errorText = text
} else {
errorText = ""
}
let (errorTextLayout, errorTextApply) = makeErrorTextLayout(TextNodeLayoutArguments(
attributedString: NSAttributedString(
string: errorText,
font: errorTextFont,
textColor: item.presentationData.theme.list.itemSecondaryTextColor
),
backgroundColor: nil,
maximumNumberOfLines: 0,
truncationType: .end,
constrainedSize: CGSize(width: max(1.0, params.width - leftInset - rightInset - 32.0), height: contentSize.height),
alignment: .center,
cutout: nil,
insets: UIEdgeInsets()
))
var visibilityHeight = currentVisibilityHeight
if let updatedController = updatedController {
@ -293,8 +321,16 @@ public final class StatsGraphItemNode: ListViewItemNode {
strongSelf.bottomStripeNode.frame = CGRect(origin: CGPoint(x: bottomStripeInset, y: contentSize.height - separatorHeight), size: CGSize(width: params.width - bottomStripeInset, height: separatorHeight))
strongSelf.activityIndicator.frame = CGRect(origin: CGPoint(x: floor((layout.size.width - 16.0) / 2.0), y: floor((layout.size.height - 16.0) / 2.0)), size: CGSize(width: 16.0, height: 16.0))
strongSelf.errorTextNode.frame = CGRect(
origin: CGPoint(
x: floorToScreenPixels((strongSelf.chartContainerNode.bounds.width - errorTextLayout.size.width) / 2.0),
y: floorToScreenPixels((strongSelf.chartContainerNode.bounds.height - errorTextLayout.size.height) / 2.0)
),
size: errorTextLayout.size
)
}
let _ = errorTextApply()
strongSelf.activityIndicator.type = .custom(item.presentationData.theme.list.itemSecondaryTextColor, 16.0, 2.0, false)
if let updatedTheme = updatedTheme {
@ -310,15 +346,27 @@ public final class StatsGraphItemNode: ListViewItemNode {
)
}
if let updatedGraph = updatedGraph {
if case .Loaded = updatedGraph, let updatedController = updatedController {
strongSelf.chartNode.setup(controller: updatedController, noInitialZoom: item.noInitialZoom)
strongSelf.activityIndicator.isHidden = true
strongSelf.chartNode.isHidden = false
} else if case .OnDemand = updatedGraph {
strongSelf.activityIndicator.isHidden = false
strongSelf.chartNode.isHidden = true
}
if let updatedGraph = updatedGraph, case .Loaded = updatedGraph, let updatedController = updatedController {
strongSelf.chartNode.setup(controller: updatedController, noInitialZoom: item.noInitialZoom)
}
switch item.graph {
case .Loaded:
strongSelf.activityIndicator.isHidden = true
strongSelf.chartNode.isHidden = false
strongSelf.errorTextNode.isHidden = true
case .OnDemand:
strongSelf.activityIndicator.isHidden = false
strongSelf.chartNode.isHidden = true
strongSelf.errorTextNode.isHidden = true
case let .Failed(error):
strongSelf.activityIndicator.isHidden = true
strongSelf.chartNode.isHidden = true
strongSelf.errorTextNode.isHidden = error.isEmpty
case .Empty:
strongSelf.activityIndicator.isHidden = true
strongSelf.chartNode.isHidden = true
strongSelf.errorTextNode.isHidden = true
}
}
})
@ -337,4 +385,3 @@ public final class StatsGraphItemNode: ListViewItemNode {
self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false)
}
}