From 4bdec327535470c8d9765d190625b13e99b87db5 Mon Sep 17 00:00:00 2001 From: Amir Khorsandi Date: Mon, 4 Apr 2022 20:51:43 +0200 Subject: [PATCH 1/5] Bump minimum to 13.0 (#70) * Bump minimum iOS to 13 * remove min ios 10 --- CollectionViewPagingLayout.podspec | 6 ++-- .../project.pbxproj | 16 ++++----- .../CollectionViewPagingLayout.xcscheme | 2 +- .../CollectionViewPagingLayoutTests.xcscheme | 2 +- Lib/BlurEffectView.swift | 1 - Lib/Scale/ScaleTransformView.swift | 3 +- Lib/Stack/StackTransformView.swift | 3 +- Lib/SwiftUI/PagePadding.swift | 3 -- Lib/SwiftUI/PagingCollectionViewCell.swift | 35 +++++++------------ .../PagingCollectionViewController.swift | 6 ---- ...agingCollectionViewControllerBuilder.swift | 3 -- .../PagingCollectionViewModifierData.swift | 5 --- Lib/SwiftUI/ScalePageView.swift | 4 --- Lib/SwiftUI/SnapshotPageView.swift | 6 ---- Lib/SwiftUI/StackPageView.swift | 4 --- Lib/SwiftUI/TransformPageView.swift | 3 -- Lib/SwiftUI/TransformPageViewProtocol.swift | 5 --- Package.swift | 2 +- .../xcschemes/PagingLayoutSamples.xcscheme | 2 +- Samples/Podfile.lock | 10 +++--- 20 files changed, 34 insertions(+), 87 deletions(-) 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/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..73576cf 100644 --- a/Lib/SwiftUI/PagingCollectionViewCell.swift +++ b/Lib/SwiftUI/PagingCollectionViewCell.swift @@ -1,18 +1,7 @@ -// -// PagingCollectionViewCell.swift -// CollectionViewPagingLayout -// -// Created by Amir on 20/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 +18,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 +42,6 @@ class PagingCollectionViewCell: UICollec } } - // MARK: Private functions @discardableResult private func updateView(progress: CGFloat? = nil) -> Content? { @@ -77,7 +65,8 @@ class PagingCollectionViewCell: UICollec func constraint(_ first: NSLayoutAnchor, _ second: NSLayoutAnchor, _ paddingKeyPath: KeyPath, - _ inside: Bool) { + _ inside: Bool) + { let padding = parent.modifierData?.pagePadding?[keyPath: paddingKeyPath] ?? .absolute(0) let constant: CGFloat switch padding { @@ -90,7 +79,8 @@ class PagingCollectionViewCell: UICollec } let identifier = "pagePaddingConstraint_\(inside)_\(T.self)" if let constraint = contentView.constraints.first(where: { $0.identifier == identifier }) ?? - viewController.view.constraints.first(where: { $0.identifier == identifier }) { + viewController.view.constraints.first(where: { $0.identifier == identifier }) + { constraint.constant = constant * (inside ? 1 : -1) } else { let constraint = first.constraint(equalTo: second, constant: constant * (inside ? 1 : -1)) @@ -106,13 +96,11 @@ class PagingCollectionViewCell: UICollec } } - -@available(iOS 13.0, *) extension PagingCollectionViewCell: TransformableView, - ScaleTransformView, - StackTransformView, - SnapshotTransformView { - + ScaleTransformView, + StackTransformView, + SnapshotTransformView +{ var scalableView: UIView { hostingController?.view ?? contentView } @@ -132,9 +120,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 +173,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..69b8096 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 @@ -99,7 +96,6 @@ public extension TransformPageViewProtocol { } -@available(iOS 13.0, *) public extension TransformPageViewProtocol where Self: UIViewControllerRepresentable { func makeUIViewController(context: UIViewControllerRepresentableContext) -> Builder.ViewController { builder.make() @@ -109,4 +105,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 @@ Date: Wed, 7 Sep 2022 14:55:47 +0900 Subject: [PATCH 2/5] Please fix wrong syntax in sample code (#78) --- HOW_TO_USE_UIKIT.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/HOW_TO_USE_UIKIT.md b/HOW_TO_USE_UIKIT.md index e1c0ab6..ac0a125 100644 --- a/HOW_TO_USE_UIKIT.md +++ b/HOW_TO_USE_UIKIT.md @@ -32,12 +32,14 @@ These protocols are highly customizable, you can make tons of different effects Here is a simple example for `ScaleTransformView` which gives you a simple paging with scaling effect: ```swift extension YourCell: ScaleTransformView { - var scaleOptions = ScaleTransformViewOptions( - minScale: 0.6, - scaleRatio: 0.4, - translationRatio: CGPoint(x: 0.66, y: 0.2), - maxTranslationRatio: CGPoint(x: 2, y: 0), - ) + var scaleOptions: ScaleTransformViewOptions { + ScaleTransformViewOptions( + minScale: 0.6, + scaleRatio: 0.4, + translationRatio: CGPoint(x: 0.66, y: 0.2), + maxTranslationRatio: CGPoint(x: 2, y: 0) + ) + } } ``` There is an "options" property for each of these protocols where you can customize the effect, check the struct to find out what each parameter does. From dfc51dd6f60a8cf1a8d252ae9a71085f5f4faee4 Mon Sep 17 00:00:00 2001 From: Amir Khorsandi Date: Sun, 11 Dec 2022 15:56:46 +0100 Subject: [PATCH 3/5] Update ci.yml --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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]} From ea81e765334f40b80fd9132dd66b2fb29d5c9029 Mon Sep 17 00:00:00 2001 From: Jerry Polyansky Date: Sun, 11 Dec 2022 18:16:20 +0300 Subject: [PATCH 4/5] refactor some views (#85) Co-authored-by: Jerry --- Lib/Scale/ScaleTransformView.swift | 11 ++- .../ScaleTransformViewOptions+Layout.swift | 27 ++++++- Lib/SwiftUI/TransformPageViewProtocol.swift | 81 +++++++++++++++++-- 3 files changed, 106 insertions(+), 13 deletions(-) diff --git a/Lib/Scale/ScaleTransformView.swift b/Lib/Scale/ScaleTransformView.swift index ab42f3c..9d10c22 100644 --- a/Lib/Scale/ScaleTransformView.swift +++ b/Lib/Scale/ScaleTransformView.swift @@ -82,12 +82,17 @@ public extension ScaleTransformView { } let layer = scalableView.layer layer.shadowColor = scaleOptions.shadowColor.cgColor + + let progressMultiplier = 1 - abs(progress) + let widthProgressValue = progressMultiplier * scaleOptions.shadowOffsetMax.width + let heightProgressValue = progressMultiplier * scaleOptions.shadowOffsetMax.height + let offset = CGSize( - width: max(scaleOptions.shadowOffsetMin.width, (1 - abs(progress)) * scaleOptions.shadowOffsetMax.width), - height: max(scaleOptions.shadowOffsetMin.height, (1 - abs(progress)) * scaleOptions.shadowOffsetMax.height) + width: max(scaleOptions.shadowOffsetMin.width, widthProgressValue), + height: max(scaleOptions.shadowOffsetMin.height, heightProgressValue) ) layer.shadowOffset = offset - layer.shadowRadius = max(scaleOptions.shadowRadiusMin, (1 - abs(progress)) * scaleOptions.shadowRadiusMax) + layer.shadowRadius = max(scaleOptions.shadowRadiusMin, progressMultiplier * scaleOptions.shadowRadiusMax) layer.shadowOpacity = max(scaleOptions.shadowOpacityMin, (1 - abs(Float(progress))) * scaleOptions.shadowOpacityMax) } 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/SwiftUI/TransformPageViewProtocol.swift b/Lib/SwiftUI/TransformPageViewProtocol.swift index 69b8096..7cdf273 100644 --- a/Lib/SwiftUI/TransformPageViewProtocol.swift +++ b/Lib/SwiftUI/TransformPageViewProtocol.swift @@ -43,11 +43,43 @@ public extension TransformPageViewProtocol { bottom: PagePadding.Padding? = nil, right: PagePadding.Padding? = nil) -> Self { let current = self.builder.modifierData.pagePadding + var topPadding: PagePadding.Padding? = { + if let top = top { + return top + } else { + return current?.top + } + }() + + var leftPadding: PagePadding.Padding? = { + if let left = left { + return left + } else { + return current?.left + } + }() + + var bottomPadding: PagePadding.Padding? = { + if let bottom = bottom { + return bottom + } else { + return current?.bottom + } + }() + + var 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 } @@ -59,11 +91,44 @@ public extension TransformPageViewProtocol { func pagePadding(vertical: PagePadding.Padding? = nil, horizontal: PagePadding.Padding? = nil) -> Self { let current = self.builder.modifierData.pagePadding + + var topPadding: PagePadding.Padding? = { + if let top = vertical { + return top + } else { + return current?.top + } + }() + + var leftPadding: PagePadding.Padding? = { + if let left = horizontal { + return left + } else { + return current?.left + } + }() + + var bottomPadding: PagePadding.Padding? = { + if let bottom = vertical { + return bottom + } else { + return current?.bottom + } + }() + + var 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 } From 5b40724af52b4d80f4b5d90a41f1aab8476be4f9 Mon Sep 17 00:00:00 2001 From: Amir Date: Sun, 11 Dec 2022 16:22:02 +0100 Subject: [PATCH 5/5] Fix warnings --- Lib/CollectionViewPagingLayout.swift | 3 ++- Lib/SwiftUI/PagingCollectionViewCell.swift | 17 +++++++++++------ Lib/SwiftUI/TransformPageViewProtocol.swift | 16 ++++++++-------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Lib/CollectionViewPagingLayout.swift b/Lib/CollectionViewPagingLayout.swift index df5a102..f9f1b86 100644 --- a/Lib/CollectionViewPagingLayout.swift +++ b/Lib/CollectionViewPagingLayout.swift @@ -38,7 +38,8 @@ public class CollectionViewPagingLayout: UICollectionViewLayout { /// See `ZPositionHandler` for details public var zPositionHandler: ZPositionHandler = .both - /// Set `alpha` to zero when the cell is not loaded yet by collection view, enabling this prevents showing a cell before applying transforms but may cause flashing when you reload the data + /// Set `alpha` to zero when the cell is not loaded yet by collection view, enabling this prevents showing a cell before applying + /// transforms but may cause flashing when you reload the data public var transparentAttributeWhenCellNotLoaded: Bool = false /// The animator for setting `contentOffset` diff --git a/Lib/SwiftUI/PagingCollectionViewCell.swift b/Lib/SwiftUI/PagingCollectionViewCell.swift index 73576cf..fe156ed 100644 --- a/Lib/SwiftUI/PagingCollectionViewCell.swift +++ b/Lib/SwiftUI/PagingCollectionViewCell.swift @@ -1,3 +1,11 @@ +// +// PagingCollectionViewCell.swift +// CollectionViewPagingLayout +// +// Created by Amir on 28/03/2021. +// Copyright © 2021 Amir Khorsandi. All rights reserved. +// + import SwiftUI import UIKit @@ -65,8 +73,7 @@ class PagingCollectionViewCell: UICollec func constraint(_ first: NSLayoutAnchor, _ second: NSLayoutAnchor, _ paddingKeyPath: KeyPath, - _ inside: Bool) - { + _ inside: Bool) { let padding = parent.modifierData?.pagePadding?[keyPath: paddingKeyPath] ?? .absolute(0) let constant: CGFloat switch padding { @@ -79,8 +86,7 @@ class PagingCollectionViewCell: UICollec } let identifier = "pagePaddingConstraint_\(inside)_\(T.self)" if let constraint = contentView.constraints.first(where: { $0.identifier == identifier }) ?? - viewController.view.constraints.first(where: { $0.identifier == identifier }) - { + viewController.view.constraints.first(where: { $0.identifier == identifier }) { constraint.constant = constant * (inside ? 1 : -1) } else { let constraint = first.constraint(equalTo: second, constant: constant * (inside ? 1 : -1)) @@ -99,8 +105,7 @@ class PagingCollectionViewCell: UICollec extension PagingCollectionViewCell: TransformableView, ScaleTransformView, StackTransformView, - SnapshotTransformView -{ + SnapshotTransformView { var scalableView: UIView { hostingController?.view ?? contentView } diff --git a/Lib/SwiftUI/TransformPageViewProtocol.swift b/Lib/SwiftUI/TransformPageViewProtocol.swift index 7cdf273..a0dd393 100644 --- a/Lib/SwiftUI/TransformPageViewProtocol.swift +++ b/Lib/SwiftUI/TransformPageViewProtocol.swift @@ -43,7 +43,7 @@ public extension TransformPageViewProtocol { bottom: PagePadding.Padding? = nil, right: PagePadding.Padding? = nil) -> Self { let current = self.builder.modifierData.pagePadding - var topPadding: PagePadding.Padding? = { + let topPadding: PagePadding.Padding? = { if let top = top { return top } else { @@ -51,7 +51,7 @@ public extension TransformPageViewProtocol { } }() - var leftPadding: PagePadding.Padding? = { + let leftPadding: PagePadding.Padding? = { if let left = left { return left } else { @@ -59,7 +59,7 @@ public extension TransformPageViewProtocol { } }() - var bottomPadding: PagePadding.Padding? = { + let bottomPadding: PagePadding.Padding? = { if let bottom = bottom { return bottom } else { @@ -67,7 +67,7 @@ public extension TransformPageViewProtocol { } }() - var rightPadding: PagePadding.Padding? = { + let rightPadding: PagePadding.Padding? = { if let right = right { return right } else { @@ -92,7 +92,7 @@ public extension TransformPageViewProtocol { horizontal: PagePadding.Padding? = nil) -> Self { let current = self.builder.modifierData.pagePadding - var topPadding: PagePadding.Padding? = { + let topPadding: PagePadding.Padding? = { if let top = vertical { return top } else { @@ -100,7 +100,7 @@ public extension TransformPageViewProtocol { } }() - var leftPadding: PagePadding.Padding? = { + let leftPadding: PagePadding.Padding? = { if let left = horizontal { return left } else { @@ -108,7 +108,7 @@ public extension TransformPageViewProtocol { } }() - var bottomPadding: PagePadding.Padding? = { + let bottomPadding: PagePadding.Padding? = { if let bottom = vertical { return bottom } else { @@ -116,7 +116,7 @@ public extension TransformPageViewProtocol { } }() - var rightPadding: PagePadding.Padding? = { + let rightPadding: PagePadding.Padding? = { if let right = horizontal { return right } else {