Skip to content

Commit f07c9ad

Browse files
authored
Merge pull request #36 from jevonmao/develop
Implement cutomize button accent color
2 parents 5875481 + 13c231d commit f07c9ad

Some content is hidden

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

44 files changed

+3302
-265
lines changed

Sources/PermissionsSwiftUI/Model/Mocks/MockNotificationManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protocol NotificationManager {
1515
}
1616
extension UNUserNotificationCenter:NotificationManager{
1717
static func shared() -> NotificationManager {
18-
UNUserNotificationCenter.current()
18+
return UNUserNotificationCenter.current()
1919
}
2020
func requestPermission(options: UNAuthorizationOptions=[], completionHandler: @escaping (Bool, Error?) -> Void) {
2121
self.requestAuthorization(options: options) { granted, error in

Sources/PermissionsSwiftUI/Model/PermissionStore.swift

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct PermissionStore {
2424
FilterPermissions.filterForShouldAskPermission(for: permissions)
2525
}
2626
var mainTexts = MainTexts()
27+
var allButtonColors = AllButtonColors()
2728
var autoDismissModal: Bool = true
2829
var autoDismissAlert: Bool = true
2930
var autoCheckModalAuth: Bool = true
@@ -122,3 +123,74 @@ extension PermissionStore{
122123
property(&PermissionStore.mutableShared, value)
123124
}
124125
}
126+
/**
127+
`AllButtonColors` encapsulates the color configuration for all states of the allow button
128+
129+
To customize button colors:
130+
1. Define a new instance of the `AllButtonColors` struct
131+
2. Add the `setAllowButtonColor(to colors:AllButtonColors)` modifier to your view
132+
3. Pass in the `AllButtonColors` struct previously into the proper parameter
133+
*/
134+
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))
141+
/**
142+
- parameters:
143+
- buttonIdle: The button color configuration for the default, idle state
144+
- buttonAllowed: The button color configuration for the highlighted, allowed state
145+
- buttonDenied: The button color configuration for the user explicitly denied state
146+
*/
147+
public init(buttonIdle: ButtonColor, buttonAllowed: ButtonColor, buttonDenied: ButtonColor){
148+
self.buttonIdle = buttonIdle
149+
self.buttonAllowed = buttonAllowed
150+
self.buttonDenied = buttonDenied
151+
}
152+
/**
153+
- parameters:
154+
- buttonIdle: The button color configuration for the default, idle state
155+
*/
156+
public init(buttonIdle: ButtonColor){
157+
self.buttonIdle = buttonIdle
158+
}
159+
/**
160+
- parameters:
161+
- buttonAllowed: The button color configuration for the highlighted, allowed state
162+
*/
163+
public init(buttonAllowed: ButtonColor){
164+
self.buttonAllowed = buttonAllowed
165+
}
166+
/**
167+
- parameters:
168+
- buttonDenied: The button color configuration for the user explicitly denied state
169+
*/
170+
public init(buttonDenied: ButtonColor){
171+
self.buttonDenied = buttonDenied
172+
}
173+
public init(){}
174+
}
175+
176+
/**
177+
`ButtonColor` represents the color configuration for the allow button in a single state
178+
179+
Declared within parent struct `AllButtonColors` and should only be used within a `AllButtonColors` struct instance.
180+
To customize
181+
*/
182+
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
187+
/**
188+
- parameters:
189+
- foregroundColor: The color of type `Color` for the foreground text
190+
- backgroundColor: The color of type `Color` for the background
191+
*/
192+
public init(foregroundColor: Color, backgroundColor: Color){
193+
self.foregroundColor = foregroundColor
194+
self.backgroundColor = backgroundColor
195+
}
196+
}

Sources/PermissionsSwiftUI/Model/PermissionTypeGetSet.swift

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -145,65 +145,3 @@ extension PermissionType:CaseIterable{
145145
}
146146
}
147147
}
148-
//switch self {
149-
//case .location:
150-
// JMLocationPermissionAlwaysManager.shared.requestInUsePermission { authorized in
151-
// isPermissionGranted(authorized)
152-
// }
153-
//case .locationAlways:
154-
// JMLocationPermissionAlwaysManager.shared.requestAlwaysPermission { authorized in
155-
// isPermissionGranted(authorized)
156-
// }
157-
//case .photo:
158-
// JMPhotoPermissionManager.shared.requestPermission { authorized in
159-
// isPermissionGranted(authorized)
160-
// }
161-
//case .microphone:
162-
// JMMicPermissionManager.shared.requestPermission { authorized in
163-
// isPermissionGranted(authorized)
164-
// }
165-
//case .camera:
166-
// JMCameraPermissionManager.shared.requestPermission { authorized in
167-
// isPermissionGranted(authorized)
168-
// }
169-
//case .notification:
170-
// JMNotificationPermissionManager.shared.requestPermission { authorized in
171-
// isPermissionGranted(authorized)
172-
// }
173-
//case .calendar:
174-
// JMCalendarPermissionManager.shared.requestPermission { authorized in
175-
// isPermissionGranted(authorized)
176-
// }
177-
//
178-
//case .bluetooth:
179-
// JMBluetoothPermissionManager.shared.requestPermission { authorized in
180-
// isPermissionGranted(authorized)
181-
//
182-
// }
183-
//case .tracking:
184-
// if #available(iOS 14.5, *) {
185-
// JMTrackingPermissionManager.shared.requestPermission{authorized in
186-
// isPermissionGranted(authorized)
187-
// }
188-
// }
189-
//case .contacts:
190-
// JMContactsPermissionManager.shared.requestPermission{authorized in
191-
// isPermissionGranted(authorized)
192-
// }
193-
//case .motion:
194-
// JMMotionPermissionManager.shared.requestPermission{authorized in
195-
// isPermissionGranted(authorized)
196-
// }
197-
//case .reminders:
198-
// JMRemindersPermissionManager.shared.requestPermission{
199-
// isPermissionGranted($0)
200-
// }
201-
//case .speech:
202-
// JMSpeechPermissionManager.shared.requestPermission{
203-
// isPermissionGranted($0)
204-
// }
205-
//case let .health:
206-
// JMHealthPermissionManager.shared.requestPermission{
207-
// isPermissionGranted($0)
208-
// }
209-
//}

Sources/PermissionsSwiftUI/Modifiers/JMPermission API/PermissionCustomModifiers.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,24 @@ public extension View{
9595
)
9696
return self
9797
}
98+
99+
/**
100+
Customizes the color of allow buttons for all status states
101+
102+
The customization of button colors with this modifier applies to both `JMAlert` and `JMModal` views
103+
104+
To customize button colors:
105+
1. Define a new instance of the `AllButtonColors` struct
106+
2. Add the `setAllowButtonColor(to colors:AllButtonColors)` modifier to your view
107+
3. Pass in the `AllButtonColors` struct previously into the proper parameter
108+
109+
- Parameters:
110+
- for: `PermissonType` specifying the permission component
111+
- description: The description text
112+
*/
113+
114+
func setAllowButtonColor(to colors:AllButtonColors) -> some View {
115+
PermissionStore.shared.updateStore(property: {$0.allButtonColors=$1}, value: colors)
116+
return self
117+
}
98118
}

Sources/PermissionsSwiftUI/Modifiers/ViewModifiers.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ import SwiftUI
1111
struct ButtonStatusColor: ViewModifier {
1212
var allowButtonStatus: AllowButtonStatus
1313
func body(content: Content) -> some View {
14+
let colorStore = PermissionStore.shared.allButtonColors
1415
switch self.allowButtonStatus {
1516
case .idle:
16-
return content.allowButton(foregroundColor: Color(.systemBlue), backgroundColor: Color(.systemGray5))
17+
return content.allowButton(foregroundColor: colorStore.buttonIdle.foregroundColor,
18+
backgroundColor: colorStore.buttonIdle.backgroundColor)
1719

1820
case .allowed:
19-
return content.allowButton(foregroundColor: Color(.white), backgroundColor: Color(.systemBlue))
21+
return content.allowButton(foregroundColor: colorStore.buttonAllowed.foregroundColor,
22+
backgroundColor: colorStore.buttonAllowed.backgroundColor)
2023

2124

2225
case .denied:
23-
return content.allowButton(foregroundColor: Color(.white), backgroundColor: Color(.systemRed))
26+
return content.allowButton(foregroundColor: colorStore.buttonIdle.foregroundColor,
27+
backgroundColor: colorStore.buttonDenied.backgroundColor)
2428
}
2529
}
2630
}

Tests/PermissionsSwiftUITests/PermissionsSwiftUITests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nec congue metus.
209209
if #available(iOS 14.5, *) {}
210210
else{
211211
PermissionStore.resetPermissionsModelStore()
212-
let view = ModalView(showModal: .constant(true))
213212
PermissionStore.shared.updateStore(property: {$0.permissions=$1}, value: PermissionType.allCases)
213+
PermissionStore.shared.updateStore(property: {$0.autoCheckModalAuth=$1}, value: false)
214+
let view = ModalView(showModal: .constant(true))
214215
assertSnapshot(matching: view.referenceFrame(), as: .image)
215216
}
216217
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

docs/Enums.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
<a title="Enumerations Reference"></a>
1818
<header>
1919
<div class="content-wrapper">
20-
<p><a href="index.html">PermissionsSwiftUI Docs</a> (100% documented)</p>
21-
<p class="header-right"><a href="https://github.com/jevonmao/PermissionsSwiftUI"><img src="img/gh.png"/>View on GitHub</a></p>
20+
<p><a href="index.html">PermissionsSwiftUI Docs</a> (90% documented)</p>
2221
<p class="header-right">
2322
<form role="search" action="search.json">
2423
<input type="text" placeholder="Search documentation" data-typeahead>
@@ -55,6 +54,12 @@
5554
<li class="nav-group-name">
5655
<a href="Structs.html">Structures</a>
5756
<ul class="nav-group-tasks">
57+
<li class="nav-group-task">
58+
<a href="Structs/AllButtonColors.html">AllButtonColors</a>
59+
</li>
60+
<li class="nav-group-task">
61+
<a href="Structs/ButtonColor.html">ButtonColor</a>
62+
</li>
5863
<li class="nav-group-task">
5964
<a href="Structs/JMPermission.html">JMPermission</a>
6065
</li>
@@ -110,7 +115,7 @@ <h4>Declaration</h4>
110115
</section>
111116
</section>
112117
<section id="footer">
113-
<p>&copy; 2021 <a class="link" href="" target="_blank" rel="external">Jevon Mao</a>. All rights reserved. (Last updated: 2021-02-17)</p>
118+
<p>&copy; 2021 <a class="link" href="" target="_blank" rel="external"></a>. All rights reserved. (Last updated: 2021-02-20)</p>
114119
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
115120
</section>
116121
</article>

docs/Enums/PermissionType.html

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
<a title="PermissionType Enumeration Reference"></a>
1818
<header>
1919
<div class="content-wrapper">
20-
<p><a href="../index.html">PermissionsSwiftUI Docs</a> (100% documented)</p>
21-
<p class="header-right"><a href="https://github.com/jevonmao/PermissionsSwiftUI"><img src="../img/gh.png"/>View on GitHub</a></p>
20+
<p><a href="../index.html">PermissionsSwiftUI Docs</a> (90% documented)</p>
2221
<p class="header-right">
2322
<form role="search" action="../search.json">
2423
<input type="text" placeholder="Search documentation" data-typeahead>
@@ -55,6 +54,12 @@
5554
<li class="nav-group-name">
5655
<a href="../Structs.html">Structures</a>
5756
<ul class="nav-group-tasks">
57+
<li class="nav-group-task">
58+
<a href="../Structs/AllButtonColors.html">AllButtonColors</a>
59+
</li>
60+
<li class="nav-group-task">
61+
<a href="../Structs/ButtonColor.html">ButtonColor</a>
62+
</li>
5863
<li class="nav-group-task">
5964
<a href="../Structs/JMPermission.html">JMPermission</a>
6065
</li>
@@ -384,9 +389,9 @@ <h4>Declaration</h4>
384389
<li class="item">
385390
<div>
386391
<code>
387-
<a name="/s:18PermissionsSwiftUI14PermissionTypeO6healthyACShySo08HKSampleE0CGcACmF"></a>
388-
<a name="//apple_ref/swift/Element/health(_:)" class="dashAnchor"></a>
389-
<a class="token" href="#/s:18PermissionsSwiftUI14PermissionTypeO6healthyACShySo08HKSampleE0CGcACmF">health(_:<wbr>)</a>
392+
<a name="/s:18PermissionsSwiftUI14PermissionTypeO6healthyACShySo08HKSampleE0CG_AGtcACmF"></a>
393+
<a name="//apple_ref/swift/Element/health(toShare:read:)" class="dashAnchor"></a>
394+
<a class="token" href="#/s:18PermissionsSwiftUI14PermissionTypeO6healthyACShySo08HKSampleE0CG_AGtcACmF">health(toShare:<wbr>read:<wbr>)</a>
390395
</code>
391396
</div>
392397
<div class="height-container">
@@ -402,19 +407,15 @@ <h4>Declaration</h4>
402407
</div>
403408

404409
<p>For example, passing in a <code>Set</code> of <code>HKSampleType</code>:</p>
405-
<pre class="highlight swift"><code><span class="p">[</span><span class="o">.</span><span class="nf">health</span><span class="p">(</span><span class="kt">Set</span><span class="p">([</span><span class="kt">HKObjectType</span><span class="o">.</span><span class="nf">workoutType</span><span class="p">(),</span>
406-
<span class="kt">HKObjectType</span><span class="o">.</span><span class="nf">quantityType</span><span class="p">(</span><span class="nv">forIdentifier</span><span class="p">:</span> <span class="o">.</span><span class="n">activeEnergyBurned</span><span class="p">)</span><span class="o">!</span><span class="p">,</span>
407-
<span class="kt">HKObjectType</span><span class="o">.</span><span class="nf">quantityType</span><span class="p">(</span><span class="nv">forIdentifier</span><span class="p">:</span> <span class="o">.</span><span class="n">distanceCycling</span><span class="p">)</span><span class="o">!</span><span class="p">,</span>
408-
<span class="kt">HKObjectType</span><span class="o">.</span><span class="nf">quantityType</span><span class="p">(</span><span class="nv">forIdentifier</span><span class="p">:</span> <span class="o">.</span><span class="n">distanceWalkingRunning</span><span class="p">)</span><span class="o">!</span><span class="p">,</span>
409-
<span class="kt">HKObjectType</span><span class="o">.</span><span class="nf">quantityType</span><span class="p">(</span><span class="nv">forIdentifier</span><span class="p">:</span> <span class="o">.</span><span class="n">heartRate</span><span class="p">)</span><span class="o">!</span><span class="p">]))]</span>
410+
<pre class="highlight swift"><code><span class="p">[</span><span class="o">.</span><span class="nf">health</span><span class="p">(</span><span class="nv">toShare</span><span class="p">:</span> <span class="kt">Set</span><span class="p">([</span><span class="kt">HKObjectType</span><span class="o">.</span><span class="nf">workoutType</span><span class="p">()]),</span> <span class="nv">read</span><span class="p">:</span> <span class="kt">Set</span><span class="p">([</span><span class="kt">HKObjectType</span><span class="o">.</span><span class="nf">workoutType</span><span class="p">()]))]</span>
410411
</code></pre>
411412

412413
</div>
413414
<div class="declaration">
414415
<h4>Declaration</h4>
415416
<div class="language">
416417
<p class="aside-title">Swift</p>
417-
<pre class="highlight swift"><code><span class="k">case</span> <span class="nf">health</span><span class="p">(</span><span class="kt">Set</span><span class="o">&lt;</span><span class="kt">HKSampleType</span><span class="o">&gt;</span><span class="p">)</span></code></pre>
418+
<pre class="highlight swift"><code><span class="k">case</span> <span class="nf">health</span><span class="p">(</span><span class="nv">toShare</span><span class="p">:</span> <span class="kt">Set</span><span class="o">&lt;</span><span class="kt">HKSampleType</span><span class="o">&gt;</span><span class="p">,</span> <span class="nv">read</span><span class="p">:</span> <span class="kt">Set</span><span class="o">&lt;</span><span class="kt">HKSampleType</span><span class="o">&gt;</span><span class="p">)</span></code></pre>
418419

419420
</div>
420421
</div>
@@ -506,7 +507,7 @@ <h4>Declaration</h4>
506507
</section>
507508
</section>
508509
<section id="footer">
509-
<p>&copy; 2021 <a class="link" href="" target="_blank" rel="external">Jevon Mao</a>. All rights reserved. (Last updated: 2021-02-17)</p>
510+
<p>&copy; 2021 <a class="link" href="" target="_blank" rel="external"></a>. All rights reserved. (Last updated: 2021-02-20)</p>
510511
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
511512
</section>
512513
</article>

docs/Extensions.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
<a title="Extensions Reference"></a>
1818
<header>
1919
<div class="content-wrapper">
20-
<p><a href="index.html">PermissionsSwiftUI Docs</a> (100% documented)</p>
21-
<p class="header-right"><a href="https://github.com/jevonmao/PermissionsSwiftUI"><img src="img/gh.png"/>View on GitHub</a></p>
20+
<p><a href="index.html">PermissionsSwiftUI Docs</a> (90% documented)</p>
2221
<p class="header-right">
2322
<form role="search" action="search.json">
2423
<input type="text" placeholder="Search documentation" data-typeahead>
@@ -55,6 +54,12 @@
5554
<li class="nav-group-name">
5655
<a href="Structs.html">Structures</a>
5756
<ul class="nav-group-tasks">
57+
<li class="nav-group-task">
58+
<a href="Structs/AllButtonColors.html">AllButtonColors</a>
59+
</li>
60+
<li class="nav-group-task">
61+
<a href="Structs/ButtonColor.html">ButtonColor</a>
62+
</li>
5863
<li class="nav-group-task">
5964
<a href="Structs/JMPermission.html">JMPermission</a>
6065
</li>
@@ -113,7 +118,7 @@ <h4>Declaration</h4>
113118
</section>
114119
</section>
115120
<section id="footer">
116-
<p>&copy; 2021 <a class="link" href="" target="_blank" rel="external">Jevon Mao</a>. All rights reserved. (Last updated: 2021-02-17)</p>
121+
<p>&copy; 2021 <a class="link" href="" target="_blank" rel="external"></a>. All rights reserved. (Last updated: 2021-02-20)</p>
117122
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
118123
</section>
119124
</article>

0 commit comments

Comments
 (0)