From 472b23ba7a2240a1fbd4bc9ee674e0bb1893375a Mon Sep 17 00:00:00 2001 From: VishwaiOSDev Date: Thu, 12 Oct 2023 00:49:42 -0400 Subject: [PATCH] feat: added support for iPadOS --- Loadify.xcodeproj/project.pbxproj | 14 +++++----- Loadify/Others/LoadifyConstants.swift | 16 ++++++++++++ Loadify/Others/Modifiers/CardView.swift | 6 ++++- .../Others/Modifiers/CustomButtonStyle.swift | 2 +- Loadify/View/Components/CustomTextField.swift | 20 +++++++------- Loadify/View/DownloadView.swift | 26 ++++++++++++++++--- 6 files changed, 63 insertions(+), 21 deletions(-) diff --git a/Loadify.xcodeproj/project.pbxproj b/Loadify.xcodeproj/project.pbxproj index 988209a..d18b223 100644 --- a/Loadify.xcodeproj/project.pbxproj +++ b/Loadify.xcodeproj/project.pbxproj @@ -777,8 +777,7 @@ INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -787,9 +786,11 @@ MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = io.VishwaiOSDev.Loadify; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 1; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -810,8 +811,7 @@ INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; - INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -820,9 +820,11 @@ MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = io.VishwaiOSDev.Loadify; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 1; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; diff --git a/Loadify/Others/LoadifyConstants.swift b/Loadify/Others/LoadifyConstants.swift index a01dfe9..c1375d6 100644 --- a/Loadify/Others/LoadifyConstants.swift +++ b/Loadify/Others/LoadifyConstants.swift @@ -7,12 +7,28 @@ import SwiftUI +typealias Device = Loadify.Device typealias LoadifyTexts = Loadify.Texts typealias LoadifyColors = LoadifyKit.ColorKit typealias LoadifyAssets = LoadifyKit.AssetKit struct Loadify { + + static let maxWidth: CGFloat = switch UIDevice.current.userInterfaceIdiom { + case .phone: + .infinity + case .pad: + 500 + default: + 600 + } + + struct Device { + static let iPad = UIDevice.current.userInterfaceIdiom == .pad + static let isLandscape: Bool = UIDevice.current.orientation.isLandscape + } + struct Texts { static let loading = "LOADING" static let downloading = "DOWNLOADING" diff --git a/Loadify/Others/Modifiers/CardView.swift b/Loadify/Others/Modifiers/CardView.swift index ac40176..adfc3fd 100644 --- a/Loadify/Others/Modifiers/CardView.swift +++ b/Loadify/Others/Modifiers/CardView.swift @@ -1,6 +1,6 @@ // // CardView.swift -// +// // // Created by Vishweshwaran on 30/10/22. // @@ -19,6 +19,10 @@ struct CardView: ViewModifier { func body(content: Content) -> some View { content + .frame(maxWidth: Loadify.maxWidth) + .if(Device.iPad) { + $0.frame(maxHeight: 650) + } .background(color) .cornerRadius(cornerRadius) } diff --git a/Loadify/Others/Modifiers/CustomButtonStyle.swift b/Loadify/Others/Modifiers/CustomButtonStyle.swift index 773fd13..5010d0d 100644 --- a/Loadify/Others/Modifiers/CustomButtonStyle.swift +++ b/Loadify/Others/Modifiers/CustomButtonStyle.swift @@ -26,7 +26,7 @@ struct CustomButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label .foregroundColor(isDisabled ? .white.opacity(0.5) : .white) - .frame(maxWidth: .infinity, maxHeight: 56) + .frame(maxWidth: Loadify.maxWidth, maxHeight: 56) .background(isDisabled ? buttonColor.opacity(0.5) : buttonColor) .cornerRadius(cornerRadius) .scaleEffect(configuration.isPressed ? 0.98 : 1.0) diff --git a/Loadify/View/Components/CustomTextField.swift b/Loadify/View/Components/CustomTextField.swift index 7cf1b58..2cadee0 100644 --- a/Loadify/View/Components/CustomTextField.swift +++ b/Loadify/View/Components/CustomTextField.swift @@ -1,6 +1,6 @@ // // CustomTextField.swift -// +// // // Created by Vishweshwaran on 30/10/22. // @@ -21,16 +21,18 @@ struct CustomTextField: View { var body: some View { VStack(alignment: .leading) { ZStack(alignment: .leading) { - if text.isEmpty { - Text("\(placeHolder)") - .font(.inter(.regular(size: 16))) - .foregroundColor(LoadifyColors.greyText) + Group { + if text.isEmpty { + Text("\(placeHolder)") + .font(.inter(.regular(size: 16))) + .foregroundColor(LoadifyColors.greyText) + } + textFieldView + .disableAutocorrection(true) } - textFieldView - .disableAutocorrection(true) + .padding(.horizontal, 16) } - .frame(maxWidth: .infinity, maxHeight: 56) - .padding(.horizontal, 16) + .frame(maxWidth: Loadify.maxWidth, maxHeight: 56) .background(LoadifyColors.textfieldBackground) .cornerRadius(10) } diff --git a/Loadify/View/DownloadView.swift b/Loadify/View/DownloadView.swift index 87c4ea4..6499814 100644 --- a/Loadify/View/DownloadView.swift +++ b/Loadify/View/DownloadView.swift @@ -30,7 +30,9 @@ struct DownloadView: View { } } .cardView(color: LoadifyColors.textfieldBackground) - Spacer() + if !Device.iPad { + Spacer() + } footerView } .padding() @@ -56,6 +58,7 @@ struct DownloadView: View { } } + @ViewBuilder private var thumbnailView: some View { ZStack(alignment: .bottomTrailing) { ImageView(urlString: details.thumbnails[details.thumbnails.count - 1].url) { @@ -65,7 +68,7 @@ struct DownloadView: View { } onLoading: { progressView .frame(minHeight: 188) - } + }.frame(maxWidth: Loadify.maxWidth) durationView .offset(x: -5, y: -5) } @@ -75,7 +78,7 @@ struct DownloadView: View { image .resizable() .frame(minHeight: 188) - .scaledToFit() + .scaleImageBasedOnDevice() .clipped() } @@ -238,8 +241,23 @@ struct DownloadView: View { } } -#Preview("iPhone 15 Pro Max") { +extension View { + + @ViewBuilder + func scaleImageBasedOnDevice() -> some View { + if Device.iPad { + self.scaledToFill() + } else { + self.scaledToFit() + } + } +} + +#Preview("iPad Pro") { NavigationView { DownloadView(details: .previews) + .previewDevice("iPad Pro (12.9-inch) (6th generation)") + .previewInterfaceOrientation(.landscapeRight) } + .navigationViewStyle(StackNavigationViewStyle()) }