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/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/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/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 69b8096..a0dd393 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 + 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 } @@ -59,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 }