diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d188538..05f1487 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,8 +24,8 @@ jobs: - name: List available Xcode versions run: ls /Applications | grep Xcode - name: Select Xcode - run: sudo xcode-select -switch /Applications/Xcode_12.4.app && /usr/bin/xcodebuild -version + run: sudo xcode-select -switch /Applications/Xcode_14.1.app && /usr/bin/xcodebuild -version - name: Run unit tests - run: xcodebuild test -scheme CollectionViewPagingLayout -project CollectionViewPagingLayout.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 12,OS=14.4' | xcpretty && exit ${PIPESTATUS[0]} + run: xcodebuild test -scheme CollectionViewPagingLayout -project CollectionViewPagingLayout.xcodeproj -destination 'platform=iOS Simulator,name=iPhone 14,OS=16.1' | xcpretty && exit ${PIPESTATUS[0]} diff --git a/CollectionViewPagingLayout.podspec b/CollectionViewPagingLayout.podspec index 9de0e31..f081bb6 100644 --- a/CollectionViewPagingLayout.podspec +++ b/CollectionViewPagingLayout.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CollectionViewPagingLayout" - s.version = "1.0.3" + s.version = "1.1.0" s.summary = "A simple but highly customizable layout for UICollectionView and SwiftUI." s.description = <<-DESC @@ -14,9 +14,9 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/amirdew/CollectionViewPagingLayout.git", :tag => "#{s.version}" } s.source_files = ["Lib/**/*.swift"] - s.swift_versions = ["5.4"] + s.swift_versions = ["5.5"] - s.ios.deployment_target = "10.0" + s.ios.deployment_target = "13.0" s.frameworks = "UIKit" s.weak_frameworks = "SwiftUI", "Combine" diff --git a/CollectionViewPagingLayout.xcodeproj/project.pbxproj b/CollectionViewPagingLayout.xcodeproj/project.pbxproj index d96af79..10010f4 100644 --- a/CollectionViewPagingLayout.xcodeproj/project.pbxproj +++ b/CollectionViewPagingLayout.xcodeproj/project.pbxproj @@ -121,6 +121,7 @@ 291EC0DA2610B32500C65A34 /* SwiftUI */ = { isa = PBXGroup; children = ( + 291EC0E22610B32500C65A34 /* SnapshotPageView.swift */, 2967EBA126230A320035540A /* PagePadding.swift */, 291EC0DB2610B32500C65A34 /* PagingCollectionViewControllerBuilder.swift */, 291EC0DC2610B32500C65A34 /* StackPageView.swift */, @@ -130,7 +131,6 @@ 291EC0DF2610B32500C65A34 /* PagingCollectionViewCell.swift */, 291EC0E02610B32500C65A34 /* TransformPageView.swift */, 291EC0E12610B32500C65A34 /* PagingCollectionViewController.swift */, - 291EC0E22610B32500C65A34 /* SnapshotPageView.swift */, ); path = SwiftUI; sourceTree = ""; @@ -294,7 +294,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1240; - LastUpgradeCheck = 1220; + LastUpgradeCheck = 1330; ORGANIZATIONNAME = Amir; TargetAttributes = { 291FDEC2262327FD00AD1C14 = { @@ -513,7 +513,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -571,7 +571,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -594,13 +594,13 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = CollectionViewPagingLayout/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.1.0; PRODUCT_BUNDLE_IDENTIFIER = amir.app.CollectionViewPagingLayout; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -621,13 +621,13 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = CollectionViewPagingLayout/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.1.0; PRODUCT_BUNDLE_IDENTIFIER = amir.app.CollectionViewPagingLayout; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; diff --git a/CollectionViewPagingLayout.xcodeproj/xcshareddata/xcschemes/CollectionViewPagingLayout.xcscheme b/CollectionViewPagingLayout.xcodeproj/xcshareddata/xcschemes/CollectionViewPagingLayout.xcscheme index 2ad420d..250ff93 100644 --- a/CollectionViewPagingLayout.xcodeproj/xcshareddata/xcschemes/CollectionViewPagingLayout.xcscheme +++ b/CollectionViewPagingLayout.xcodeproj/xcshareddata/xcschemes/CollectionViewPagingLayout.xcscheme @@ -1,6 +1,6 @@ 0, scaleOptions.blurEffectEnabled else { scaleBlurViewHost.subviews.first(where: { $0 is BlurEffectView })?.removeFromSuperview() diff --git a/Lib/Scale/ScaleTransformViewOptions+Layout.swift b/Lib/Scale/ScaleTransformViewOptions+Layout.swift index e508185..6625331 100644 --- a/Lib/Scale/ScaleTransformViewOptions+Layout.swift +++ b/Lib/Scale/ScaleTransformViewOptions+Layout.swift @@ -102,6 +102,29 @@ public extension ScaleTransformViewOptions { maxTranslateRatios: (0.05, 0, -0.86)) ) case .coverFlow: + let defaultAngle: Double = .pi / 1.65 + let minAngle: Double = -.pi / 3 + let maxAngle: Double = .pi / 3 + let rotation3d = Rotation3dOptions( + angle: defaultAngle, + minAngle: minAngle, + maxAngle: maxAngle, + x: 0, + y: -1, + z: 0, + m34: -0.000_5 + ) + + + let translateRatios: (CGFloat, CGFloat, CGFloat) = (0.1, 0, -0.7) + let minTranslateRatios: (CGFloat, CGFloat, CGFloat) = (-0.1, 0, -3) + let maxTranslateRatios: (CGFloat, CGFloat, CGFloat) = (0.1, 0, 0) + let translation3d = Translation3dOptions( + translateRatios: translateRatios, + minTranslateRatios: minTranslateRatios, + maxTranslateRatios: maxTranslateRatios + ) + return Self( minScale: 0.7, maxScale: 0.7, @@ -110,8 +133,8 @@ public extension ScaleTransformViewOptions { minTranslationRatio: .zero, maxTranslationRatio: .zero, shadowEnabled: true, - rotation3d: .init(angle: .pi / 1.65, minAngle: -.pi / 3, maxAngle: .pi / 3, x: 0, y: -1, z: 0, m34: -0.000_5), - translation3d: .init(translateRatios: (0.1, 0, -0.7), minTranslateRatios: (-0.1, 0, -3), maxTranslateRatios: (0.1, 0, 0)) + rotation3d: rotation3d, + translation3d: translation3d ) } } diff --git a/Lib/Stack/StackTransformView.swift b/Lib/Stack/StackTransformView.swift index 3b45745..aa8e4e8 100644 --- a/Lib/Stack/StackTransformView.swift +++ b/Lib/Stack/StackTransformView.swift @@ -187,8 +187,7 @@ public extension StackTransformView { cardView.transform = cardView.transform.rotated(by: angle) } - - @available(iOS 10.0, *) + private func applyBlurEffect(progress: CGFloat) { guard stackOptions.maxBlurEffectRadius > 0, stackOptions.blurEffectEnabled else { stackBlurViewHost.subviews.first(where: { $0 is BlurEffectView })?.removeFromSuperview() diff --git a/Lib/SwiftUI/PagePadding.swift b/Lib/SwiftUI/PagePadding.swift index 6c26ba2..0e2b6b5 100644 --- a/Lib/SwiftUI/PagePadding.swift +++ b/Lib/SwiftUI/PagePadding.swift @@ -6,11 +6,9 @@ // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) import Foundation import UIKit -@available(iOS 13.0, *) /// Provides paddings around the page public struct PagePadding { @@ -30,4 +28,3 @@ public struct PagePadding { case fractionalWidth(CGFloat) } } -#endif diff --git a/Lib/SwiftUI/PagingCollectionViewCell.swift b/Lib/SwiftUI/PagingCollectionViewCell.swift index 4978ead..fe156ed 100644 --- a/Lib/SwiftUI/PagingCollectionViewCell.swift +++ b/Lib/SwiftUI/PagingCollectionViewCell.swift @@ -2,17 +2,14 @@ // PagingCollectionViewCell.swift // CollectionViewPagingLayout // -// Created by Amir on 20/03/2021. +// Created by Amir on 28/03/2021. // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) -import UIKit import SwiftUI +import UIKit -@available(iOS 13.0, *) class PagingCollectionViewCell: UICollectionViewCell { - typealias Parent = PagingCollectionViewController // MARK: Properties @@ -29,7 +26,7 @@ class PagingCollectionViewCell: UICollec func update(value: ValueType, index: IndexPath, parent: Parent) { self.parent = parent - self.viewBuilder = parent.pageViewBuilder + viewBuilder = parent.pageViewBuilder self.value = value self.index = index if hostingController != nil { @@ -53,7 +50,6 @@ class PagingCollectionViewCell: UICollec } } - // MARK: Private functions @discardableResult private func updateView(progress: CGFloat? = nil) -> Content? { @@ -106,13 +102,10 @@ class PagingCollectionViewCell: UICollec } } - -@available(iOS 13.0, *) extension PagingCollectionViewCell: TransformableView, - ScaleTransformView, - StackTransformView, - SnapshotTransformView { - + ScaleTransformView, + StackTransformView, + SnapshotTransformView { var scalableView: UIView { hostingController?.view ?? contentView } @@ -132,9 +125,11 @@ extension PagingCollectionViewCell: TransformableView, var scaleOptions: ScaleTransformViewOptions { parent?.modifierData?.scaleOptions ?? .init() } + var stackOptions: StackTransformViewOptions { parent?.modifierData?.stackOptions ?? .init() } + var snapshotOptions: SnapshotTransformViewOptions { parent?.modifierData?.snapshotOptions ?? .init() } @@ -183,4 +178,3 @@ extension PagingCollectionViewCell: TransformableView, return snapshot.snapshotSize == targetView.bounds.size } } -#endif diff --git a/Lib/SwiftUI/PagingCollectionViewController.swift b/Lib/SwiftUI/PagingCollectionViewController.swift index 0420aff..3969f1e 100644 --- a/Lib/SwiftUI/PagingCollectionViewController.swift +++ b/Lib/SwiftUI/PagingCollectionViewController.swift @@ -6,11 +6,9 @@ // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) import UIKit import SwiftUI -@available(iOS 13.0, *) public class PagingCollectionViewController: UIViewController, UICollectionViewDataSource, CollectionViewPagingLayoutDelegate, @@ -153,14 +151,12 @@ private protocol PagingCollectionViewControllerEquatableList { func isListSame(as list: [T]) -> Bool } -@available(iOS 13.0, *) extension PagingCollectionViewController: PagingCollectionViewControllerEquatableList where ValueType: Equatable { func isListSame(as list: [T]) -> Bool { self.list == (list as? [ValueType]) } } -@available(iOS 13.0, *) private extension UICollectionView { func registerClass(_ cellType: T.Type, reuseIdentifier: String = T.reuseIdentifier) { register(cellType, forCellWithReuseIdentifier: reuseIdentifier) @@ -172,10 +168,8 @@ private extension UICollectionView { } -@available(iOS 13.0, *) private extension UICollectionViewCell { static var reuseIdentifier: String { String(describing: self) } } -#endif diff --git a/Lib/SwiftUI/PagingCollectionViewControllerBuilder.swift b/Lib/SwiftUI/PagingCollectionViewControllerBuilder.swift index 7853d52..ed15a56 100644 --- a/Lib/SwiftUI/PagingCollectionViewControllerBuilder.swift +++ b/Lib/SwiftUI/PagingCollectionViewControllerBuilder.swift @@ -6,10 +6,8 @@ // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) import SwiftUI -@available(iOS 13.0, *) public class PagingCollectionViewControllerBuilder { public typealias ViewController = PagingCollectionViewController @@ -78,4 +76,3 @@ public class PagingCollectionViewControllerBuilder() -> WritableKeyPath? func getValue() -> T? } -@available(iOS 13.0, *) struct CollectionViewProperty: CollectionViewPropertyProtocol { let keyPath: WritableKeyPath let value: T @@ -47,4 +43,3 @@ struct CollectionViewProperty: CollectionViewPropertyProtocol { value as? T } } -#endif diff --git a/Lib/SwiftUI/ScalePageView.swift b/Lib/SwiftUI/ScalePageView.swift index 47fbbfe..937324b 100644 --- a/Lib/SwiftUI/ScalePageView.swift +++ b/Lib/SwiftUI/ScalePageView.swift @@ -6,11 +6,9 @@ // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) import Foundation import SwiftUI -@available(iOS 13.0, *) public struct ScalePageView: UIViewControllerRepresentable, TransformPageViewProtocol { // MARK: Properties @@ -31,11 +29,9 @@ public struct ScalePageView: UIViewC } -@available(iOS 13.0, *) public extension ScalePageView { func options(_ options: ScaleTransformViewOptions) -> Self { builder.modifierData.scaleOptions = options return self } } -#endif diff --git a/Lib/SwiftUI/SnapshotPageView.swift b/Lib/SwiftUI/SnapshotPageView.swift index dda220e..f2c1e87 100644 --- a/Lib/SwiftUI/SnapshotPageView.swift +++ b/Lib/SwiftUI/SnapshotPageView.swift @@ -6,11 +6,9 @@ // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) import Foundation import SwiftUI -@available(iOS 13.0, *) public struct SnapshotPageView: UIViewControllerRepresentable, TransformPageViewProtocol { // MARK: Properties @@ -31,7 +29,6 @@ public struct SnapshotPageView: UIVi } -@available(iOS 13.0, *) public extension SnapshotPageView { func options(_ options: SnapshotTransformViewOptions) -> Self { builder.modifierData.snapshotOptions = options @@ -39,7 +36,6 @@ public extension SnapshotPageView { } } -@available(iOS 13.0, *) public extension SnapshotPageView { /// A unique identifier for the snapshot, a new snapshot won't be made if /// there is a cashed snapshot with the same identifier @@ -52,7 +48,6 @@ public extension SnapshotPageView { } } -@available(iOS 13.0, *) public extension SnapshotPageView { /// Check if the snapshot can be reused /// - Parameter snapshotContainer: The container for snapshot pieces, see `SnapshotContainerView` @@ -63,4 +58,3 @@ public extension SnapshotPageView { return self } } -#endif diff --git a/Lib/SwiftUI/StackPageView.swift b/Lib/SwiftUI/StackPageView.swift index 75c33cf..6562acc 100644 --- a/Lib/SwiftUI/StackPageView.swift +++ b/Lib/SwiftUI/StackPageView.swift @@ -6,11 +6,9 @@ // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) import Foundation import SwiftUI -@available(iOS 13.0, *) public struct StackPageView: UIViewControllerRepresentable, TransformPageViewProtocol { // MARK: Properties @@ -31,11 +29,9 @@ public struct StackPageView: UIViewC } -@available(iOS 13.0, *) public extension StackPageView { func options(_ options: StackTransformViewOptions) -> Self { builder.modifierData.stackOptions = options return self } } -#endif diff --git a/Lib/SwiftUI/TransformPageView.swift b/Lib/SwiftUI/TransformPageView.swift index bb1c501..564e728 100644 --- a/Lib/SwiftUI/TransformPageView.swift +++ b/Lib/SwiftUI/TransformPageView.swift @@ -5,11 +5,9 @@ // Created by Amir on 28/03/2021. // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) import Foundation import SwiftUI -@available(iOS 13.0, *) public struct TransformPageView: UIViewControllerRepresentable, TransformPageViewProtocol { // MARK: Properties @@ -27,4 +25,3 @@ public struct TransformPageView: UIV builder = .init(data: data, pageViewBuilder: viewBuilder, selection: selection) } } -#endif diff --git a/Lib/SwiftUI/TransformPageViewProtocol.swift b/Lib/SwiftUI/TransformPageViewProtocol.swift index 48b20fa..a0dd393 100644 --- a/Lib/SwiftUI/TransformPageViewProtocol.swift +++ b/Lib/SwiftUI/TransformPageViewProtocol.swift @@ -6,11 +6,9 @@ // Copyright © 2021 Amir Khorsandi. All rights reserved. // -#if canImport(SwiftUI) && canImport(Combine) import Foundation import SwiftUI -@available(iOS 13.0, *) public protocol TransformPageViewProtocol { associatedtype ValueType: Identifiable associatedtype PageContent: View @@ -21,7 +19,6 @@ public protocol TransformPageViewProtocol { } -@available(iOS 13.0, *) public extension TransformPageViewProtocol { func numberOfVisibleItems(_ count: Int) -> Self { self.builder.modifierData.numberOfVisibleItems = count @@ -46,11 +43,43 @@ public extension TransformPageViewProtocol { bottom: PagePadding.Padding? = nil, right: PagePadding.Padding? = nil) -> Self { let current = self.builder.modifierData.pagePadding + let topPadding: PagePadding.Padding? = { + if let top = top { + return top + } else { + return current?.top + } + }() + + let leftPadding: PagePadding.Padding? = { + if let left = left { + return left + } else { + return current?.left + } + }() + + let bottomPadding: PagePadding.Padding? = { + if let bottom = bottom { + return bottom + } else { + return current?.bottom + } + }() + + let rightPadding: PagePadding.Padding? = { + if let right = right { + return right + } else { + return current?.right + } + }() + self.builder.modifierData.pagePadding = .init( - top: top ?? current?.top, - left: left ?? current?.left, - bottom: bottom ?? current?.bottom, - right: right ?? current?.right + top: topPadding, + left: leftPadding, + bottom: bottomPadding, + right: rightPadding ) return self } @@ -62,11 +91,44 @@ public extension TransformPageViewProtocol { func pagePadding(vertical: PagePadding.Padding? = nil, horizontal: PagePadding.Padding? = nil) -> Self { let current = self.builder.modifierData.pagePadding + + let topPadding: PagePadding.Padding? = { + if let top = vertical { + return top + } else { + return current?.top + } + }() + + let leftPadding: PagePadding.Padding? = { + if let left = horizontal { + return left + } else { + return current?.left + } + }() + + let bottomPadding: PagePadding.Padding? = { + if let bottom = vertical { + return bottom + } else { + return current?.bottom + } + }() + + let rightPadding: PagePadding.Padding? = { + if let right = horizontal { + return right + } else { + return current?.right + } + }() + self.builder.modifierData.pagePadding = .init( - top: vertical ?? current?.top, - left: horizontal ?? current?.left, - bottom: vertical ?? current?.bottom, - right: horizontal ?? current?.right + top: topPadding, + left: leftPadding, + bottom: bottomPadding, + right: rightPadding ) return self } @@ -99,7 +161,6 @@ public extension TransformPageViewProtocol { } -@available(iOS 13.0, *) public extension TransformPageViewProtocol where Self: UIViewControllerRepresentable { func makeUIViewController(context: UIViewControllerRepresentableContext) -> Builder.ViewController { builder.make() @@ -109,4 +170,3 @@ public extension TransformPageViewProtocol where Self: UIViewControllerRepresent builder.update(viewController: uiViewController) } } -#endif diff --git a/Package.swift b/Package.swift index 432937f..ec040a6 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "CollectionViewPagingLayout", platforms: [ - .iOS(.v10) + .iOS(.v13) ], products: [ .library( diff --git a/Samples/PagingLayoutSamples.xcodeproj/xcshareddata/xcschemes/PagingLayoutSamples.xcscheme b/Samples/PagingLayoutSamples.xcodeproj/xcshareddata/xcschemes/PagingLayoutSamples.xcscheme index 2d6c665..c405f46 100644 --- a/Samples/PagingLayoutSamples.xcodeproj/xcshareddata/xcschemes/PagingLayoutSamples.xcscheme +++ b/Samples/PagingLayoutSamples.xcodeproj/xcshareddata/xcschemes/PagingLayoutSamples.xcscheme @@ -1,6 +1,6 @@