Skip to content

Commit 3a95137

Browse files
authored
Merge pull request #30 from jevonmao/v1.2.1-hotfix
Merge branch 'develop' into branch 'main'
2 parents a1649ec + 03d8559 commit 3a95137

File tree

54 files changed

+476
-137
lines changed

Some content is hidden

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

54 files changed

+476
-137
lines changed

Sources/PermissionsSwiftUI/Components/Alert-style/AlertMainView.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ import SwiftUI
99

1010
struct AlertMainView: View {
1111
private var showAlert: Binding<Bool>
12-
var show:Bool{
13-
get{
14-
showAlert.wrappedValue
15-
}
16-
set{
17-
showAlert.wrappedValue = newValue
18-
}
19-
}
2012
private var bodyView: AnyView
2113
init(for bodyView: AnyView, show showAlert: Binding<Bool>) {
2214
self.bodyView = bodyView
@@ -25,7 +17,8 @@ struct AlertMainView: View {
2517
var body: some View {
2618
ZStack{
2719
bodyView
28-
if show{
20+
21+
if showAlert.wrappedValue {
2922
Group{
3023
Blur(style: .systemUltraThinMaterialDark)
3124
.edgesIgnoringSafeArea(.all)
@@ -35,10 +28,12 @@ struct AlertMainView: View {
3528
.onAppear(perform: PermissionStore.shared.onAppear)
3629
.onDisappear(perform: PermissionStore.shared.onDisappear)
3730
}
38-
39-
31+
4032
}
4133
}
34+
.edgesIgnoringSafeArea(.all)
35+
.animation(.default)
36+
4237

4338
}
4439
}

Sources/PermissionsSwiftUI/Components/Alert-style/AlertView.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import SwiftUI
99

1010
struct AlertView: View {
11-
@Binding var showAlert:Bool
12-
var mainText:PermissionStore.MainTexts{PermissionStore.shared.mainTexts}
13-
var body: some View {
14-
ZStack{
11+
@Binding var showAlert: Bool
12+
var mainText: PermissionStore.MainTexts{PermissionStore.shared.mainTexts}
1513

14+
var paddingSize: CGFloat {
15+
screenSize.width < 400 ? 20-(1000-screenSize.width)/120 : 20
16+
}
17+
var body: some View {
1618
VStack{
1719
HeaderText(exitButtonAction: {showAlert = false}, isAlert: true)
20+
.padding(.bottom, paddingSize/1.5)
1821
PermissionSection(showModal: $showAlert, isAlert:true)
1922

2023
if PermissionStore.shared.permissions.count < 2{
@@ -24,15 +27,16 @@ struct AlertView: View {
2427
.font(.system(.caption, design: .rounded))
2528
.fontWeight(.regular)
2629
.foregroundColor(Color(.systemGray))
27-
.padding()
30+
2831
.lineLimit(3)
2932
.frame(maxWidth:.infinity, alignment: .leading)
33+
.fixedSize(horizontal: false, vertical: true)
34+
.minimumScaleFactor(0.5)
3035
}
31-
.padding(5)
32-
.background(Color(.systemBackground).opacity(0.8))
33-
.frame(width: screenSize.width > 375 ? 375 : screenSize.width-60)
34-
.clipShape(RoundedRectangle(cornerRadius: 20, style: .continuous))
35-
}
36+
.padding(paddingSize)
37+
.alertViewFrame()
38+
39+
3640

3741

3842
}

Sources/PermissionsSwiftUI/Components/Modal-style/AllowButtonSection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ struct AllowButtonSection: View {
1616
.fontWeight(.bold)
1717
.buttonStatusColor(for: allowButtonStatus)
1818
})
19+
.layoutPriority(-1)
1920
}
2021
}

Sources/PermissionsSwiftUI/Components/Modal-style/ModalView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ struct ModalView: View {
1717
HeaderText(exitButtonAction: {showModal=false})
1818

1919
PermissionSection(showModal:$showModal, isAlert:false)
20-
.background(Color(.secondarySystemBackground))
20+
.background(Color(.systemBackground))
2121
.clipShape(RoundedRectangle(cornerRadius: 15))
2222
.padding()
23-
.padding(.horizontal, 5)
2423
.frame(maxWidth:UIScreen.main.bounds.width-30)
2524

2625
Text(mainText.bottomDescription)
@@ -32,7 +31,7 @@ struct ModalView: View {
3231
.padding(.bottom,30)
3332

3433
}
35-
.background(Color(.systemBackground))
34+
.background(Color(.secondarySystemBackground))
3635
.edgesIgnoringSafeArea(.all)
3736
}
3837
}

Sources/PermissionsSwiftUI/Components/Modal-style/PermissionSection.swift

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,68 @@ enum AllowButtonStatus:CaseIterable {
3535
struct PermissionSectionCell: View {
3636
@State var permission: PermissionType
3737
@State var allowButtonStatus: AllowButtonStatus = .idle
38-
@Binding var showModal:Bool
39-
var isAlert:Bool
40-
var isLast:Bool{
38+
@Binding var showModal: Bool
39+
var isAlert: Bool
40+
var isLast: Bool {
4141
///Filter and only get unauthorized permissions
4242
let permissions = PermissionStore.shared.permissions.filter{$0.currentPermission.authorized==false}
43-
if permissions.count == 0{
43+
if permissions.count == 0 {
4444
return true
4545
}
4646
else{
4747
return false
4848
}
4949
}
50+
var screenSizeConstant: CGFloat {
51+
screenSize.width < 400 ? 40-(1000-screenSize.width)/80 : 40
52+
}
53+
var fontSizeConstant: CGFloat {
54+
screenSize.width < 400 ? 20-(1000-screenSize.width)/150 : 20
55+
}
56+
var smallFontSizeConstant: CGFloat {
57+
fontSizeConstant - fontSizeConstant/2.8
58+
}
59+
var vertPaddingConstant: CGFloat {
60+
if isAlert {
61+
return screenSize.width < 400 ? 0 : 10
62+
}
63+
else{
64+
return 15
65+
}
66+
}
67+
var horiPaddingConstant: CGFloat {
68+
if isAlert {
69+
return 0
70+
}
71+
else{
72+
return 15
73+
}
74+
}
5075
var body: some View {
5176
let currentPermission = self.permission.currentPermission
5277
HStack {
5378
currentPermission.imageIcon
5479
.foregroundColor(Color.blue)
55-
.font(.system(size: 40))
56-
.frame(width: 50)
80+
.font(.system(size: screenSizeConstant))
81+
.frame(width: screenSizeConstant)
82+
.padding(.horizontal, 5)
5783
VStack(alignment: .leading) {
5884
Text(currentPermission.title)
59-
.font(.system(size: 20))
85+
.font(.system(size: fontSizeConstant))
6086
.bold()
87+
.lineLimit(1)
88+
.layoutPriority(1)
6189
Text(currentPermission.description)
62-
.font(.footnote)
90+
.font(.system(size: smallFontSizeConstant))
6391
.lineLimit(3)
6492
.foregroundColor(Color(.systemGray2))
93+
.minimumScaleFactor(0.5)
94+
6595
}
6696
.padding(.horizontal, 3)
6797

6898
Spacer()
69-
if isAlert{
99+
if isAlert {
70100
AllowButtonSection(action: {
71101
permission.requestPermission(isPermissionGranted: {handleButtonState(for: $0)})
72102
}, allowButtonStatus: $allowButtonStatus)
@@ -80,7 +110,8 @@ struct PermissionSectionCell: View {
80110

81111
}
82112
.fixedSize(horizontal: false, vertical: true)
83-
.padding(15)
113+
.padding(.vertical, vertPaddingConstant)
114+
.padding(.horizontal, horiPaddingConstant)
84115
}
85116
func handleButtonState(for authorized:Bool){
86117
var currentPermission = permission.currentPermission
@@ -93,10 +124,20 @@ struct PermissionSectionCell: View {
93124
currentPermission.authorized = false
94125
}
95126
permission.currentPermission = currentPermission
96-
if isLast{
97-
DispatchQueue.main.asyncAfter(deadline: .now()+0.5){
98-
showModal = false
127+
if isAlert{
128+
if isLast && PermissionStore.shared.autoDismissAlert {
129+
DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
130+
showModal = false
131+
}
132+
}
133+
}
134+
else{
135+
if isLast && PermissionStore.shared.autoDismissModal {
136+
DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
137+
showModal = false
138+
}
99139
}
100140
}
141+
101142
}
102143
}

Sources/PermissionsSwiftUI/Components/Shared/Blur.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import SwiftUI
99

10-
let screenSize = UIScreen.main.bounds.size
10+
let screenSize = UIScreen.main.bounds
11+
1112
struct Blur: UIViewRepresentable {
1213
var style: UIBlurEffect.Style = .systemMaterial
1314
func makeUIView(context: Context) -> UIVisualEffectView {

Sources/PermissionsSwiftUI/Components/Shared/ExitButtonSection.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,35 @@ import SwiftUI
99

1010
struct ExitButtonSection: View {
1111
var action: () -> Void
12+
var buttonSizeConstant: CGFloat {
13+
screenSize.width < 400 ? 40-(1000-screenSize.width)/80 : 40
14+
}
1215
var body: some View {
1316
Button(action: action, label: {
1417
Circle()
1518
.fill(Color(.systemGray4))
16-
.frame(width: 40, height: 40)
19+
.frame(width: buttonSizeConstant, height: buttonSizeConstant)
1720
.overlay(
1821
Image(systemName: "xmark")
1922
.font(.system(size: 18, weight: .bold, design: .rounded))
23+
.minimumScaleFactor(0.2)
2024
.foregroundColor(Color(.systemGray))
25+
.padding(4)
2126
)
2227
})
2328
}
2429
}
30+
31+
//
32+
//Circle()
33+
// .fill(Color(.systemGray4))
34+
// .frame(maxWidth:40, maxHeight: 40)
35+
// .overlay( Image(systemName: "xmark")
36+
// .font(.system(size: 18, weight: .bold, design: .rounded))
37+
// .foregroundColor(Color(.systemGray))
38+
// .minimumScaleFactor(0.1)
39+
// .padding(6)
40+
//
41+
//
42+
//
43+
// )

Sources/PermissionsSwiftUI/Components/Shared/HeaderText.swift

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,31 @@ struct HeaderText: View {
1414
var body: some View {
1515
VStack{
1616
VStack{
17-
if isAlert{
18-
Text("PERMISSIONS REQUEST")
19-
.font(.footnote)
20-
.fontWeight(.semibold)
21-
.foregroundColor(Color(.systemGray2))
22-
.frame(maxWidth:.infinity, alignment: .leading)
23-
.padding(.vertical, -3)
24-
}
17+
if isAlert{
18+
Text("PERMISSIONS REQUEST")
19+
.font(.footnote)
20+
.fontWeight(.semibold)
21+
.foregroundColor(Color(.systemGray2))
22+
.frame(maxWidth:.infinity, alignment: .leading)
23+
.padding(.vertical, -5)
24+
}
25+
2526
HStack {
2627
Text(mainText.headerText)
2728
.font(.system(isAlert ? .title : .largeTitle, design: .rounded))
2829
.fontWeight(.bold)
2930
.lineLimit(1)
30-
.minimumScaleFactor(0.5)
31-
32-
31+
.minimumScaleFactor(0.85)
32+
.allowsTightening(true)
33+
.layoutPriority(1)
34+
3335
Spacer()
3436
ExitButtonSection(action: { exitButtonAction() })
37+
.layoutPriority(-1)
3538
}
3639
}
37-
.padding()
38-
.padding(.top, isAlert ? 0 : 20)
40+
.padding(.top, isAlert ? 0 : 30)
41+
.padding(.horizontal, isAlert ? 0 : 16)
3942

4043
if !isAlert{
4144
Text(mainText.headerDescription)
@@ -44,11 +47,13 @@ struct HeaderText: View {
4447
.foregroundColor(Color(.systemGray))
4548
.padding()
4649
.lineLimit(3)
50+
.fixedSize(horizontal: false, vertical: true)
51+
.minimumScaleFactor(0.5)
4752
}
4853

4954
}
55+
5056

5157

5258
}
5359
}
54-

Sources/PermissionsSwiftUI/Model/PermissionStore.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// PermissionModelSet.swift
3-
//
3+
//
44
//
55
// Created by Jevon Mao on 2/6/21.
66
//
@@ -19,14 +19,16 @@ struct PermissionStore {
1919
}
2020
var permissions: [PermissionType] = []
2121
var mainTexts = MainTexts()
22-
var onAppear:(()->Void)?
23-
var onDisappear:(()->Void)?
22+
var autoDismissModal: Bool = true
23+
var autoDismissAlert: Bool = true
24+
var onAppear: (()->Void)?
25+
var onDisappear: (()->Void)?
2426
struct MainTexts{
25-
var headerText:String = "Need Permissions"
26-
var headerDescription:String = """
27+
var headerText: String = "Need Permissions"
28+
var headerDescription: String = """
2729
In order for you use certain features of this app, you need to give permissions. See description for each permission
2830
"""
29-
var bottomDescription:String = """
31+
var bottomDescription: String = """
3032
Permission are necessary for all the features and functions to work properly. If not allowed, you have to enable permissions in settings
3133
"""
3234
}

Sources/PermissionsSwiftUI/Model/PermissionTypeGetSet.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ extension PermissionType:PermissionTypeProtocol{
127127
case .tracking:
128128
if #available(iOS 14.5, *) {
129129
JMTrackingPermissionManager.shared.requestPermission{authorized in
130-
print(authorized)
131130
isPermissionGranted(authorized)
132131
}
133132
}

Sources/PermissionsSwiftUI/Model/Permissions/JMHealthPermissionManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class JMHealthPermissionManager{
1919
completion(false)
2020
return
2121
}
22-
2322
healthStore.requestAuthorization(toShare: toShare, read: read) { authorized, error in
23+
2424
guard error == nil else{
2525
print("PermissionSwiftUI - \(String(describing: error))")
2626
completion(false)

0 commit comments

Comments
 (0)