mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various Fixes
This commit is contained in:
parent
95d121162e
commit
06a749543d
@ -67,23 +67,30 @@ public final class DisplayLinkAnimator {
|
||||
}
|
||||
|
||||
public final class ConstantDisplayLinkAnimator {
|
||||
private var displayLink: CADisplayLink!
|
||||
private var displayLink: CADisplayLink?
|
||||
private let update: () -> Void
|
||||
private var completed = false
|
||||
|
||||
public var frameInterval: Int = 1 {
|
||||
didSet {
|
||||
if #available(iOS 10.0, *) {
|
||||
let preferredFramesPerSecond: Int
|
||||
if self.frameInterval == 1 {
|
||||
preferredFramesPerSecond = 60
|
||||
} else {
|
||||
preferredFramesPerSecond = 30
|
||||
}
|
||||
self.displayLink.preferredFramesPerSecond = preferredFramesPerSecond
|
||||
self.updateDisplayLink()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateDisplayLink() {
|
||||
guard let displayLink = self.displayLink else {
|
||||
return
|
||||
}
|
||||
if #available(iOS 10.0, *) {
|
||||
let preferredFramesPerSecond: Int
|
||||
if self.frameInterval == 1 {
|
||||
preferredFramesPerSecond = 60
|
||||
} else {
|
||||
self.displayLink.frameInterval = self.frameInterval
|
||||
preferredFramesPerSecond = 30
|
||||
}
|
||||
displayLink.preferredFramesPerSecond = preferredFramesPerSecond
|
||||
} else {
|
||||
displayLink.frameInterval = self.frameInterval
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,16 +98,18 @@ public final class ConstantDisplayLinkAnimator {
|
||||
didSet {
|
||||
if self.isPaused != oldValue {
|
||||
if !self.isPaused && self.displayLink == nil {
|
||||
self.displayLink = CADisplayLink(target: DisplayLinkTarget({ [weak self] in
|
||||
let displayLink = CADisplayLink(target: DisplayLinkTarget({ [weak self] in
|
||||
self?.tick()
|
||||
}), selector: #selector(DisplayLinkTarget.event))
|
||||
/*if #available(iOS 15.0, *) {
|
||||
self.displayLink?.preferredFrameRateRange = CAFrameRateRange(minimum: 60.0, maximum: 120.0, preferred: 120.0)
|
||||
}*/
|
||||
self.displayLink.add(to: RunLoop.main, forMode: .common)
|
||||
displayLink.add(to: RunLoop.main, forMode: .common)
|
||||
self.displayLink = displayLink
|
||||
self.updateDisplayLink()
|
||||
}
|
||||
|
||||
self.displayLink.isPaused = self.isPaused
|
||||
self.displayLink?.isPaused = self.isPaused
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,13 +119,17 @@ public final class ConstantDisplayLinkAnimator {
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.displayLink.isPaused = true
|
||||
self.displayLink.invalidate()
|
||||
if let displayLink = self.displayLink {
|
||||
displayLink.isPaused = true
|
||||
displayLink.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
public func invalidate() {
|
||||
self.displayLink.isPaused = true
|
||||
self.displayLink.invalidate()
|
||||
if let displayLink = self.displayLink {
|
||||
displayLink.isPaused = true
|
||||
displayLink.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func tick() {
|
||||
|
@ -314,14 +314,14 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode {
|
||||
strongSelf.statusNodeContainer.isHidden = true
|
||||
|
||||
Queue.concurrentDefaultQueue().async {
|
||||
if let message = strongSelf.message, !message.isCopyProtected(), let image = generate(TransformImageArguments(corners: ImageCorners(), imageSize: displaySize, boundingSize: displaySize, intrinsicInsets: UIEdgeInsets()))?.generateImage() {
|
||||
strongSelf.recognitionDisposable.set((recognizedContent(postbox: strongSelf.context.account.postbox, image: image, messageId: message.id)
|
||||
if let message = strongSelf.message, !message.isCopyProtected() {
|
||||
strongSelf.recognitionDisposable.set((recognizedContent(postbox: strongSelf.context.account.postbox, image: { return generate(TransformImageArguments(corners: ImageCorners(), imageSize: displaySize, boundingSize: displaySize, intrinsicInsets: UIEdgeInsets()))?.generateImage() }, messageId: message.id)
|
||||
|> deliverOnMainQueue).start(next: { [weak self] results in
|
||||
if let strongSelf = self {
|
||||
strongSelf.recognizedContentNode?.removeFromSupernode()
|
||||
if !results.isEmpty {
|
||||
let size = strongSelf.imageNode.bounds.size
|
||||
let recognizedContentNode = RecognizedContentContainer(size: size, image: image, recognitions: results, presentationData: strongSelf.context.sharedContext.currentPresentationData.with { $0 }, present: { c, a in
|
||||
let recognizedContentNode = RecognizedContentContainer(size: size, recognitions: results, presentationData: strongSelf.context.sharedContext.currentPresentationData.with { $0 }, present: { c, a in
|
||||
strongSelf.galleryController()?.presentInGlobalOverlay(c, with: a)
|
||||
}, performAction: { [weak self] string, action in
|
||||
guard let strongSelf = self else {
|
||||
@ -358,11 +358,6 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode {
|
||||
}
|
||||
strongSelf.footerContentNode.openActionOptions?(.url(url: payload, concealed: true), message)
|
||||
}
|
||||
recognizedContentNode.textAction = { _, _ in
|
||||
// guard let strongSelf = self else {
|
||||
// return
|
||||
// }
|
||||
}
|
||||
recognizedContentNode.alpha = 0.0
|
||||
recognizedContentNode.frame = CGRect(origin: CGPoint(), size: size)
|
||||
recognizedContentNode.update(size: strongSelf.imageNode.bounds.size, transition: .immediate)
|
||||
@ -1029,9 +1024,8 @@ private class RecognizedContentContainer: ASDisplayNode {
|
||||
private var selectionNode: RecognizedTextSelectionNode?
|
||||
|
||||
var barcodeAction: ((String, CGRect) -> Void)?
|
||||
var textAction: ((String, CGRect) -> Void)?
|
||||
|
||||
init(size: CGSize, image: UIImage, recognitions: [RecognizedContent], presentationData: PresentationData, present: @escaping (ViewController, Any?) -> Void, performAction: @escaping (String, RecognizedTextSelectionAction) -> Void) {
|
||||
init(size: CGSize, recognitions: [RecognizedContent], presentationData: PresentationData, present: @escaping (ViewController, Any?) -> Void, performAction: @escaping (String, RecognizedTextSelectionAction) -> Void) {
|
||||
self.size = size
|
||||
self.recognitions = recognitions
|
||||
|
||||
|
@ -328,16 +328,18 @@ private func recognizeContent(in image: UIImage) -> Signal<[RecognizedContent],
|
||||
}
|
||||
}
|
||||
|
||||
public func recognizedContent(postbox: Postbox, image: UIImage, messageId: MessageId) -> Signal<[RecognizedContent], NoError> {
|
||||
public func recognizedContent(postbox: Postbox, image: @escaping () -> UIImage?, messageId: MessageId) -> Signal<[RecognizedContent], NoError> {
|
||||
return cachedImageRecognizedContent(postbox: postbox, messageId: messageId)
|
||||
|> mapToSignal { cachedContent -> Signal<[RecognizedContent], NoError> in
|
||||
if let cachedContent = cachedContent {
|
||||
return .single(cachedContent.results)
|
||||
} else {
|
||||
} else if let image = image() {
|
||||
return recognizeContent(in: image)
|
||||
|> beforeNext { results in
|
||||
let _ = updateCachedImageRecognizedContent(postbox: postbox, messageId: messageId, content: CachedImageRecognizedContent(results: results)).start()
|
||||
}
|
||||
} else {
|
||||
return .single([])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public final class SolidRoundedButtonNode: ASDisplayNode {
|
||||
private var fontSize: CGFloat
|
||||
|
||||
private let buttonBackgroundNode: ASDisplayNode
|
||||
private let buttonGlossNode: SolidRoundedButtonGlossNode
|
||||
private let buttonGlossNode: SolidRoundedButtonGlossNode?
|
||||
private let buttonNode: HighlightTrackingButtonNode
|
||||
private let titleNode: ImmediateTextNode
|
||||
private let subtitleNode: ImmediateTextNode
|
||||
@ -94,7 +94,11 @@ public final class SolidRoundedButtonNode: ASDisplayNode {
|
||||
self.buttonBackgroundNode.backgroundColor = theme.backgroundColor
|
||||
self.buttonBackgroundNode.cornerRadius = cornerRadius
|
||||
|
||||
self.buttonGlossNode = SolidRoundedButtonGlossNode(color: theme.foregroundColor, cornerRadius: cornerRadius)
|
||||
if gloss {
|
||||
self.buttonGlossNode = SolidRoundedButtonGlossNode(color: theme.foregroundColor, cornerRadius: cornerRadius)
|
||||
} else {
|
||||
self.buttonGlossNode = nil
|
||||
}
|
||||
|
||||
self.buttonNode = HighlightTrackingButtonNode()
|
||||
|
||||
@ -112,8 +116,8 @@ public final class SolidRoundedButtonNode: ASDisplayNode {
|
||||
super.init()
|
||||
|
||||
self.addSubnode(self.buttonBackgroundNode)
|
||||
if gloss {
|
||||
self.addSubnode(self.buttonGlossNode)
|
||||
if let buttonGlossNode = self.buttonGlossNode {
|
||||
self.addSubnode(buttonGlossNode)
|
||||
}
|
||||
self.addSubnode(self.buttonNode)
|
||||
self.addSubnode(self.titleNode)
|
||||
@ -207,7 +211,7 @@ public final class SolidRoundedButtonNode: ASDisplayNode {
|
||||
self.theme = theme
|
||||
|
||||
self.buttonBackgroundNode.backgroundColor = theme.backgroundColor
|
||||
self.buttonGlossNode.color = theme.foregroundColor
|
||||
self.buttonGlossNode?.color = theme.foregroundColor
|
||||
self.titleNode.attributedText = NSAttributedString(string: self.title ?? "", font: self.font == .bold ? Font.semibold(self.fontSize) : Font.regular(self.fontSize), textColor: theme.foregroundColor)
|
||||
self.subtitleNode.attributedText = NSAttributedString(string: self.subtitle ?? "", font: Font.regular(14.0), textColor: theme.foregroundColor)
|
||||
|
||||
@ -231,7 +235,9 @@ public final class SolidRoundedButtonNode: ASDisplayNode {
|
||||
let buttonSize = CGSize(width: width, height: self.buttonHeight)
|
||||
let buttonFrame = CGRect(origin: CGPoint(), size: buttonSize)
|
||||
transition.updateFrame(node: self.buttonBackgroundNode, frame: buttonFrame)
|
||||
transition.updateFrame(node: self.buttonGlossNode, frame: buttonFrame)
|
||||
if let buttonGlossNode = self.buttonGlossNode {
|
||||
transition.updateFrame(node: buttonGlossNode, frame: buttonFrame)
|
||||
}
|
||||
transition.updateFrame(node: self.buttonNode, frame: buttonFrame)
|
||||
|
||||
if self.title != self.titleNode.attributedText?.string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user