Skip to content

Commit 1d000fb

Browse files
committed
Merge branch 'develop'
2 parents 333833b + 225d7f3 commit 1d000fb

File tree

12 files changed

+282
-55
lines changed

12 files changed

+282
-55
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// AlertMainView.swift.swift
3+
//
4+
//
5+
// Created by Jevon Mao on 2/10/21.
6+
//
7+
8+
import SwiftUI
9+
10+
struct AlertMainView: View {
11+
private var showAlert: Binding<Bool>
12+
var show:Bool{
13+
get{
14+
showAlert.wrappedValue
15+
}
16+
set{
17+
showAlert.wrappedValue = newValue
18+
}
19+
}
20+
private var bodyView: AnyView
21+
init(for bodyView: AnyView, show showAlert: Binding<Bool>) {
22+
self.bodyView = bodyView
23+
self.showAlert = showAlert
24+
}
25+
var body: some View {
26+
ZStack{
27+
bodyView
28+
if show{
29+
Group{
30+
Blur(style: .systemUltraThinMaterialDark)
31+
.edgesIgnoringSafeArea(.all)
32+
.transition(AnyTransition.opacity.animation(Animation.default.speed(1.8)))
33+
AlertView(showAlert:showAlert)
34+
.transition(AnyTransition.opacity.combined(with: .scale(scale: 0.92)).animation(Animation.default.speed(1.5)))
35+
.onAppear(perform: PermissionStore.shared.onAppear)
36+
.onDisappear(perform: PermissionStore.shared.onDisappear)
37+
}
38+
39+
40+
}
41+
}
42+
43+
}
44+
}
45+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// AlertView.swift
3+
//
4+
//
5+
// Created by Jevon Mao on 2/10/21.
6+
//
7+
8+
import SwiftUI
9+
10+
struct AlertView: View {
11+
@Binding var showAlert:Bool
12+
var mainText:PermissionStore.MainTexts{PermissionStore.shared.mainTexts}
13+
var body: some View {
14+
ZStack{
15+
16+
VStack{
17+
HeaderText(exitButtonAction: {showAlert = false}, isAlert: true)
18+
PermissionSection(showModal: $showAlert, isAlert:true)
19+
20+
if PermissionStore.shared.permissions.count < 2{
21+
Divider()
22+
}
23+
Text(mainText.bottomDescription)
24+
.font(.system(.caption, design: .rounded))
25+
.fontWeight(.regular)
26+
.foregroundColor(Color(.systemGray))
27+
.padding()
28+
.lineLimit(3)
29+
.frame(maxWidth:.infinity, alignment: .leading)
30+
}
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+
37+
38+
}
39+
}

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,18 @@ import SwiftUI
1010
struct ModalView: View {
1111
@Binding var showModal: Bool
1212
var mainText:PermissionStore.MainTexts{PermissionStore.shared.mainTexts}
13+
1314
var body: some View {
1415
ScrollView {
1516
VStack {
16-
HStack {
17-
Text(mainText.headerText)
18-
.font(.system(.largeTitle, design: .rounded))
19-
.bold()
20-
Spacer()
21-
ExitButtonSection(action: { showModal.toggle() })
22-
}
23-
.padding()
24-
.padding(.top, 20)
25-
26-
Text(mainText.headerDescription)
27-
.font(.system(.body, design: .rounded))
28-
.fontWeight(.medium)
29-
.foregroundColor(Color(.systemGray))
30-
.padding()
17+
HeaderText(exitButtonAction: {showModal=false})
3118

32-
PermissionSection(showModal:$showModal)
19+
PermissionSection(showModal:$showModal, isAlert:false)
20+
.background(Color(.secondarySystemBackground))
21+
.clipShape(RoundedRectangle(cornerRadius: 15))
22+
.padding()
23+
.padding(.horizontal, 5)
24+
.frame(maxWidth:UIScreen.main.bounds.width-30)
3325

3426
Text(mainText.bottomDescription)
3527
.font(.system(.callout, design: .rounded))

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

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ import SwiftUI
1010
struct PermissionSection: View {
1111
@Environment(\.colorScheme) var colorScheme
1212
@Binding var showModal:Bool
13+
var isAlert:Bool
1314
var body: some View {
1415
VStack {
1516
let permissions = PermissionStore.shared.permissions
1617
ForEach(permissions.indices, id: \.self) {
17-
PermissionSectionCell(permission: permissions[$0], showModal: $showModal)
18+
PermissionSectionCell(permission: permissions[$0], showModal: $showModal, isAlert: isAlert)
19+
1820
if permissions.count > 1 {
1921
Divider()
2022
}
2123
}
2224
}
23-
.background(Color(.secondarySystemBackground))
24-
.clipShape(RoundedRectangle(cornerRadius: 15))
25-
.padding()
26-
.padding(.horizontal, 5)
27-
.frame(maxWidth:UIScreen.main.bounds.width-30)
2825

2926
}
3027
}
@@ -39,6 +36,7 @@ struct PermissionSectionCell: View {
3936
@State var permission: PermissionType
4037
@State var allowButtonStatus: AllowButtonStatus = .idle
4138
@Binding var showModal:Bool
39+
var isAlert:Bool
4240
var isLast:Bool{
4341
///Filter and only get unauthorized permissions
4442
let permissions = PermissionStore.shared.permissions.filter{$0.currentPermission.authorized==false}
@@ -68,30 +66,37 @@ struct PermissionSectionCell: View {
6866
.padding(.horizontal, 3)
6967

7068
Spacer()
71-
AllowButtonSection(action: {
72-
permission.requestPermission { authed in
73-
var currentPermission = permission.currentPermission
74-
if authed {
75-
allowButtonStatus = .allowed
76-
currentPermission.authorized = true
77-
}
78-
else {
79-
allowButtonStatus = .idle
80-
currentPermission.authorized = false
81-
}
82-
permission.currentPermission = currentPermission
83-
if isLast{
84-
DispatchQueue.main.asyncAfter(deadline: .now()+0.5){
85-
showModal = false
86-
}
87-
}
88-
89-
90-
}
91-
}, allowButtonStatus: $allowButtonStatus)
69+
if isAlert{
70+
AllowButtonSection(action: {
71+
permission.requestPermission(isPermissionGranted: {handleButtonState(for: $0)})
72+
}, allowButtonStatus: $allowButtonStatus)
73+
}
74+
else{
75+
AllowButtonSection(action: {
76+
permission.requestPermission(isPermissionGranted: {handleButtonState(for: $0)})
77+
}, allowButtonStatus: $allowButtonStatus)
78+
.animation(.default)
79+
}
80+
9281
}
9382
.fixedSize(horizontal: false, vertical: true)
9483
.padding(15)
95-
.frame(maxHeight:.infinity)
84+
}
85+
func handleButtonState(for authorized:Bool){
86+
var currentPermission = permission.currentPermission
87+
if authorized {
88+
allowButtonStatus = .allowed
89+
currentPermission.authorized = true
90+
}
91+
else {
92+
allowButtonStatus = .idle
93+
currentPermission.authorized = false
94+
}
95+
permission.currentPermission = currentPermission
96+
if isLast{
97+
DispatchQueue.main.asyncAfter(deadline: .now()+0.5){
98+
showModal = false
99+
}
100+
}
96101
}
97102
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Blur.swift
3+
//
4+
//
5+
// Created by Jevon Mao on 2/10/21.
6+
//
7+
8+
import SwiftUI
9+
10+
let screenSize = UIScreen.main.bounds.size
11+
struct Blur: UIViewRepresentable {
12+
var style: UIBlurEffect.Style = .systemMaterial
13+
func makeUIView(context: Context) -> UIVisualEffectView {
14+
return UIVisualEffectView(effect: UIBlurEffect(style: style))
15+
}
16+
func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
17+
uiView.effect = UIBlurEffect(style: style)
18+
}
19+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// HeaderText.swift
3+
//
4+
//
5+
// Created by Jevon Mao on 2/10/21.
6+
//
7+
8+
import SwiftUI
9+
10+
struct HeaderText: View {
11+
var exitButtonAction:() -> Void
12+
var isAlert:Bool = false
13+
var mainText:PermissionStore.MainTexts{PermissionStore.shared.mainTexts}
14+
var body: some View {
15+
VStack{
16+
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+
}
25+
HStack {
26+
Text(mainText.headerText)
27+
.font(.system(isAlert ? .title : .largeTitle, design: .rounded))
28+
.fontWeight(.bold)
29+
.lineLimit(1)
30+
.minimumScaleFactor(0.5)
31+
32+
33+
Spacer()
34+
ExitButtonSection(action: { exitButtonAction() })
35+
}
36+
}
37+
.padding()
38+
.padding(.top, isAlert ? 0 : 20)
39+
40+
if !isAlert{
41+
Text(mainText.headerDescription)
42+
.font(.system(.body, design: .rounded))
43+
.fontWeight(.medium)
44+
.foregroundColor(Color(.systemGray))
45+
.padding()
46+
.lineLimit(3)
47+
}
48+
49+
}
50+
51+
52+
}
53+
}
54+

0 commit comments

Comments
 (0)