Skip to content

Commit f266dcb

Browse files
committed
Restructure Project
1 parent cc7cf07 commit f266dcb

29 files changed

+300
-154
lines changed

.spi.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version: 1
22
builder:
33
configs:
4-
- documentation_targets: [PasscodeKit, PasscodeCore, PasscodeModel, PasscodeUI]
4+
- documentation_targets: [PasscodeKit, PasscodeCore]
5+
custom_documentation_parameters: [--include-extended-types]
56
platform: ios

Demo/Demo/ContentView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import SwiftUI
99
import PasscodeKit
1010
import KeychainSwift
11-
import PasscodeModel
1211

1312
struct ContentView: View {
1413
@Environment(\.passcode.manager) private var passcodeManager

Package.swift

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ let package = Package(
1515
.library(
1616
name: "PasscodeCore",
1717
targets: ["PasscodeCore"]
18-
),
19-
.library(
20-
name: "PasscodeModel",
21-
targets: ["PasscodeModel"]
22-
),
23-
.library(
24-
name: "PasscodeUI",
25-
targets: ["PasscodeUI"]
2618
)
2719
],
2820
dependencies: [
@@ -35,25 +27,14 @@ let package = Package(
3527
name: "PasscodeKit",
3628
dependencies: [
3729
"PasscodeCore",
38-
"PasscodeUI",
30+
.product(name: "SwiftUIIntrospect", package: "swiftui-introspect"),
3931
.product(name: "KeychainSwift", package: "keychain-swift")
40-
]
32+
],
33+
resources: [.process("Resources")]
4134
),
4235
.target(
4336
name: "PasscodeCore",
4437
dependencies: ["WindowSceneReader"]
45-
),
46-
.target(
47-
name: "PasscodeModel",
48-
dependencies: []
49-
),
50-
.target(
51-
name: "PasscodeUI",
52-
dependencies: [
53-
"PasscodeModel",
54-
.product(name: "SwiftUIIntrospect", package: "swiftui-introspect"),
55-
],
56-
resources: [.process("Resources")]
5738
)
5839
]
5940
)

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Easily add a passcode to your iOS app
77

88
## Usage
99

10-
PasscodeKit is split into several modules and depending on what you need you can use different or multiple modules.
10+
PasscodeKit is split into two modules and depending on what you need you can use the main or core module.
1111

1212
### PasscodeKit
1313

1414
<img width="200" alt="Screenshot" src="https://github.com/divadretlaw/PasscodeKit/assets/6899256/f9328b38-7b17-42b0-ab4b-3e07dad4f1d6">
1515

16-
The most complete, but also less customizable, module. Simply add `.passcode(title:hint:)`, with an optional title and hint view, to your root view.
16+
The default module, with UI and handling already setup. Simply add `.passcode(title:hint:)`, with an optional title and hint view, to your root view.
1717

1818
```swift
1919
@main
@@ -49,23 +49,19 @@ passcodeManager.delete()
4949

5050
### PasscodeCore
5151

52-
The core module, that handles displaying the passcode window. By default it has no UI to enter a passcode or setting up and storing the passcode, but you can use this to implement your own passcode UI.
52+
The core module, that handles displaying the passcode window. By default it has no UI to enter a passcode or setting up and storing the passcode, but you can use this as a base to implement your own UI.
5353

5454
```swift
5555
.passcode(mode: PasscodeMode) { dismiss in
56-
// some Passcode input UI
56+
// some Passcode input UI, call `dismiss(animated:)` once finished
5757
} background: {
58-
// some optional background
58+
// some optional background view
5959
}
6060
```
6161

62-
### PasscodeUI
63-
64-
The UI used in `PasscodeKit` without dependencies on `PasscodeCore` and `PasscodeKit`
65-
6662
#### Localization
6763

68-
Customize / Localize the `PasscodeUI` by providing a `Passcode.strings` file in your main app bundle. See the default [Passcode.strings](Sources/PasscodeUI/Resources/Passcode.strings) file for English Strings.
64+
Customize / Localize the `PasscodeKit` by providing a `Passcode.strings` file in your main app bundle. See the default [Passcode.strings](Sources/PasscodeKit/Resources/Passcode.strings) file for English Strings.
6965

7066
## Installation
7167

@@ -77,16 +73,16 @@ Add the following package URL to Xcode
7773
https://github.com/divadretlaw/PasscodeKit
7874
```
7975

80-
Select the module(s) you need
76+
Select the module you need
8177

82-
![Xcode](https://github.com/divadretlaw/PasscodeKit/assets/6899256/457e60c8-9146-4c57-bf2a-83f970b0e203)
78+
![Xcode](https://github.com/divadretlaw/PasscodeKit/assets/6899256/081ca701-deb1-4230-9e8e-25d9fe24e803)
8379

8480
### Swift Package Manager
8581

8682
```swift
8783
let package = Package(
8884
dependencies: [
89-
.package(url: "https://github.com/divadretlaw/PasscodeKit.git", from: "0.3.0"),
85+
.package(url: "https://github.com/divadretlaw/PasscodeKit.git", from: "0.7.0")
9086
],
9187
targets: [
9288
.target(

Sources/PasscodeCore/Environment/Configuration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import SwiftUI
99

1010
public extension PasscodeEnvironmentValues {
11+
/// The duration of the dismiss animation.
1112
var animatedDismissDuration: TimeInterval {
1213
get { self[AnimatedDismissDurationKey.self] }
1314
set { self[AnimatedDismissDurationKey.self] = newValue }
1415
}
1516

17+
/// The `ColorScheme` of the passcode overlay.
1618
var colorScheme: ColorScheme? {
1719
get { self[ColorSchemeKey.self] }
1820
set { self[ColorSchemeKey.self] = newValue }

Sources/PasscodeCore/Environment/DismissPasscodeAction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct DismissPasscodeAction {
2828
///
2929
/// var body: some View {
3030
/// Button("Dismiss Passcode") {
31-
/// dismissPasscode() // Implicitly calls dismissPasscode.callAsFunction()
31+
/// dismissPasscode(animated: true) // Implicitly calls dismissPasscode.callAsFunction(animated:)
3232
/// }
3333
/// }
3434
/// }
@@ -55,7 +55,7 @@ extension View {
5555
///
5656
/// - Parameters:
5757
/// - action: A closure to run when passcode should dismiss. The closure
58-
/// takes a `animated` parameter that indicates wheter the dismiss should be animated
58+
/// takes a `animated` parameter that indicates whether the dismiss should be animated
5959
/// or not.
6060
///
6161
/// - Returns: A view that runs an action when the passcode should dismiss.

Sources/PasscodeKit/API.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
//
77

88
import SwiftUI
9-
import PasscodeCore
10-
import PasscodeModel
11-
import PasscodeUI
9+
@_exported import PasscodeCore
1210
import KeychainSwift
1311

1412
public extension View {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//
2+
// CodeViewConfiguration.swift
3+
// PasscodeKit
4+
//
5+
// Created by David Walter on 02.09.23.
6+
//
7+
8+
import SwiftUI
9+
import PasscodeCore
10+
11+
/// Customize the code view
12+
public struct CodeViewConfiguration {
13+
var foregroundColor: Color = .primary
14+
var emptyImage = Image(systemName: "circle")
15+
var filledImage = Image(systemName: "circle.fill")
16+
var spacing: CGFloat = 20
17+
18+
/// Configures the foreground color.
19+
/// - Parameter color: The color to use.
20+
/// - Returns: The configuration with the foreground color configured.
21+
func foregroundColor(_ color: Color) -> Self {
22+
var configuration = self
23+
configuration.foregroundColor = color
24+
return configuration
25+
}
26+
27+
/// Configures the empty image code point.
28+
/// - Parameter image: The name of the system symbol image to use as empty code point.
29+
/// - Returns: The configuration with the empty image configured.
30+
func empty(systemName: String) -> Self {
31+
var configuration = self
32+
configuration.emptyImage = Image(systemName: systemName)
33+
return configuration
34+
}
35+
36+
/// Configures the empty image code point.
37+
/// - Parameter image: The name of the system symbol image to use as empty code point.
38+
/// - Returns: The configuration with the empty image configured.
39+
func empty(image: Image) -> Self {
40+
var configuration = self
41+
configuration.emptyImage = image
42+
return configuration
43+
}
44+
45+
/// Configures the filled image code point.
46+
/// - Parameter image: The name of the system symbol image to use as filled code point.
47+
/// - Returns: The configuration with the filled image configured.
48+
func filled(systemName: String) -> Self {
49+
var configuration = self
50+
configuration.filledImage = Image(systemName: systemName)
51+
return configuration
52+
}
53+
54+
/// Configures the filled image code point.
55+
/// - Parameter image: The image to use as filled code point.
56+
/// - Returns: The configuration with the filled image configured.
57+
func filled(image: Image) -> Self {
58+
var configuration = self
59+
configuration.filledImage = image
60+
return configuration
61+
}
62+
63+
/// Configures the spacing between the code points.
64+
/// - Parameter value: The spacing to use.
65+
/// - Returns: The configuration with the spacing configured.
66+
func spacing(_ value: CGFloat) -> Self {
67+
var configuration = self
68+
configuration.spacing = spacing
69+
return configuration
70+
}
71+
}
72+
73+
public extension PasscodeEnvironmentValues {
74+
var codeViewConfiguration: CodeViewConfiguration {
75+
get { self[CodeViewConfigurationKey.self] }
76+
set { self[CodeViewConfigurationKey.self] = newValue }
77+
}
78+
}
79+
80+
private struct CodeViewConfigurationKey: EnvironmentKey {
81+
static var defaultValue: CodeViewConfiguration {
82+
CodeViewConfiguration()
83+
}
84+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// KeypadViewConfiguration.swift
3+
// PasscodeKit
4+
//
5+
// Created by David Walter on 02.09.23.
6+
//
7+
8+
import SwiftUI
9+
import PasscodeCore
10+
11+
/// Customize the keypad view
12+
public struct KeypadViewConfiguration {
13+
var foregroundColor: Color = .primary
14+
var hSpacing: CGFloat = 40
15+
var vSpacing: CGFloat = 20
16+
var deleteImage = Image(systemName: "delete.left")
17+
18+
/// Configures the foreground color.
19+
/// - Parameter color: The color to use.
20+
/// - Returns: The configuration with the foreground color configured.
21+
func foregroundColor(_ color: Color) -> Self {
22+
var configuration = self
23+
configuration.foregroundColor = color
24+
return configuration
25+
}
26+
27+
/// Sets the spacing between the button.
28+
/// - Parameters:
29+
/// - vertical: The vertical spacing.
30+
/// - horizontal: The horizontal spacing.
31+
/// - Returns: The configuration with the spacing configured.
32+
func spacing(vertical: CGFloat? = nil, horizontal: CGFloat? = nil) -> Self {
33+
var configuration = self
34+
if let vertical = vertical {
35+
configuration.vSpacing = vertical
36+
}
37+
if let horizontal = horizontal {
38+
configuration.hSpacing = horizontal
39+
}
40+
return configuration
41+
}
42+
43+
/// Configures the image for the delete button.
44+
/// - Parameter image: The name of the system symbol image to use.
45+
/// - Returns: The configuration with the delete image configured.
46+
func delete(systemName: String) -> Self {
47+
var configuration = self
48+
configuration.deleteImage = Image(systemName: systemName)
49+
return configuration
50+
}
51+
52+
/// Configures the image for the delete button.
53+
/// - Parameter image: The name of the system symbol image to use.
54+
/// - Returns: The configuration with the delete image configured.
55+
func delete(image: Image) -> Self {
56+
var configuration = self
57+
configuration.deleteImage = image
58+
return configuration
59+
}
60+
}
61+
62+
public extension PasscodeEnvironmentValues {
63+
var keypadViewConfiguration: KeypadViewConfiguration {
64+
get { self[KeypadViewConfigurationKey.self] }
65+
set { self[KeypadViewConfigurationKey.self] = newValue }
66+
}
67+
}
68+
69+
private struct KeypadViewConfigurationKey: EnvironmentKey {
70+
static var defaultValue: KeypadViewConfiguration {
71+
KeypadViewConfiguration()
72+
}
73+
}

0 commit comments

Comments
 (0)