This commit is contained in:
Ali 2023-07-07 19:17:08 +04:00
parent 9732758e56
commit a732b92463
3 changed files with 48 additions and 4 deletions

View File

@ -277,10 +277,22 @@ open class TransformImageNode: ASDisplayNode {
}
}
private class CaptureProtectedContentLayer: AVSampleBufferDisplayLayer {
override func action(forKey event: String) -> CAAction? {
public class CaptureProtectedContentLayer: AVSampleBufferDisplayLayer {
override public func action(forKey event: String) -> CAAction? {
return nullAction
}
override public init() {
super.init()
}
override public init(layer: Any) {
super.init(layer: layer)
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
open class TransformImageView: UIView {

View File

@ -8,9 +8,11 @@ import ComponentFlow
import TinyThumbnail
import ImageBlur
import MediaResources
import Display
final class StoryItemImageView: UIView {
private let contentView: UIImageView
private var captureProtectedContentLayer: CaptureProtectedContentLayer?
private var currentMedia: EngineMedia?
private var disposable: Disposable?
@ -19,6 +21,8 @@ final class StoryItemImageView: UIView {
private(set) var isContentLoaded: Bool = false
var didLoadContents: (() -> Void)?
private var isCaptureProtected: Bool = false
override init(frame: CGRect) {
self.contentView = UIImageView()
self.contentView.contentMode = .scaleAspectFill
@ -37,10 +41,34 @@ final class StoryItemImageView: UIView {
}
private func updateImage(image: UIImage) {
self.contentView.image = image
if self.isCaptureProtected {
let captureProtectedContentLayer: CaptureProtectedContentLayer
if let current = self.captureProtectedContentLayer {
captureProtectedContentLayer = current
} else {
captureProtectedContentLayer = CaptureProtectedContentLayer()
captureProtectedContentLayer.videoGravity = .resizeAspectFill
if #available(iOS 13.0, *) {
captureProtectedContentLayer.preventsCapture = true
captureProtectedContentLayer.preventsDisplaySleepDuringVideoPlayback = false
}
captureProtectedContentLayer.frame = self.contentView.frame
self.captureProtectedContentLayer = captureProtectedContentLayer
self.layer.addSublayer(captureProtectedContentLayer)
}
if let cmSampleBuffer = image.cmSampleBuffer {
captureProtectedContentLayer.enqueue(cmSampleBuffer)
}
} else {
self.contentView.image = image
}
}
func update(context: AccountContext, peer: EnginePeer, storyId: Int32, media: EngineMedia, size: CGSize, isCaptureProtected: Bool, attemptSynchronous: Bool, transition: Transition) {
self.isCaptureProtected = isCaptureProtected
var dimensions: CGSize?
let isMediaUpdated: Bool
@ -173,6 +201,10 @@ final class StoryItemImageView: UIView {
let filledSize = dimensions.aspectFilled(size)
let contentFrame = CGRect(origin: CGPoint(x: floor((size.width - filledSize.width) * 0.5), y: floor((size.height - filledSize.height) * 0.5)), size: filledSize)
transition.setFrame(view: self.contentView, frame: contentFrame)
if let captureProtectedContentLayer = self.captureProtectedContentLayer {
transition.setFrame(layer: captureProtectedContentLayer, frame: contentFrame)
}
}
}
}

View File

@ -112,7 +112,7 @@ private func calculateMergingCircleShape(center: CGPoint, leftCenter: CGPoint?,
}
var startAngle = segmentSpacingAngle * 0.5 - CGFloat.pi * 0.5 + CGFloat(i) * (segmentSpacingAngle + segmentAngle)
startAngle += (1.0 - segmentFraction) * CGFloat.pi * 2.0 * 0.25
startAngle += (1.0 - segmentFraction) * CGFloat.pi * 2.0 * (-0.25)
let endAngle = startAngle + segmentAngle
path.move(to: CGPoint(x: center.x + cos(startAngle) * radius, y: center.y + sin(startAngle) * radius))