Skip to content

Instantly share code, notes, and snippets.

View nonisolated's full-sized avatar

Dmitry Baginsky nonisolated

View GitHub Profile
@nonisolated
nonisolated / SecureView.swift
Last active July 7, 2023 14:59
A SwiftUI wrapper for UIView that provides protection against screenshots. This view uses a UITextField with isSecureTextEntry set to true to create an invisible, screenshot-proof container in which you can place other views.
public struct SecureView<Content: View>: UIViewRepresentable {
let content: () -> Content
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
public func makeUIView(context: Context) -> UIView {
let secureTextField = UITextField()
secureTextField.isSecureTextEntry = true
func calculateRectBetween(lastPoint: CGPoint, newPoint: CGPoint) -> CGRect {
let originX = min(lastPoint.x, newPoint.x) - (lineWidth / 2)
let originY = min(lastPoint.y, newPoint.y) - (lineWidth / 2)
let maxX = max(lastPoint.x, newPoint.x) + (lineWidth / 2)
let maxY = max(lastPoint.y, newPoint.y) + (lineWidth / 2)
let width = maxX - originX
let height = maxY - originY