-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4376794
Showing
13 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# .github/workflows/build-documentation.yml | ||
|
||
name: build-documentation | ||
|
||
on: | ||
# Run on push to main branch | ||
push: | ||
branches: | ||
- main | ||
|
||
# Dispatch if triggered using Github (website) | ||
workflow_dispatch: | ||
|
||
jobs: | ||
Build-documentation: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Build documentation | ||
uses: 0xWDG/build-documentation@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# .github/workflows/build-multiplatform.yml | ||
|
||
name: Build-Packages | ||
|
||
on: | ||
# Run on pull_request | ||
pull_request: | ||
|
||
# Dispatch if triggered using Github (website) | ||
workflow_dispatch: | ||
|
||
jobs: | ||
Build-Packages: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Build Swift Packages | ||
uses: 0xWDG/build-swift@main | ||
with: | ||
# watchOS is unsupported | ||
watchOS: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Run Swiftlint | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
swiftlint: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: SwiftLint | ||
run: | | ||
brew install swiftlint | ||
swiftlint --reporter github-actions-logging --strict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Run tests on Linux and macOS | ||
on: | ||
push: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test_linux: | ||
if: true | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Swift test | ||
run: swift test | ||
|
||
test_macos: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Swift test | ||
run: swift test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## User settings | ||
xcuserdata/ | ||
|
||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) | ||
*.xcscmblueprint | ||
*.xccheckout | ||
|
||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) | ||
build/ | ||
DerivedData/ | ||
*.moved-aside | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
|
||
## App packaging | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
### Swift Package Manager | ||
Packages/ | ||
Package.pins | ||
Package.resolved | ||
# *.xcodeproj | ||
# | ||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata | ||
# hence it is not needed unless you have added a package configuration file to your project | ||
.swiftpm | ||
.build/ | ||
|
||
### CocoaPods | ||
Pods/ | ||
*.xcworkspace | ||
|
||
### Carthage | ||
Carthage/Checkouts | ||
Carthage/Build/ | ||
|
||
### Accio dependency management | ||
Dependencies/ | ||
.accio/ | ||
|
||
### fastlane | ||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
|
||
### Code Injection | ||
iOSInjectionProject/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: 1 | ||
builder: | ||
configs: | ||
- documentation_targets: [preventScreenshot] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
excluded: | ||
- "*resource_bundle_accessor*" # SwiftPM Generated | ||
- ".build/*" | ||
|
||
opt_in_rules: | ||
- missing_docs | ||
- empty_count | ||
- empty_string | ||
- toggle_bool | ||
- unused_optional_binding | ||
- valid_ibinspectable | ||
- modifier_order | ||
- first_where | ||
- fatal_error_message | ||
- force_unwrapping | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Wesley de Groot, [email protected] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// swift-tools-version: 5.8.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "preventScreenshot", | ||
platforms: [ | ||
.iOS(.v15), | ||
.macOS(.v12), | ||
.tvOS(.v14), | ||
.macCatalyst(.v15) | ||
], | ||
products: [ | ||
// Products define the executables and libraries a package produces, making them visible to other packages. | ||
.library( | ||
name: "preventScreenshot", | ||
targets: ["preventScreenshot"]) | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package, defining a module or a test suite. | ||
// Targets can depend on other targets in this package and products from dependencies. | ||
.target( | ||
name: "preventScreenshot"), | ||
.testTarget( | ||
name: "preventScreenshotTests", | ||
dependencies: ["preventScreenshot"]) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# preventScreenshot | ||
|
||
preventScreenshot allows you to prevents screenshots of a SwiftUI Element. | ||
|
||
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FpreventScreenshot%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/0xWDG/preventScreenshot) | ||
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FpreventScreenshot%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/0xWDG/preventScreenshot) | ||
[![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://swift.org/package-manager) | ||
![License](https://img.shields.io/github/license/0xWDG/preventScreenshot) | ||
|
||
## Requirements | ||
|
||
- Swift 5.9+ (Xcode 15+) | ||
- iOS 13+, macOS 10.15+ | ||
|
||
## Installation (Pakage.swift) | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/0xWDG/preventScreenshot.git", .branch("main")), | ||
], | ||
targets: [ | ||
.target(name: "MyTarget", dependencies: [ | ||
.product(name: "preventScreenshot", package: "preventScreenshot"), | ||
]), | ||
] | ||
``` | ||
|
||
## Installation (Xcode) | ||
|
||
1. In Xcode, open your project and navigate to **File** → **Swift Packages** → **Add Package Dependency...** | ||
2. Paste the repository URL (`https://github.com/0xWDG/preventScreenshot`) and click **Next**. | ||
3. Click **Finish**. | ||
|
||
## Usage | ||
|
||
Example to read a ImageView (Multi platform): | ||
|
||
```swift | ||
import SwiftUI | ||
import preventScreenshot | ||
|
||
struct ContentView: View { | ||
var body: some View { | ||
VStack { | ||
Text("Don't take a screenshot of this") | ||
.preventScreenshot() | ||
} | ||
.padding() | ||
} | ||
} | ||
``` | ||
|
||
## Contact | ||
|
||
We can get in touch via [Twitter/X](https://twitter.com/0xWDG), [Discord](https://discordapp.com/users/918438083861573692), [Mastodon](https://iosdev.space/@0xWDG), [Email](mailto:[email protected]), [Website](https://wesleydegroot.nl). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// Inspect.swift | ||
// Inspect | ||
// | ||
// Created by Wesley de Groot on 25/06/2024. | ||
// https://wesleydegroot.nl | ||
// | ||
// https://github.com/0xWDG/preventScreenshot | ||
// MIT LICENCE | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
#if os(macOS) | ||
public typealias PlatformView = NSView | ||
public typealias PlatformTextField = NSSecureTextField | ||
public typealias PlatformRepresentable = NSViewRepresentable | ||
public typealias PlatformHostingController = NSHostingController | ||
#else | ||
public typealias PlatformView = UIView | ||
public typealias PlatformTextField = UITextField | ||
public typealias PlatformRepresentable = UIViewRepresentable | ||
public typealias PlatformHostingController = UIHostingController | ||
#endif | ||
|
||
/// Screenshot Prevent Wrapper | ||
public struct ScreenshotPreventWrapper<Content: View>: PlatformRepresentable { | ||
let content: () -> Content | ||
|
||
public init(@ViewBuilder content: @escaping () -> Content) { | ||
self.content = content | ||
} | ||
|
||
public func makeNSView(context: Context) -> NSView { | ||
return self.makeUIView(context: context) | ||
} | ||
|
||
public func makeUIView(context: Context) -> PlatformView { | ||
let secureTextField = PlatformTextField() | ||
|
||
#if !os(macOS) | ||
secureTextField.isSecureTextEntry = true | ||
secureTextField.isUserInteractionEnabled = false | ||
#endif | ||
|
||
guard let secureView = secureTextField.layer?.sublayers?.first?.delegate as? PlatformView else { | ||
return PlatformView() | ||
} | ||
|
||
secureView.subviews.forEach { subview in | ||
subview.removeFromSuperview() | ||
} | ||
|
||
let hostedContent = PlatformHostingController(rootView: content()) | ||
#if os(macOS) | ||
// TODO: This seems not to work | ||
hostedContent.view.layer?.backgroundColor = .clear | ||
#else | ||
hController.view.backgroundColor = .clear | ||
#endif | ||
hostedContent.view.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
secureView.addSubview(hostedContent.view) | ||
NSLayoutConstraint.activate([ | ||
hostedContent.view.topAnchor.constraint(equalTo: secureView.topAnchor), | ||
hostedContent.view.bottomAnchor.constraint(equalTo: secureView.bottomAnchor), | ||
hostedContent.view.leadingAnchor.constraint(equalTo: secureView.leadingAnchor), | ||
hostedContent.view.trailingAnchor.constraint(equalTo: secureView.trailingAnchor) | ||
]) | ||
|
||
return secureView | ||
} | ||
|
||
public func updateNSView(_ nsView: PlatformView, context: Context) { } | ||
public func updateUIView(_ uiView: PlatformView, context: Context) { } | ||
} | ||
|
||
|
||
extension View { | ||
@ViewBuilder public func preventScreenshot() -> some View { | ||
ScreenshotPreventWrapper { | ||
self | ||
.redacted(reason: .privacy) | ||
.privacySensitive() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import XCTest | ||
@testable import Inspect | ||
|
||
final class preventScreenshotTests: XCTestCase { | ||
func testExample() throws { | ||
// XCTest Documentation | ||
// https://developer.apple.com/documentation/xctest | ||
|
||
// Defining Test Cases and Test Methods | ||
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods | ||
} | ||
} |
Oops, something went wrong.