Skip to content

Commit

Permalink
feat: API Improvements
Browse files Browse the repository at this point in the history
- Rename `ShyView` to `SecureContainerView`
- Add `ShyView` properyWrapper
- Add `runtimeWarning` `IncompatibilityHandler`
- Add SwiftUI support
- Update example
- Add swiftpackageindex docc docs
- Update CI workflow
- Update podspec
  • Loading branch information
maximkrouk committed Dec 27, 2023
1 parent 4ac1d92 commit af4b080
Show file tree
Hide file tree
Showing 28 changed files with 814 additions and 320 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ on:

jobs:
test-ios:
name: "macOS 12 (Xcode 14.0)"
runs-on: macos-12
name: "macOS 13 (Xcode 15.0)"
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- name: Select Xcode 14.0
run: sudo xcode-select -s /Applications/Xcode_14.0.app
- name: Select Xcode 15.1
run: sudo xcode-select -s /Applications/Xcode_15.1.app
- name: Run tests
run: make test-ios
5 changes: 5 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
builder:
- platform: ios
documentation_targets: [ShyView]
swift_version: 5.9
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- ShyView (0.2.0)
- ShyView (0.3.0)

DEPENDENCIES:
- ShyView (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ShyView: 1c4e992d875830b975da4da9a05c8744f7e99078
ShyView: 2c67cf242f9320c96c2a2326abf7956a784d3bf1

PODFILE CHECKSUM: 274f9073cceb255d19ab7e6e29abcacc0c16cebd

Expand Down
6 changes: 3 additions & 3 deletions Example/Pods/Local Podspecs/ShyView.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

227 changes: 128 additions & 99 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 9 additions & 27 deletions Example/ShyView/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,19 @@ import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


func applicationWillResignActive(_ application: UIApplication) {}
func applicationDidEnterBackground(_ application: UIApplication) {}
func applicationWillEnterForeground(_ application: UIApplication) {}
func applicationDidBecomeActive(_ application: UIApplication) {}
func applicationWillTerminate(_ application: UIApplication) {}
}

9 changes: 5 additions & 4 deletions Example/ShyView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ViewController: UIViewController {
balanceLabel.text = "123,456€"
balanceLabel.textColor = .white

headerStackView.addArrangedSubview(balanceLabel.privacySensitive())
headerStackView.addArrangedSubview(SecureContainerView(balanceLabel)!)
}
}

Expand Down Expand Up @@ -72,8 +72,9 @@ class TransactionCell: UITableViewCell {
@IBOutlet private weak var categoryLabel: UILabel!
@IBOutlet private weak var contentStackView: UIStackView!

let amountLabel = UILabel()

@ShyView
var amountLabel: UILabel

lazy var formatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
Expand All @@ -83,7 +84,7 @@ class TransactionCell: UITableViewCell {

override func awakeFromNib() {
super.awakeFromNib()
contentStackView.addArrangedSubview(ShyView(amountLabel) ?? amountLabel)
contentStackView.addArrangedSubview(_amountLabel)
}

func configure(transaction: Transaction) {
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test-ios:
xcodebuild \
-scheme ShyView \
-destination platform="iOS Simulator,name=iPhone 14 Pro,OS=16.0" \
-destination platform="iOS Simulator,name=iPhone 15 Pro,OS=17.0" \
test | xcpretty && exit 0 \
10 changes: 6 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// swift-tools-version: 5.6
// swift-tools-version: 5.8

import PackageDescription

let package = Package(
name: "ShyView",
platforms: [
.iOS(.v11),
.macOS(.v10_10),
.tvOS(.v10),
.iOS(.v12),
.macOS(.v10_15),
.macCatalyst(.v13),
.watchOS(.v6),
.tvOS(.v12),
],
products: [
.library(
Expand Down
4 changes: 2 additions & 2 deletions ShyView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ShyView'
s.version = '0.2.0'
s.version = '0.3.0'
s.summary = 'A UI component that avoid schreenshots and recordings'

s.description = <<-DESC
Expand All @@ -20,7 +20,7 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/MarioIannotta/ShyView.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/marioiannotta'

s.source_files = 'Sources/ShyView/ShyView.swift'
s.source_files = 'Sources/ShyView/**/*'
s.swift_version = '5'
s.ios.deployment_target = '13.0'
end
74 changes: 74 additions & 0 deletions Sources/ShyView/Helpers/RuntimeWarnings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Source: https://github.com/pointfreeco/swift-composable-architecture/blob/main/Sources/ComposableArchitecture/Internal/RuntimeWarnings.swift

import Foundation

extension Notification.Name {
public static let runtimeWarning = Self("ShyView.runtimeWarning")
}

@_transparent
@usableFromInline
@inline(__always)
func runtimeWarn(
_ message: @autoclosure () -> String,
category: String? = "ShyView"
) {
#if DEBUG
let message = message()
NotificationCenter.default.post(
name: .runtimeWarning,
object: nil,
userInfo: ["message": message]
)
let category = category ?? "Runtime Warning"

#if canImport(os)
os_log(
.fault,
dso: dso,
log: OSLog(subsystem: "com.apple.runtime-issues", category: category),
"%@",
message
)
#else
fputs("\(formatter.string(from: Date())) [\(category)] \(message)\n", stderr)
#endif
#endif
}

#if DEBUG

#if canImport(os)
import os

// NB: Xcode runtime warnings offer a much better experience than traditional assertions and
// breakpoints, but Apple provides no means of creating custom runtime warnings ourselves.
// To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
//
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
@usableFromInline
let dso = { () -> UnsafeMutableRawPointer in
let count = _dyld_image_count()
for i in 0..<count {
if let name = _dyld_get_image_name(i) {
let swiftString = String(cString: name)
if swiftString.hasSuffix("/SwiftUI") {
if let header = _dyld_get_image_header(i) {
return UnsafeMutableRawPointer(mutating: UnsafeRawPointer(header))
}
}
}
}
return UnsafeMutableRawPointer(mutating: #dsohandle)
}()
#else
import Foundation

@usableFromInline
let formatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:MM:SS.sssZ"
return formatter
}()
#endif
#endif
28 changes: 28 additions & 0 deletions Sources/ShyView/Helpers/UIView+Layout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// UIView+Layout.swift
// ShyView
//
// Created by Maxim Krouk on 01/09/2023.
//

#if canImport(UIKit) && !os(watchOS) && !os(tvOS)
import UIKit

extension UIView {
func pinEdgesToSuperview() {
guard let superview else { return }
pinEdges(to: superview)
}

func pinEdges(to target: UIView) {
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
topAnchor.constraint(equalTo: target.topAnchor),
bottomAnchor.constraint(equalTo: target.bottomAnchor),
leadingAnchor.constraint(equalTo: target.leadingAnchor),
trailingAnchor.constraint(equalTo: target.trailingAnchor)
])
}
}

#endif
23 changes: 23 additions & 0 deletions Sources/ShyView/Helpers/UIView+SecureView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// UIView+SecureView.swift
// ShyView
//
// Created by Maxim Krouk on 01/09/2023.
//

#if canImport(UIKit) && !os(watchOS) && !os(tvOS)
import UIKit

extension UIView {
static func makeSecureView() -> UIView? {
let secureView: UIView?
let textField = UITextField()
textField.isSecureTextEntry = true
secureView = textField.layer.sublayers?.first?.delegate as? UIView
secureView?.subviews.forEach { $0.removeFromSuperview() }
secureView?.isUserInteractionEnabled = true
return secureView
}
}

#endif
Loading

0 comments on commit af4b080

Please sign in to comment.