From 430af6139ffe7d0601606888b3d5342d91e9f230 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Sun, 31 Mar 2024 21:57:05 +0300 Subject: [PATCH] Develop (#15) Format and HealtKit error support --- AppExample/Example/Router/Alerts.swift | 2 +- .../CreateEventScreen/CreateEventView.swift | 46 +++++++++---------- .../CreateEventViewSheet.swift | 22 ++++----- .../ContactsLists/ContactsListsView.swift | 18 ++++---- .../ContactsPicker/EmailPickerView.swift | 46 +++++++++---------- .../ViewModifier/PremiumBlockOverlay.swift | 10 ++-- .../SystemKit/ErrorView/ErrorView.swift | 10 ++++ .../MapCoordinateView/MapCoordinateView.swift | 4 +- .../LocalNotificationView.swift | 4 +- 9 files changed, 85 insertions(+), 77 deletions(-) diff --git a/AppExample/Example/Router/Alerts.swift b/AppExample/Example/Router/Alerts.swift index 153c230..4b1c578 100644 --- a/AppExample/Example/Router/Alerts.swift +++ b/AppExample/Example/Router/Alerts.swift @@ -4,9 +4,9 @@ // import OversizeLocalizable +import OversizeModels import OversizeServices import SwiftUI -import OversizeModels enum RootAlert: Identifiable { case dismiss(_ action: () -> Void) diff --git a/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventView.swift b/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventView.swift index 2a9f32e..b86aa0a 100644 --- a/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventView.swift +++ b/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventView.swift @@ -56,7 +56,7 @@ public struct CreateEventView: View { Button { viewModel.present(.calendar) } label: { HStack(spacing: .xxxSmall) { Circle() - .fill(Color(viewModel.calendar?.cgColor ?? CGColor.init(red: 0.4, green: 0.4, blue: 0.4, alpha: 1))) + .fill(Color(viewModel.calendar?.cgColor ?? CGColor(red: 0.4, green: 0.4, blue: 0.4, alpha: 1))) .frame(width: 16, height: 16) .padding(.xxxSmall) @@ -150,27 +150,27 @@ public struct CreateEventView: View { .scrollContentBackground(.hidden) .background { #if os(iOS) - RoundedRectangleCorner(radius: 4, corners: [.bottomLeft, .bottomRight]) - .fillSurfaceSecondary() - .overlay(alignment: .topLeading) { - if viewModel.note.isEmpty { - Text("Note") - .body(.medium) - .onSurfaceDisabledForegroundColor() - .padding(.small) + RoundedRectangleCorner(radius: 4, corners: [.bottomLeft, .bottomRight]) + .fillSurfaceSecondary() + .overlay(alignment: .topLeading) { + if viewModel.note.isEmpty { + Text("Note") + .body(.medium) + .onSurfaceDisabledForegroundColor() + .padding(.small) + } } - } #else - RoundedRectangle(cornerRadius: .small) - .fillSurfaceSecondary() - .overlay(alignment: .topLeading) { - if viewModel.note.isEmpty { - Text("Note") - .body(.medium) - .onSurfaceDisabledForegroundColor() - .padding(.small) + RoundedRectangle(cornerRadius: .small) + .fillSurfaceSecondary() + .overlay(alignment: .topLeading) { + if viewModel.note.isEmpty { + Text("Note") + .body(.medium) + .onSurfaceDisabledForegroundColor() + .padding(.small) + } } - } #endif } .frame(minHeight: 76) @@ -183,11 +183,11 @@ public struct CreateEventView: View { .padding(.vertical, 18) .background { #if os(iOS) - RoundedRectangleCorner(radius: 4, corners: [.topLeft, .topRight]) - .fillSurfaceSecondary() + RoundedRectangleCorner(radius: 4, corners: [.topLeft, .topRight]) + .fillSurfaceSecondary() #else - RoundedRectangle(cornerRadius: .small) - .fillSurfaceSecondary() + RoundedRectangle(cornerRadius: .small) + .fillSurfaceSecondary() #endif } } diff --git a/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventViewSheet.swift b/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventViewSheet.swift index a09b54f..5136669 100644 --- a/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventViewSheet.swift +++ b/Sources/OversizeCalendarKit/CreateEventScreen/CreateEventViewSheet.swift @@ -65,23 +65,23 @@ public extension CreateEventView { switch sheet { case .startTime: #if os(iOS) - DatePickerSheet(title: "Starts time", selection: $viewModel.dateStart) - .onDisappear { - if viewModel.dateStart > viewModel.dateEnd { - viewModel.dateEnd = viewModel.dateStart.halfHour + DatePickerSheet(title: "Starts time", selection: $viewModel.dateStart) + .onDisappear { + if viewModel.dateStart > viewModel.dateEnd { + viewModel.dateEnd = viewModel.dateStart.halfHour + } } - } - .presentationDetents([.height(500)]) + .presentationDetents([.height(500)]) #else - EmptyView() + EmptyView() #endif case .endTime: #if os(iOS) - DatePickerSheet(title: "Ends time", selection: $viewModel.dateEnd) - .datePickerMinimumDate(viewModel.dateStart.minute) - .presentationDetents([.height(500)]) + DatePickerSheet(title: "Ends time", selection: $viewModel.dateEnd) + .datePickerMinimumDate(viewModel.dateStart.minute) + .presentationDetents([.height(500)]) #else - EmptyView() + EmptyView() #endif case .attachment: AttachmentView() diff --git a/Sources/OversizeContactsKit/ContactsLists/ContactsListsView.swift b/Sources/OversizeContactsKit/ContactsLists/ContactsListsView.swift index c13e5ef..c1d8c82 100644 --- a/Sources/OversizeContactsKit/ContactsLists/ContactsListsView.swift +++ b/Sources/OversizeContactsKit/ContactsLists/ContactsListsView.swift @@ -66,19 +66,19 @@ public struct ContactsListsView: View { private func emailRow(email: CNLabeledValue, contact: CNContact) -> some View { let email = email.value as String #if os(iOS) - if let avatarThumbnailData = contact.thumbnailImageData, let avatarThumbnail = UIImage(data: avatarThumbnailData) { - Row(contact.givenName + " " + contact.familyName, subtitle: email) { - Avatar(firstName: contact.givenName, lastName: contact.familyName, avatar: Image(uiImage: avatarThumbnail)) + if let avatarThumbnailData = contact.thumbnailImageData, let avatarThumbnail = UIImage(data: avatarThumbnailData) { + Row(contact.givenName + " " + contact.familyName, subtitle: email) { + Avatar(firstName: contact.givenName, lastName: contact.familyName, avatar: Image(uiImage: avatarThumbnail)) + } + } else { + Row(contact.givenName + " " + contact.familyName, subtitle: email) { + Avatar(firstName: contact.givenName, lastName: contact.familyName) + } } - } else { + #else Row(contact.givenName + " " + contact.familyName, subtitle: email) { Avatar(firstName: contact.givenName, lastName: contact.familyName) } - } - #else - Row(contact.givenName + " " + contact.familyName, subtitle: email) { - Avatar(firstName: contact.givenName, lastName: contact.familyName) - } #endif } diff --git a/Sources/OversizeContactsKit/ContactsPicker/EmailPickerView.swift b/Sources/OversizeContactsKit/ContactsPicker/EmailPickerView.swift index bb67810..3301f8b 100644 --- a/Sources/OversizeContactsKit/ContactsPicker/EmailPickerView.swift +++ b/Sources/OversizeContactsKit/ContactsPicker/EmailPickerView.swift @@ -49,9 +49,9 @@ public struct EmailPickerView: View { TextField("Email or name", text: $viewModel.searchText) .textFieldStyle(DefaultPlaceholderTextFieldStyle()) .focused($isFocusSearth) - #if os(iOS) + #if os(iOS) .keyboardType(.emailAddress) - #endif + #endif } .onAppear { isFocusSearth = true @@ -154,17 +154,28 @@ public struct EmailPickerView: View { let email = email.value as String let isSelected = selectedEmails.contains(email) #if os(iOS) - if let avatarThumbnailData = contact.thumbnailImageData, let avatarThumbnail = UIImage(data: avatarThumbnailData) { - Checkbox(isOn: Binding( - get: { isSelected }, - set: { _ in onContactClick(email: email) } - ), label: { - Row(contact.givenName + " " + contact.familyName, subtitle: email) { - Avatar(firstName: contact.givenName, lastName: contact.familyName, avatar: Image(uiImage: avatarThumbnail)) - } + if let avatarThumbnailData = contact.thumbnailImageData, let avatarThumbnail = UIImage(data: avatarThumbnailData) { + Checkbox(isOn: Binding( + get: { isSelected }, + set: { _ in onContactClick(email: email) } + ), label: { + Row(contact.givenName + " " + contact.familyName, subtitle: email) { + Avatar(firstName: contact.givenName, lastName: contact.familyName, avatar: Image(uiImage: avatarThumbnail)) + } - }) - } else { + }) + } else { + Checkbox(isOn: Binding( + get: { isSelected }, + set: { _ in onContactClick(email: email) } + ), label: { + Row(contact.givenName + " " + contact.familyName, subtitle: email) { + Avatar(firstName: contact.givenName, lastName: contact.familyName) + } + + }) + } + #else Checkbox(isOn: Binding( get: { isSelected }, set: { _ in onContactClick(email: email) } @@ -174,17 +185,6 @@ public struct EmailPickerView: View { } }) - } - #else - Checkbox(isOn: Binding( - get: { isSelected }, - set: { _ in onContactClick(email: email) } - ), label: { - Row(contact.givenName + " " + contact.familyName, subtitle: email) { - Avatar(firstName: contact.givenName, lastName: contact.familyName) - } - - }) #endif } diff --git a/Sources/OversizeKit/StoreKit/ViewModifier/PremiumBlockOverlay.swift b/Sources/OversizeKit/StoreKit/ViewModifier/PremiumBlockOverlay.swift index 63e1aeb..0594af7 100644 --- a/Sources/OversizeKit/StoreKit/ViewModifier/PremiumBlockOverlay.swift +++ b/Sources/OversizeKit/StoreKit/ViewModifier/PremiumBlockOverlay.swift @@ -17,17 +17,16 @@ public struct PremiumBlockOverlay: ViewModifier { let subtitle: String? private let closeAction: (() -> Void)? - public init(isShow: Binding = .constant(true), title: String, subtitle: String?, closeAction: (() -> Void)? = nil) { - self._isShow = isShow + _isShow = isShow self.title = title self.subtitle = subtitle self.closeAction = closeAction } public func body(content: Content) -> some View { - if !isPremium && isShow { + if !isPremium, isShow { ZStack { content @@ -89,16 +88,15 @@ public struct PremiumBlockOverlay: ViewModifier { } public extension View { - func premiumContent(_ title: String, subtitle: String?, closeAction: (() -> Void)? = nil) -> some View { modifier(PremiumBlockOverlay(title: title, subtitle: subtitle, closeAction: closeAction)) } - + @available(*, deprecated, renamed: "premiumContent", message: "Renamed") func premiumContent(title: String, subtitle: String?, closeAction: (() -> Void)? = nil) -> some View { modifier(PremiumBlockOverlay(title: title, subtitle: subtitle, closeAction: closeAction)) } - + func premiumContent(isShow: Binding = .constant(true), title: String, subtitle: String?, closeAction: (() -> Void)? = nil) -> some View { modifier(PremiumBlockOverlay(isShow: isShow, title: title, subtitle: subtitle, closeAction: closeAction)) } diff --git a/Sources/OversizeKit/SystemKit/ErrorView/ErrorView.swift b/Sources/OversizeKit/SystemKit/ErrorView/ErrorView.swift index b7d6082..fa471dc 100644 --- a/Sources/OversizeKit/SystemKit/ErrorView/ErrorView.swift +++ b/Sources/OversizeKit/SystemKit/ErrorView/ErrorView.swift @@ -88,6 +88,16 @@ public struct ErrorView: View { } else { return nil } + case let .healthKit(type: type): + if type == .notAccess { + return .accent(L10n.Button.goToSettings, action: { + #if os(iOS) + UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) + #endif + }) + } else { + return nil + } case let .contacts(type: type): if type == .notAccess { return .accent(L10n.Button.goToSettings, action: { diff --git a/Sources/OversizeLocationKit/MapCoordinateView/MapCoordinateView.swift b/Sources/OversizeLocationKit/MapCoordinateView/MapCoordinateView.swift index dec7d90..93ed613 100644 --- a/Sources/OversizeLocationKit/MapCoordinateView/MapCoordinateView.swift +++ b/Sources/OversizeLocationKit/MapCoordinateView/MapCoordinateView.swift @@ -31,9 +31,9 @@ public struct MapCoordinateView: View { }) .background(.thickMaterial, ignoresSafeAreaEdges: .top) } - #if os(iOS) + #if os(iOS) .toolbar(.hidden, for: .tabBar) - #endif + #endif } else { mapView .safeAreaInset(edge: .top) { diff --git a/Sources/OversizeNotificationKit/LocalNotificationView.swift b/Sources/OversizeNotificationKit/LocalNotificationView.swift index 740ccd9..87cbe51 100644 --- a/Sources/OversizeNotificationKit/LocalNotificationView.swift +++ b/Sources/OversizeNotificationKit/LocalNotificationView.swift @@ -77,7 +77,7 @@ public struct LocalNotificationView: View { } } } - .surfaceContentRowInsets() + .surfaceContentRowMargins() if isPendingNotification { SectionView { VStack(spacing: .zero) { @@ -92,7 +92,7 @@ public struct LocalNotificationView: View { } } } - .surfaceContentRowInsets() + .surfaceContentRowMargins() } } }