Skip to content

Commit 87b24bb

Browse files
authored
Merge pull request #37 from jevonmao/develop
Improve accent color customization. For v1.2.3
2 parents f07c9ad + 3181dd5 commit 87b24bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+182
-13936
lines changed

Sources/PermissionsSwiftUI/Components/Shared/PermissionSection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct PermissionSectionCell: View {
8888
let currentPermission = self.permission.currentPermission
8989
HStack {
9090
currentPermission.imageIcon
91-
.foregroundColor(Color.blue)
91+
.foregroundColor(PermissionStore.shared.allButtonColors.primaryColor)
9292
.font(.system(size: screenSizeConstant))
9393
.frame(width: screenSizeConstant)
9494
.padding(.horizontal, 5)

Sources/PermissionsSwiftUI/Model/JMPermissionModel.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ public struct JMPermission:Equatable{
2828
- Attention:
2929
The `JMPermission` structure is made public only for obervation purposes. Users of PermissionsSwiftUI should not be calling `JMPermission` constructor directly.
3030
*/
31-
public init(imageIcon: AnyView, title: String, description: String, authorized: Bool) {
31+
public init(imageIcon: AnyView, title: String, description: String) {
32+
self.imageIcon = imageIcon
33+
self.title = title
34+
self.description = description
35+
}
36+
internal init(imageIcon: AnyView, title: String, description: String, authorized: Bool) {
3237
self.imageIcon = imageIcon
3338
self.title = title
3439
self.description = description
3540
self.authorized = authorized
3641
}
37-
3842
public static func == (lhs: JMPermission, rhs: JMPermission) -> Bool {
3943
if lhs.title == rhs.title && lhs.description == rhs.description && lhs.authorized == rhs.authorized{
4044
return true
@@ -44,10 +48,9 @@ public struct JMPermission:Equatable{
4448
}
4549
}
4650

47-
48-
var imageIcon: AnyView
49-
var title: String
50-
var description: String
51-
var authorized:Bool
51+
public var imageIcon: AnyView
52+
public var title: String
53+
public var description: String
54+
internal var authorized:Bool = false
5255

5356
}

Sources/PermissionsSwiftUI/Model/PermissionStore.swift

Lines changed: 110 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@
88
import Foundation
99
import SwiftUI
1010

11-
//MARK: Storage
12-
struct PermissionStore {
13-
private init(){}
11+
//MARK: - Storage
12+
/**
13+
The global shared storage for PermissionsSwiftUI
14+
*/
15+
public struct PermissionStore {
16+
//MARK: Init and Singleton Management
17+
/**
18+
Initalizes and returns a new instance of `PermissionStore`
19+
20+
The `PermissionStore` initliazer accepts no parameters, instead, set properties after intialization:
21+
```
22+
let store = PermissionStore()
23+
store.mainTexts.headerText = "PermissionsSwiftUI is the best library"
24+
*/
25+
public init(){}
1426
//a private singleton instance that allows read & write, but for this file's methods only
1527
fileprivate static var mutableShared = PermissionStore()
1628
//Read only singleton exposed to other parts of program
@@ -19,99 +31,127 @@ struct PermissionStore {
1931
mutableShared
2032
}
2133
}
22-
var permissions: [PermissionType] = []
34+
///A global array of permissions that configures the permissions to request
35+
public var permissions: [PermissionType] = []
2336
var permissionsToAsk: [PermissionType]{
2437
FilterPermissions.filterForShouldAskPermission(for: permissions)
2538
}
26-
var mainTexts = MainTexts()
27-
var allButtonColors = AllButtonColors()
28-
var autoDismissModal: Bool = true
29-
var autoDismissAlert: Bool = true
30-
var autoCheckModalAuth: Bool = true
31-
var autoCheckAlertAuth: Bool = true
32-
var onAppear: (()->Void)?
33-
var onDisappear: (()->Void)?
34-
struct MainTexts{
35-
var headerText: String = "Need Permissions"
36-
var headerDescription: String = """
39+
//MARK: Secondary Components
40+
///The text for text label components, including header and descriptions
41+
public var mainTexts = MainTexts()
42+
///The color configuration for permission allow buttons
43+
public var allButtonColors = AllButtonColors()
44+
///Whether to auto dismiss the modal after last permission is allowed
45+
public var autoDismissModal: Bool = true
46+
///Whether to auto dismiss the alert after last permission is allowed
47+
public var autoDismissAlert: Bool = true
48+
///Whether to auto check for authorization status before showing, and show the view only if permission is in `notDetermined`
49+
public var autoCheckModalAuth: Bool = true
50+
///Whether to auto check for authorization status before showing, and show the view only if permission is in `notDetermined`
51+
public var autoCheckAlertAuth: Bool = true
52+
///Override point for executing action when PermissionsSwiftUI view appears
53+
public var onAppear: (()->Void)?
54+
///Override point for executing action when PermissionsSwiftUI view disappears
55+
public var onDisappear: (()->Void)?
56+
public struct MainTexts{
57+
///Text to display for header text
58+
public var headerText: String = "Need Permissions"
59+
///Text to display for header description text
60+
public var headerDescription: String = """
3761
In order for you use certain features of this app, you need to give permissions. See description for each permission
3862
"""
39-
var bottomDescription: String = """
63+
///Text to display for bottom part description text
64+
public var bottomDescription: String = """
4065
Permission are necessary for all the features and functions to work properly. If not allowed, you have to enable permissions in settings
4166
"""
4267
}
43-
var cameraPermission = JMPermission(
68+
//MARK: Permission Components
69+
///The displayed text and image icon for the camera permission
70+
public var cameraPermission = JMPermission(
4471
imageIcon: AnyView(Image(systemName: "camera.fill")),
4572
title: "Camera",
4673
description: "Allow to use your camera", authorized: false)
47-
48-
var locationPermission = JMPermission(
74+
///The displayed text and image icon for the location permission
75+
public var locationPermission = JMPermission(
4976
imageIcon: AnyView(Image(systemName: "location.fill.viewfinder")),
5077
title: "Location",
5178
description: "Allow to access your location", authorized: false
5279
)
53-
var locationAlwaysPermission = JMPermission(
80+
///The displayed text and image icon for the location always permission
81+
public var locationAlwaysPermission = JMPermission(
5482
imageIcon: AnyView(Image(systemName: "location.fill.viewfinder")),
5583
title: "Location Always",
5684
description: "Allow to access your location", authorized: false
5785
)
58-
var photoPermission = JMPermission(
86+
///The displayed text and image icon for the photo library permission
87+
public var photoPermission = JMPermission(
5988
imageIcon: AnyView(Image(systemName: "photo")),
6089
title: "Photo Library",
6190
description: "Allow to access your photos", authorized: false
6291
)
63-
var microphonePermisson = JMPermission(
92+
///The displayed text and image icon for the microphone permission
93+
public var microphonePermisson = JMPermission(
6494
imageIcon: AnyView(Image(systemName: "mic.fill")),
6595
title: "Microphone",
6696
description: "Allow to record with microphone", authorized: false
6797
)
68-
var notificationPermission = JMPermission(
98+
///The displayed text and image icon for the notification center permission
99+
public var notificationPermission = JMPermission(
69100
imageIcon: AnyView(Image(systemName: "bell.fill")),
70101
title: "Notification",
71102
description: "Allow to send notifications", authorized: false
72103
)
73-
var calendarPermisson = JMPermission(
104+
///The displayed text and image icon for the calendar permission
105+
public var calendarPermisson = JMPermission(
74106
imageIcon: AnyView(Image(systemName: "calendar")),
75107
title: "Calendar",
76108
description: "Allow to access calendar", authorized: false
77109
)
78-
var bluetoothPermission = JMPermission(
110+
///The displayed text and image icon for the bluetooth permission
111+
public var bluetoothPermission = JMPermission(
79112
imageIcon: AnyView(Image(systemName: "wave.3.left.circle.fill")),
80113
title: "Bluetooth",
81114
description: "Allow to use bluetooth", authorized: false
82115
)
83-
var trackingPermission = JMPermission(
116+
///The displayed text and image icon for the permission to track across apps and websites
117+
public var trackingPermission = JMPermission(
84118
imageIcon: AnyView(Image(systemName: "person.circle.fill")),
85119
title: "Tracking",
86120
description: "Allow to track your data", authorized: false
87121
)
88-
var contactsPermission = JMPermission(
122+
///The displayed text and image icon for the contact permission
123+
public var contactsPermission = JMPermission(
89124
imageIcon: AnyView(Image(systemName: "book.fill")),
90125
title: "Contacts",
91126
description: "Allow to access your contacts", authorized: false
92127
)
93-
var motionPermission = JMPermission(
128+
///The displayed text and image icon for the motion permission
129+
public var motionPermission = JMPermission(
94130
imageIcon: AnyView(Image(systemName: "hare.fill")),
95131
title: "Motion",
96132
description: "Allow to access your motion sensor data", authorized: false
97133
)
98-
var remindersPermission = JMPermission(
134+
///The displayed text and image icon for the reminders permission
135+
public var remindersPermission = JMPermission(
99136
imageIcon: AnyView(Image(systemName: "list.bullet.rectangle")),
100137
title: "Reminders",
101138
description: "Allow to access your reminders", authorized: false
102139
)
103-
var speechPermission = JMPermission(
140+
///The displayed text and image icon for the speech recognition permission
141+
public var speechPermission = JMPermission(
104142
imageIcon: AnyView(Image(systemName: "rectangle.3.offgrid.bubble.left.fill")),
105143
title: "Speech",
106144
description: "Allow to access speech recognition", authorized: false
107145
)
108-
var healthPermission = JMPermission(imageIcon: AnyView(Image(systemName: "heart.fill")),
109-
title: "Health",
110-
description: "Allow to access your health information",
111-
authorized: false)
146+
///The displayed text and image icon for the health permission
147+
public var healthPermission = JMPermission(
148+
imageIcon: AnyView(Image(systemName: "heart.fill")),
149+
title: "Health",
150+
description: "Allow to access your health information",
151+
authorized: false)
112152

113153
}
114-
// MARK: Updating methods
154+
// MARK: - Updating methods
115155
extension PermissionStore{
116156
//Used for unit testing, need to reset storage before each subtest
117157
static func resetPermissionsModelStore(){
@@ -123,6 +163,7 @@ extension PermissionStore{
123163
property(&PermissionStore.mutableShared, value)
124164
}
125165
}
166+
// MARK: - Button Customizations
126167
/**
127168
`AllButtonColors` encapsulates the color configuration for all states of the allow button
128169

@@ -132,19 +173,15 @@ extension PermissionStore{
132173
3. Pass in the `AllButtonColors` struct previously into the proper parameter
133174
*/
134175
public struct AllButtonColors{
135-
public var buttonIdle = ButtonColor(foregroundColor: Color(.systemBlue),
136-
backgroundColor: Color(.systemGray5))
137-
public var buttonAllowed = ButtonColor(foregroundColor: Color(.white),
138-
backgroundColor: Color(.systemBlue))
139-
public var buttonDenied = ButtonColor(foregroundColor: Color(.white),
140-
backgroundColor: Color(.systemRed))
176+
//MARK: Creating New Button Configs
141177
/**
142178
- parameters:
143179
- buttonIdle: The button color configuration for the default, idle state
144180
- buttonAllowed: The button color configuration for the highlighted, allowed state
145181
- buttonDenied: The button color configuration for the user explicitly denied state
146182
*/
147183
public init(buttonIdle: ButtonColor, buttonAllowed: ButtonColor, buttonDenied: ButtonColor){
184+
self.init()
148185
self.buttonIdle = buttonIdle
149186
self.buttonAllowed = buttonAllowed
150187
self.buttonDenied = buttonDenied
@@ -154,23 +191,47 @@ public struct AllButtonColors{
154191
- buttonIdle: The button color configuration for the default, idle state
155192
*/
156193
public init(buttonIdle: ButtonColor){
194+
self.init()
157195
self.buttonIdle = buttonIdle
158196
}
159197
/**
160198
- parameters:
161199
- buttonAllowed: The button color configuration for the highlighted, allowed state
162200
*/
163201
public init(buttonAllowed: ButtonColor){
202+
self.init()
164203
self.buttonAllowed = buttonAllowed
165204
}
166205
/**
167206
- parameters:
168207
- buttonDenied: The button color configuration for the user explicitly denied state
169208
*/
170209
public init(buttonDenied: ButtonColor){
210+
self.init()
171211
self.buttonDenied = buttonDenied
172212
}
173-
public init(){}
213+
214+
public init(primaryColor: Color?=nil, tertiaryColor: Color?=nil){
215+
self.primaryColor = primaryColor ?? Color(.systemBlue)
216+
self.tertiaryColor = tertiaryColor ?? Color(.systemRed)
217+
self.buttonIdle = ButtonColor(foregroundColor: self.primaryColor,
218+
backgroundColor: Color(.systemGray5))
219+
self.buttonAllowed = ButtonColor(foregroundColor: Color(.white),
220+
backgroundColor: self.primaryColor)
221+
self.buttonDenied = ButtonColor(foregroundColor: Color(.white),
222+
backgroundColor: self.tertiaryColor)
223+
}
224+
225+
//MARK: Button Color States
226+
227+
var primaryColor: Color
228+
var tertiaryColor: Color
229+
///The button color configuration under idle status defined by a `ButtonColor` struct
230+
public var buttonIdle: ButtonColor
231+
///The button color configuration under allowed status defined by a `ButtonColor` struct
232+
public var buttonAllowed: ButtonColor
233+
///The button color configuration under denied status defined by a `ButtonColor` struct
234+
public var buttonDenied: ButtonColor
174235
}
175236

176237
/**
@@ -180,10 +241,7 @@ public struct AllButtonColors{
180241
To customize
181242
*/
182243
public struct ButtonColor{
183-
//The color of type `Color` for the foreground text
184-
public var foregroundColor: Color
185-
//The color of type `Color` for the foreground text
186-
public var backgroundColor: Color
244+
// MARK: Creating New Button Color
187245
/**
188246
- parameters:
189247
- foregroundColor: The color of type `Color` for the foreground text
@@ -193,4 +251,10 @@ public struct ButtonColor{
193251
self.foregroundColor = foregroundColor
194252
self.backgroundColor = backgroundColor
195253
}
254+
//MARK: Properties
255+
///The color of type `Color` for the foreground text
256+
public var foregroundColor: Color
257+
///The color of type `Color` for the foreground text
258+
public var backgroundColor: Color
259+
196260
}

0 commit comments

Comments
 (0)