Hide chat from screenshots

This commit is contained in:
Ali 2023-08-22 23:47:45 +04:00
parent 1a67361b6b
commit a73e1d805e
2 changed files with 57 additions and 5 deletions

View File

@ -31,7 +31,7 @@ public protocol SparseItemGridShimmerLayer: CALayer {
}
public protocol SparseItemGridBinding: AnyObject {
func createLayer() -> SparseItemGridLayer?
func createLayer(item: SparseItemGrid.Item) -> SparseItemGridLayer?
func createView() -> SparseItemGridView?
func createShimmerLayer() -> SparseItemGridShimmerLayer?
func bindLayers(items: [SparseItemGrid.Item], layers: [SparseItemGridDisplayItem], size: CGSize, insets: UIEdgeInsets, synchronous: SparseItemGrid.Synchronous)
@ -982,7 +982,7 @@ public final class SparseItemGrid: ASDisplayNode {
itemLayer = current
updateLayers.append((itemLayer, index))
} else {
itemLayer = VisibleItem(layer: items.itemBinding.createLayer(), view: items.itemBinding.createView())
itemLayer = VisibleItem(layer: items.itemBinding.createLayer(item: item), view: items.itemBinding.createView())
self.visibleItems[item.id] = itemLayer
bindItems.append(item)

View File

@ -70,6 +70,55 @@ private struct ChatControllerNodeDerivedLayoutState {
var upperInputPositionBound: CGFloat?
}
class HistoryNodeContainer: ASDisplayNode {
private(set) var secretContainer: UIView?
public var isSecret: Bool = false {
didSet {
if self.isSecret != oldValue {
if self.isNodeLoaded {
(self.view as? UITextField)?.isSecureTextEntry = self.isSecret
}
}
}
}
init(isSecret: Bool) {
self.isSecret = isSecret
super.init()
self.setViewBlock {
let captureProtectedView = UITextField(frame: CGRect())
captureProtectedView.isSecureTextEntry = self.isSecret
self.secretContainer = captureProtectedView.subviews.first
return captureProtectedView
}
let _ = self.view
}
override func addSubnode(_ subnode: ASDisplayNode) {
if let secretContainer = self.secretContainer {
secretContainer.addSubnode(subnode)
} else {
super.addSubnode(subnode)
}
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if let secretContainer = self.secretContainer {
return secretContainer.hitTest(point, with: event)
} else {
return super.hitTest(point, with: event)
}
}
func updateSize(size: CGSize, transition: ContainedViewLayoutTransition) {
/*if let secretContainer = self.secretContainer {
}*/
}
}
class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
let context: AccountContext
let chatLocation: ChatLocation
@ -96,7 +145,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
let backgroundNode: WallpaperBackgroundNode
let historyNode: ChatHistoryListNode
var blurredHistoryNode: ASImageNode?
let historyNodeContainer: ASDisplayNode
let historyNodeContainer: HistoryNodeContainer
let loadingNode: ChatLoadingNode
private(set) var loadingPlaceholderNode: ChatLoadingPlaceholderNode?
@ -438,9 +487,9 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
//self.historyScrollingArea = SparseDiscreteScrollingArea()
//self.historyNode.historyScrollingArea = self.historyScrollingArea
self.historyNodeContainer = ASDisplayNode()
self.historyNodeContainer = HistoryNodeContainer(isSecret: chatLocation.peerId?.namespace == Namespaces.Peer.SecretChat)
self.historyNodeContainer.addSubnode(self.historyNode)
//self.historyNodeContainer.addSubnode(self.historyScrollingArea)
var getContentAreaInScreenSpaceImpl: (() -> CGRect)?
var onTransitionEventImpl: ((ContainedViewLayoutTransition) -> Void)?
@ -857,6 +906,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
statusBar.statusBarStyle = .Ignore
}
}
self.historyNodeContainer.isSecret = self.chatPresentationInterfaceState.copyProtectionEnabled || self.chatLocation.peerId?.namespace == Namespaces.Peer.SecretChat
var previousListBottomInset: CGFloat?
if !self.historyNode.frame.isEmpty {
@ -1484,6 +1535,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
transition.updateBounds(node: self.historyNodeContainer, bounds: contentBounds)
transition.updatePosition(node: self.historyNodeContainer, position: contentBounds.center)
self.historyNodeContainer.updateSize(size: contentBounds.size, transition: transition)
transition.updateBounds(node: self.historyNode, bounds: CGRect(origin: CGPoint(), size: contentBounds.size))
transition.updatePosition(node: self.historyNode, position: CGPoint(x: contentBounds.size.width / 2.0, y: contentBounds.size.height / 2.0))