mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-31 07:30:40 +00:00
Fixed status bar proxy time drawing on pre-X devices
This commit is contained in:
parent
416b7fdc65
commit
a6a4448368
@ -51,6 +51,14 @@ private func maxSubviewBounds(_ view: UIView) -> CGRect {
|
|||||||
return bounds
|
return bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private let formatter: DateFormatter? = {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.timeStyle = .short
|
||||||
|
formatter.locale = Locale.current
|
||||||
|
return formatter
|
||||||
|
}()
|
||||||
|
|
||||||
|
|
||||||
private class StatusBarItemNode: ASDisplayNode {
|
private class StatusBarItemNode: ASDisplayNode {
|
||||||
var statusBarStyle: StatusBarStyle
|
var statusBarStyle: StatusBarStyle
|
||||||
var targetView: UIView
|
var targetView: UIView
|
||||||
@ -103,11 +111,42 @@ private class StatusBarItemNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context.withContext { c in
|
if self.targetView.checkIsKind(of: timeViewClass) {
|
||||||
c.translateBy(x: containingBounds.minX, y: -containingBounds.minY)
|
context.withContext { c in
|
||||||
UIGraphicsPushContext(c)
|
c.translateBy(x: containingBounds.minX, y: -containingBounds.minY)
|
||||||
self.targetView.layer.render(in: c)
|
UIGraphicsPushContext(c)
|
||||||
UIGraphicsPopContext()
|
|
||||||
|
let color: UIColor
|
||||||
|
switch self.statusBarStyle {
|
||||||
|
case .Black, .Ignore, .Hide:
|
||||||
|
color = UIColor.black
|
||||||
|
case .White:
|
||||||
|
color = UIColor.white
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter?.locale = Locale.current
|
||||||
|
if let string = formatter?.string(from: Date()) {
|
||||||
|
let attributedString = NSAttributedString(string: string, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 12.0), NSAttributedStringKey.foregroundColor: color])
|
||||||
|
|
||||||
|
let line = CTLineCreateWithAttributedString(attributedString)
|
||||||
|
|
||||||
|
c.translateBy(x: containingBounds.width / 2.0, y: containingBounds.height / 2.0)
|
||||||
|
c.scaleBy(x: 1.0, y: -1.0)
|
||||||
|
c.translateBy(x: -containingBounds.width / 2.0, y: -containingBounds.height / 2.0)
|
||||||
|
|
||||||
|
c.translateBy(x: 0.0, y: 5.0 + UIScreenPixel)
|
||||||
|
CTLineDraw(line, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
UIGraphicsPopContext()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context.withContext { c in
|
||||||
|
c.translateBy(x: containingBounds.minX, y: -containingBounds.minY)
|
||||||
|
UIGraphicsPushContext(c)
|
||||||
|
self.targetView.layer.render(in: c)
|
||||||
|
UIGraphicsPopContext()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//dumpViews(self.targetView)
|
//dumpViews(self.targetView)
|
||||||
@ -136,8 +175,9 @@ private class StatusBarItemNode: ASDisplayNode {
|
|||||||
type = .Activity
|
type = .Activity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tintStatusBarItem(context, type: type, style: statusBarStyle)
|
tintStatusBarItem(context, type: type, style: self.statusBarStyle)
|
||||||
self.contentNode.contents = context.generateImage()?.cgImage
|
let image = context.generateImage()?.cgImage
|
||||||
|
self.contentNode.contents = image
|
||||||
|
|
||||||
let mappedFrame = self.targetView.convert(self.targetView.bounds, to: self.rootView)
|
let mappedFrame = self.targetView.convert(self.targetView.bounds, to: self.rootView)
|
||||||
self.frame = mappedFrame
|
self.frame = mappedFrame
|
||||||
@ -356,6 +396,14 @@ private let stringClass: AnyClass? = {
|
|||||||
return NSClassFromString("_UI" + nameString)
|
return NSClassFromString("_UI" + nameString)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
private let timeViewClass: AnyClass? = {
|
||||||
|
var nameString = "StatusBar"
|
||||||
|
if CFAbsoluteTimeGetCurrent() > 0 {
|
||||||
|
nameString += "TimeItemView"
|
||||||
|
}
|
||||||
|
return NSClassFromString("UI" + nameString)
|
||||||
|
}()
|
||||||
|
|
||||||
private func containsSubviewOfClass(view: UIView, of subviewClass: AnyClass?) -> Bool {
|
private func containsSubviewOfClass(view: UIView, of subviewClass: AnyClass?) -> Bool {
|
||||||
guard let subviewClass = subviewClass else {
|
guard let subviewClass = subviewClass else {
|
||||||
return false
|
return false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user