From 81f2129f6e637bc916734ce53f6a46af2dbbdd77 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Wed, 7 Oct 2020 17:18:10 +0100 Subject: [PATCH 1/3] Fix create framework step --- .github/workflows/create-release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 1b2a9d0..4244f17 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -17,9 +17,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Select Xcode 12 - run: sudo xcode-select -s /Applications/Xcode_12.app/Contents/Developer - - name: Create XCFramework uses: unsignedapps/swift-create-xcframework@v1 From da17b9749d3468fe45334b46d47fe93e4439d0c9 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Wed, 7 Oct 2020 17:56:48 +0100 Subject: [PATCH 2/3] Removing animation(nil) for loop pagers too --- Sources/SwiftUIPager/PagerContent.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftUIPager/PagerContent.swift b/Sources/SwiftUIPager/PagerContent.swift index 6a1b5a2..c9401ff 100644 --- a/Sources/SwiftUIPager/PagerContent.swift +++ b/Sources/SwiftUIPager/PagerContent.swift @@ -156,10 +156,8 @@ extension Pager { let stack = HStack(spacing: interactiveItemSpacing) { ForEach(dataDisplayed, id: id) { item in Group { - if self.isInifinitePager { - self.content(item.element) - .opacity(self.isInifinitePager && self.isEdgePage(item) ? 0 : 1) - .animation(nil) // disable animation for opacity + if self.isInifinitePager && self.isEdgePage(item) { + EmptyView() } else { self.content(item.element) } From 79dd91626fe5c2e60208b649060c5624fa88d2e9 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Mon, 12 Oct 2020 16:30:17 +0100 Subject: [PATCH 3/3] Adding sensitivity modifier --- .../project.pbxproj | 4 ++ .../Examples/InfiniteExampleView.swift | 1 + .../PaginationSensitivity.swift | 43 ++++++++++++++++++ Sources/SwiftUIPager/Pager+Buildable.swift | 12 +++-- Sources/SwiftUIPager/Pager.swift | 6 ++- .../SwiftUIPager/PagerContent+Buildable.swift | 7 ++- .../SwiftUIPager/PagerContent+Helper.swift | 12 ++++- Sources/SwiftUIPager/PagerContent.swift | 11 +++-- SwiftUIPager.xcodeproj/project.pbxproj | 12 +++++ .../Pager+Buildable_Tests.swift | 9 ++++ .../PagerContent+Helper_Tests.swift | 23 +++++++++- .../PaginationSensitivity_Tests.swift | 45 +++++++++++++++++++ Tests/SwiftUIPagerTests/XCTestManifests.swift | 3 +- release_description.md | 5 ++- 14 files changed, 179 insertions(+), 14 deletions(-) create mode 100644 Sources/SwiftUIPager/PageConfiguration/PaginationSensitivity.swift create mode 100644 Tests/SwiftUIPagerTests/PaginationSensitivity_Tests.swift diff --git a/Example/SwiftUIPagerExample.xcodeproj/project.pbxproj b/Example/SwiftUIPagerExample.xcodeproj/project.pbxproj index 440a092..e27fb65 100644 --- a/Example/SwiftUIPagerExample.xcodeproj/project.pbxproj +++ b/Example/SwiftUIPagerExample.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 17D9E0FD23D4CF6900C5AE93 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 17D9E0FC23D4CF6900C5AE93 /* Assets.xcassets */; }; 17D9E10023D4CF6900C5AE93 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 17D9E0FE23D4CF6900C5AE93 /* LaunchScreen.storyboard */; }; 6B22DC81247E5C9A00EF95C5 /* NestedExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B22DC80247E5C9A00EF95C5 /* NestedExampleView.swift */; }; + 6B35B6C125346610000D618F /* PaginationSensitivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B35B6C025346610000D618F /* PaginationSensitivity.swift */; }; 6B4EC8A2240D072B001E7490 /* ColorsExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B4EC8A1240D072B001E7490 /* ColorsExampleView.swift */; }; 6B4EC8A4240D07D5001E7490 /* InfiniteExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B4EC8A3240D07D5001E7490 /* InfiniteExampleView.swift */; }; 6B4EC8A6240D0918001E7490 /* EmbeddedExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B4EC8A5240D0918001E7490 /* EmbeddedExampleView.swift */; }; @@ -59,6 +60,7 @@ 17D9E0FF23D4CF6900C5AE93 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 17D9E10123D4CF6900C5AE93 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6B22DC80247E5C9A00EF95C5 /* NestedExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NestedExampleView.swift; sourceTree = ""; }; + 6B35B6C025346610000D618F /* PaginationSensitivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PaginationSensitivity.swift; path = ../../Sources/SwiftUIPager/PageConfiguration/PaginationSensitivity.swift; sourceTree = ""; }; 6B4EC8A1240D072B001E7490 /* ColorsExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorsExampleView.swift; sourceTree = ""; }; 6B4EC8A3240D07D5001E7490 /* InfiniteExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfiniteExampleView.swift; sourceTree = ""; }; 6B4EC8A5240D0918001E7490 /* EmbeddedExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbeddedExampleView.swift; sourceTree = ""; }; @@ -187,6 +189,7 @@ children = ( 6BCF139124B2677B00AADE74 /* ContentLoadingPolicy.swift */, 6BEA731224ACF8D7007EA8DC /* GesturePriority.swift */, + 6B35B6C025346610000D618F /* PaginationSensitivity.swift */, 6B6FAA3C24D553C8000D1539 /* PagingAnimation.swift */, 6BEA730F24ACF8D7007EA8DC /* PositionAlignment.swift */, 6BEA731024ACF8D7007EA8DC /* SwipeDirection.swift */, @@ -283,6 +286,7 @@ 6BC5EDFF24866D9500E1E78C /* Buildable.swift in Sources */, 6B9C4A8A24B45F66004C06C5 /* OnDeactivateModifier.swift in Sources */, 6BEA731624ACF8D7007EA8DC /* GesturePriority.swift in Sources */, + 6B35B6C125346610000D618F /* PaginationSensitivity.swift in Sources */, 6BEA731324ACF8D7007EA8DC /* PositionAlignment.swift in Sources */, 6BEA731424ACF8D7007EA8DC /* SwipeDirection.swift in Sources */, 6BC5EE0224866D9500E1E78C /* PagerContent+Helper.swift in Sources */, diff --git a/Example/SwiftUIPagerExample/Examples/InfiniteExampleView.swift b/Example/SwiftUIPagerExample/Examples/InfiniteExampleView.swift index b977bc6..552ee3d 100644 --- a/Example/SwiftUIPagerExample/Examples/InfiniteExampleView.swift +++ b/Example/SwiftUIPagerExample/Examples/InfiniteExampleView.swift @@ -58,6 +58,7 @@ struct InfiniteExampleView: View { } .pagingPriority(.simultaneous) .loopPages() + .sensitivity(.high) .itemSpacing(10) .itemAspectRatio(1.3, alignment: .start) .padding(20) diff --git a/Sources/SwiftUIPager/PageConfiguration/PaginationSensitivity.swift b/Sources/SwiftUIPager/PageConfiguration/PaginationSensitivity.swift new file mode 100644 index 0000000..c9df413 --- /dev/null +++ b/Sources/SwiftUIPager/PageConfiguration/PaginationSensitivity.swift @@ -0,0 +1,43 @@ +// +// PaginationSensitivity.swift +// SwiftUIPagerExample +// +// Created by Fernando Moya de Rivas on 12/10/2020. +// Copyright © 2020 Fernando Moya de Rivas. All rights reserved. +// + +import CoreGraphics + +/// Defines how sensitive the pagination is to determine whether or not to move to the next the page. +@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) +public enum PaginationSensitivity: Equatable { + + /// The shift relative to container size needs to be greater than or equal to 75% + case low + + /// The shift relative to container size needs to be greater than or equal to 50% + case medium + + /// The shift relative to container size needs to be greater than or equal to 25% + case high + + /// The shift relative to container size needs to be greater than or equal to the specified value + case custom(CGFloat) + + /// The shift relative to container size needs to be greater than or equal to 50% + public static var `default`: Self = .medium + + var value: CGFloat { + switch self { + case .low: + return 0.75 + case .high: + return 0.25 + case .medium: + return 0.5 + case .custom(let value): + return value + } + } + +} diff --git a/Sources/SwiftUIPager/Pager+Buildable.swift b/Sources/SwiftUIPager/Pager+Buildable.swift index feff275..e9d01f8 100644 --- a/Sources/SwiftUIPager/Pager+Buildable.swift +++ b/Sources/SwiftUIPager/Pager+Buildable.swift @@ -11,12 +11,13 @@ import SwiftUI @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) extension Pager: Buildable, PagerProxy { - public typealias DraggingResult = (page: Int, newPage: Int, translation: CGFloat, velocity: Double) + /// Result of paginating + public typealias DragResult = (page: Int, newPage: Int, translation: CGFloat, velocity: Double) /// Sets the animation to be applied when the user stops dragging /// /// - Parameter value: callback to get an animation based on the result of dragging - public func pagingAnimation(_ value: ((DraggingResult) -> PagingAnimation)?) -> Self { + public func pagingAnimation(_ value: ((DragResult) -> PagingAnimation)?) -> Self { mutating(keyPath: \.pagingAnimation, value: value) } @@ -51,9 +52,13 @@ extension Pager: Buildable, PagerProxy { .mutating(keyPath: \.loopingCount, value: count) } - /// Disables dragging on `Pager` #if !os(tvOS) + /// Sensitivity used to determine whether or not to swipe the page + public func sensitivity(_ value: PaginationSensitivity) -> Self { + mutating(keyPath: \.sensitivity, value: value) + } + /// Makes `Pager` not delay gesture recognition /// /// - Parameter value: whether or not touches should be delayed @@ -61,6 +66,7 @@ extension Pager: Buildable, PagerProxy { mutating(keyPath: \.delaysTouches, value: value) } + /// Disables dragging on `Pager` public func disableDragging() -> Self { mutating(keyPath: \.allowsDragging, value: false) } diff --git a/Sources/SwiftUIPager/Pager.swift b/Sources/SwiftUIPager/Pager.swift index dd87a09..4b2b29c 100644 --- a/Sources/SwiftUIPager/Pager.swift +++ b/Sources/SwiftUIPager/Pager.swift @@ -65,7 +65,10 @@ public struct Pager: View where PageView: View, Element: /*** ViewModified properties ***/ /// Animation to be applied when the user stops dragging - var pagingAnimation: ((DraggingResult) -> PagingAnimation)? + var pagingAnimation: ((DragResult) -> PagingAnimation)? + + /// Sensitivity used to determine whether or not to swipe the page + var sensitivity: PaginationSensitivity = .default /// Policy to be applied when loading content var contentLoadingPolicy: ContentLoadingPolicy = .default @@ -204,6 +207,7 @@ public struct Pager: View where PageView: View, Element: .allowsDragging(allowsDragging) .pagingPriority(gesturePriority) .delaysTouches(delaysTouches) + .sensitivity(sensitivity) #endif pagerContent = allowsMultiplePagination ? pagerContent.multiplePagination() : pagerContent diff --git a/Sources/SwiftUIPager/PagerContent+Buildable.swift b/Sources/SwiftUIPager/PagerContent+Buildable.swift index 8581dbb..e8c1c9f 100644 --- a/Sources/SwiftUIPager/PagerContent+Buildable.swift +++ b/Sources/SwiftUIPager/PagerContent+Buildable.swift @@ -14,7 +14,7 @@ extension Pager.PagerContent: Buildable, PagerProxy { /// Sets the animation to be applied when the user stops dragging /// /// - Parameter value: callback to get an animation based on the result of dragging - func pagingAnimation(_ value: ((Pager.DraggingResult) -> PagingAnimation)?) -> Self { + func pagingAnimation(_ value: ((Pager.DragResult) -> PagingAnimation)?) -> Self { mutating(keyPath: \.pagingAnimation, value: value) } @@ -58,6 +58,11 @@ extension Pager.PagerContent: Buildable, PagerProxy { #if !os(tvOS) + /// Sensitivity used to determine whether or not to swipe the page + func sensitivity(_ value: PaginationSensitivity) -> Self { + mutating(keyPath: \.sensitivity, value: value) + } + /// Makes `Pager` not delay gesture recognition /// /// - Parameter value: whether or not touches should be delayed diff --git a/Sources/SwiftUIPager/PagerContent+Helper.swift b/Sources/SwiftUIPager/PagerContent+Helper.swift index 2b12535..a83651e 100644 --- a/Sources/SwiftUIPager/PagerContent+Helper.swift +++ b/Sources/SwiftUIPager/PagerContent+Helper.swift @@ -53,10 +53,18 @@ extension Pager.PagerContent { return totalOffset < 0 ? .forward : .backward } - /// The current page index. Will equal `page` if not dragging + /// Current page index, sensitivity 50%. Will equal `page` if not dragging var currentPage: Int { + currentPage(sensitivity: 0.5) + } + + /// Current page index, based on sensitivity. Will equal `page` if not dragging + func currentPage(sensitivity: CGFloat) -> Int { guard isDragging else { return page } - let newPage = -Int((totalOffset / pageDistance).rounded()) + page + let dOffset = totalOffset / pageDistance + let remaining = dOffset - dOffset.rounded(.towardZero) + let dPage = Int(dOffset.rounded(.towardZero)) + (abs(remaining) < sensitivity ? 0 : Int(remaining.rounded(.awayFromZero))) + let newPage = page - dPage guard isInifinitePager else { return max(min(newPage, numberOfPages - 1), 0) } guard numberOfPages > 0 else { return 0 } diff --git a/Sources/SwiftUIPager/PagerContent.swift b/Sources/SwiftUIPager/PagerContent.swift index 6a1b5a2..88e8125 100644 --- a/Sources/SwiftUIPager/PagerContent.swift +++ b/Sources/SwiftUIPager/PagerContent.swift @@ -51,7 +51,10 @@ extension Pager { /*** ViewModified properties ***/ /// Animation to be applied when the user stops dragging - var pagingAnimation: ((DraggingResult) -> PagingAnimation)? + var pagingAnimation: ((DragResult) -> PagingAnimation)? + + /// Sensitivity used to determine whether or not to swipe the page + var sensitivity: PaginationSensitivity = .default /// Policy to be applied when loading content var contentLoadingPolicy: ContentLoadingPolicy = .default @@ -251,7 +254,7 @@ extension Pager.PagerContent { } func onDragGestureEnded() { - let draggingResult = self.draggingResult + let draggingResult = self.dragResult let newPage = draggingResult.page let pageIncrement = draggingResult.increment @@ -274,8 +277,8 @@ extension Pager.PagerContent { } } - private var draggingResult: (page: Int, increment: Int) { - let currentPage = self.currentPage + private var dragResult: (page: Int, increment: Int) { + let currentPage = self.currentPage(sensitivity: sensitivity.value) let velocity = -self.draggingVelocity guard allowsMultiplePagination else { diff --git a/SwiftUIPager.xcodeproj/project.pbxproj b/SwiftUIPager.xcodeproj/project.pbxproj index 3807d05..88423d1 100644 --- a/SwiftUIPager.xcodeproj/project.pbxproj +++ b/SwiftUIPager.xcodeproj/project.pbxproj @@ -53,6 +53,11 @@ 6B2C305F248D740800E528F9 /* PagerContent+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BDE442823DE12480022A2F7 /* PagerContent+Helper.swift */; }; 6B2C3061248D740800E528F9 /* libswiftCore.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B2C2FFC248D58F300E528F9 /* libswiftCore.tbd */; settings = {ATTRIBUTES = (Weak, ); }; }; 6B2C3062248D740800E528F9 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B2C2FDE248D379D00E528F9 /* SwiftUI.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + 6B362CBD2534940B008DB2DF /* PaginationSensitivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B362CBC2534940B008DB2DF /* PaginationSensitivity.swift */; }; + 6B362CBE2534940B008DB2DF /* PaginationSensitivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B362CBC2534940B008DB2DF /* PaginationSensitivity.swift */; }; + 6B362CBF2534940B008DB2DF /* PaginationSensitivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B362CBC2534940B008DB2DF /* PaginationSensitivity.swift */; }; + 6B362CC02534940B008DB2DF /* PaginationSensitivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B362CBC2534940B008DB2DF /* PaginationSensitivity.swift */; }; + 6B362CC12534940B008DB2DF /* PaginationSensitivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B362CBC2534940B008DB2DF /* PaginationSensitivity.swift */; }; 6B6FAA3F24D56BAC000D1539 /* PagingAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B6FAA3E24D56BAC000D1539 /* PagingAnimation.swift */; }; 6B6FAA4024D56BAC000D1539 /* PagingAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B6FAA3E24D56BAC000D1539 /* PagingAnimation.swift */; }; 6B6FAA4124D56BAC000D1539 /* PagingAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B6FAA3E24D56BAC000D1539 /* PagingAnimation.swift */; }; @@ -135,6 +140,7 @@ 6B2C3001248D592100E528F9 /* libswiftCore.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libswiftCore.tbd; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS13.4.sdk/usr/lib/swift/libswiftCore.tbd; sourceTree = DEVELOPER_DIR; }; 6B2C3067248D740800E528F9 /* SwiftUIPager.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftUIPager.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6B2C3069248D747700E528F9 /* Info-Catalyst.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Catalyst.plist"; sourceTree = ""; }; + 6B362CBC2534940B008DB2DF /* PaginationSensitivity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PaginationSensitivity.swift; path = Sources/SwiftUIPager/PageConfiguration/PaginationSensitivity.swift; sourceTree = SOURCE_ROOT; }; 6B3F9C052488E6FE00AF5E74 /* Info-tvOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; 6B6FAA3E24D56BAC000D1539 /* PagingAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PagingAnimation.swift; path = Sources/SwiftUIPager/PageConfiguration/PagingAnimation.swift; sourceTree = SOURCE_ROOT; }; 6BBC3D6B2488DBE8004194BD /* SwiftUIPager.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftUIPager.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -275,6 +281,7 @@ children = ( 6BCF138B24B2674800AADE74 /* ContentLoadingPolicy.swift */, 6BEA731A24ACF9B0007EA8DC /* GesturePriority.swift */, + 6B362CBC2534940B008DB2DF /* PaginationSensitivity.swift */, 6B6FAA3E24D56BAC000D1539 /* PagingAnimation.swift */, 6BEA731924ACF9B0007EA8DC /* PositionAlignment.swift */, 6BEA731724ACF9AF007EA8DC /* SwipeDirection.swift */, @@ -561,6 +568,7 @@ 6BEF51A624C9ED34000DF66B /* PagerProxy.swift in Sources */, 6BCF138E24B2674F00AADE74 /* ContentLoadingPolicy.swift in Sources */, 172F4D5823DF830600FD2F15 /* Buildable.swift in Sources */, + 6B362CBF2534940B008DB2DF /* PaginationSensitivity.swift in Sources */, 172F4D5923DF830600FD2F15 /* Pager.swift in Sources */, 6BEA732724ACFA03007EA8DC /* SwipeDirection.swift in Sources */, 6BEA732224ACF9FF007EA8DC /* PositionAlignment.swift in Sources */, @@ -585,6 +593,7 @@ 6BEF51A724C9ED34000DF66B /* PagerProxy.swift in Sources */, 6BCF138F24B2675000AADE74 /* ContentLoadingPolicy.swift in Sources */, 172F4D8023DF8B3800FD2F15 /* View+Helper.swift in Sources */, + 6B362CC02534940B008DB2DF /* PaginationSensitivity.swift in Sources */, 172F4D8523DF8B4800FD2F15 /* Pager+Buildable.swift in Sources */, 6BEA732824ACFA04007EA8DC /* SwipeDirection.swift in Sources */, 6BEA732324ACF9FF007EA8DC /* PositionAlignment.swift in Sources */, @@ -609,6 +618,7 @@ 6BEF51A524C9ED33000DF66B /* PagerProxy.swift in Sources */, 6BCF138D24B2674F00AADE74 /* ContentLoadingPolicy.swift in Sources */, 6B2C305C248D740800E528F9 /* Buildable.swift in Sources */, + 6B362CBE2534940B008DB2DF /* PaginationSensitivity.swift in Sources */, 6B2C305E248D740800E528F9 /* Pager.swift in Sources */, 6BEA732624ACFA03007EA8DC /* SwipeDirection.swift in Sources */, 6BEA732124ACF9FE007EA8DC /* PositionAlignment.swift in Sources */, @@ -633,6 +643,7 @@ 6BBC3D782488DC0E004194BD /* Pager+Buildable.swift in Sources */, 6BEF51A824C9ED35000DF66B /* PagerProxy.swift in Sources */, 6BCF139024B2675000AADE74 /* ContentLoadingPolicy.swift in Sources */, + 6B362CC12534940B008DB2DF /* PaginationSensitivity.swift in Sources */, 6BBC3D742488DC01004194BD /* View+Helper.swift in Sources */, 6BEA732924ACFA04007EA8DC /* SwipeDirection.swift in Sources */, 6BEA732424ACFA00007EA8DC /* PositionAlignment.swift in Sources */, @@ -657,6 +668,7 @@ 6BEF51A424C9ED33000DF66B /* PagerProxy.swift in Sources */, 6BCF138C24B2674E00AADE74 /* ContentLoadingPolicy.swift in Sources */, 6BDE442C23DE12480022A2F7 /* Buildable.swift in Sources */, + 6B362CBD2534940B008DB2DF /* PaginationSensitivity.swift in Sources */, 6BDE442923DE12480022A2F7 /* Pager.swift in Sources */, 6BEA732524ACFA02007EA8DC /* SwipeDirection.swift in Sources */, 6BEA732024ACF9FE007EA8DC /* PositionAlignment.swift in Sources */, diff --git a/Tests/SwiftUIPagerTests/Pager+Buildable_Tests.swift b/Tests/SwiftUIPagerTests/Pager+Buildable_Tests.swift index 7935488..efefb90 100644 --- a/Tests/SwiftUIPagerTests/Pager+Buildable_Tests.swift +++ b/Tests/SwiftUIPagerTests/Pager+Buildable_Tests.swift @@ -35,6 +35,7 @@ final class Pager_Buildable_Tests: XCTestCase { XCTAssertEqual(pager.contentLoadingPolicy, .default) XCTAssertEqual(pager.allowsMultiplePagination, false) XCTAssertNil(pager.pagingAnimation) + XCTAssertEqual(pager.sensitivity, .default) let pagerContent = pager.content(for: CGSize(width: 100, height: 100)) XCTAssertNil(pagerContent.direction) @@ -42,6 +43,14 @@ final class Pager_Buildable_Tests: XCTestCase { XCTAssertFalse(pagerContent.isDragging) } + func test_GivenPager_WhenSensitivityHigh_ThenSensitivityHigh() { + var pager = givenPager + pager = pager.sensitivity(.high) + + let pagerContent = pager.content(for: CGSize(width: 100, height: 100)) + XCTAssertEqual(pagerContent.sensitivity, .high) + } + func test_GivenPager_WhenDelaysTouchesFalse_ThenMinimumDistanceZero() { var pager = givenPager pager = pager.delaysTouches(false) diff --git a/Tests/SwiftUIPagerTests/PagerContent+Helper_Tests.swift b/Tests/SwiftUIPagerTests/PagerContent+Helper_Tests.swift index 15e469b..bfbab6c 100644 --- a/Tests/SwiftUIPagerTests/PagerContent+Helper_Tests.swift +++ b/Tests/SwiftUIPagerTests/PagerContent+Helper_Tests.swift @@ -110,6 +110,24 @@ final class PagerContent_Helper_Tests: XCTestCase { XCTAssertEqual(currentPage, 3) } + func test_GivenHighSensitivePager_WhenCurrentPage_ThenThree() { + let pager = givenPager.pageOffset(2.25) + let currentPage = pager.currentPage(sensitivity: PaginationSensitivity.high.value) + XCTAssertEqual(currentPage, 3) + } + + func test_GivenHighSensitivePager_WhenCurrentPage_ThenTwo() { + let pager = givenPager.pageOffset(2.24) + let currentPage = pager.currentPage(sensitivity: PaginationSensitivity.high.value) + XCTAssertEqual(currentPage, 2) + } + + func test_GivenCustomSensitivePager_WhenCurrentPage_ThenTwo() { + let pager = givenPager.pageOffset(2.42) + let currentPage = pager.currentPage(sensitivity: PaginationSensitivity.custom(0.43).value) + XCTAssertEqual(currentPage, 2) + } + func test_GivenInfinitePagerDragging_WhenCurrentPage_Then19() { let pager = givenPager.pageOffset(-1).loopPages() let currentPage = pager.currentPage @@ -298,6 +316,9 @@ final class PagerContent_Helper_Tests: XCTestCase { ("test_GivenPager_WhenAxisForItem_ThenZero", test_GivenPager_WhenAxisForItem_ThenZero), ("test_GivenPagerWithRotation_WhenAxisForItem_ThenRotationAxis", test_GivenPagerWithRotation_WhenAxisForItem_ThenRotationAxis), ("test_GivenPager_WhenIsFocused_ThenTrue", test_GivenPager_WhenIsFocused_ThenTrue), - ("test_GivenPager_WhenIsFocused_ThenFalse", test_GivenPager_WhenIsFocused_ThenFalse) + ("test_GivenPager_WhenIsFocused_ThenFalse", test_GivenPager_WhenIsFocused_ThenFalse), + ("test_GivenHighSensitivePager_WhenCurrentPage_ThenThree", test_GivenHighSensitivePager_WhenCurrentPage_ThenThree), + ("test_GivenHighSensitivePager_WhenCurrentPage_ThenTwo", test_GivenHighSensitivePager_WhenCurrentPage_ThenTwo), + ("test_GivenCustomSensitivePager_WhenCurrentPage_ThenTwo", test_GivenCustomSensitivePager_WhenCurrentPage_ThenTwo) ] } diff --git a/Tests/SwiftUIPagerTests/PaginationSensitivity_Tests.swift b/Tests/SwiftUIPagerTests/PaginationSensitivity_Tests.swift new file mode 100644 index 0000000..c862152 --- /dev/null +++ b/Tests/SwiftUIPagerTests/PaginationSensitivity_Tests.swift @@ -0,0 +1,45 @@ +// +// PaginationSensitivity_Tests.swift +// +// +// Created by Fernando Moya de Rivas on 12/10/2020. +// + +import XCTest +@testable import SwiftUIPager + +final class PaginationSensitivity_Tests: XCTestCase { + + func test_GivenSensitivityHigh_WhenValue_ThenAQuarter() { + let sensitivity: PaginationSensitivity = .high + let value = sensitivity.value + XCTAssertEqual(value, 0.25) + } + + func test_GivenSensitivityLow_WhenValue_ThenThreeQuarters() { + let sensitivity: PaginationSensitivity = .low + let value = sensitivity.value + XCTAssertEqual(value, 0.75) + } + + func test_GivenSensitivityDefault_WhenValue_ThenOneHalf() { + let sensitivity: PaginationSensitivity = .default + let value = sensitivity.value + XCTAssertEqual(value, 0.5) + XCTAssertEqual(sensitivity, .medium) + } + + func test_GivenSensitivityCustom_WhenValue_ThenCustomValue() { + let sensitivity: PaginationSensitivity = .custom(0.42) + let value = sensitivity.value + XCTAssertEqual(value, 0.42) + } + + static var allTests = [ + ("test_GivenSensitivityHigh_WhenValue_ThenAQuarter", test_GivenSensitivityHigh_WhenValue_ThenAQuarter), + ("test_GivenSensitivityLow_WhenValue_ThenThreeQuarters", test_GivenSensitivityLow_WhenValue_ThenThreeQuarters), + ("test_GivenSensitivityDefault_WhenValue_ThenOneHalf", test_GivenSensitivityDefault_WhenValue_ThenOneHalf), + ("test_GivenSensitivityCustom_WhenValue_ThenCustomValue", test_GivenSensitivityCustom_WhenValue_ThenCustomValue) + ] + +} diff --git a/Tests/SwiftUIPagerTests/XCTestManifests.swift b/Tests/SwiftUIPagerTests/XCTestManifests.swift index 5db5ce9..cc189e3 100644 --- a/Tests/SwiftUIPagerTests/XCTestManifests.swift +++ b/Tests/SwiftUIPagerTests/XCTestManifests.swift @@ -10,7 +10,8 @@ public func allTests() -> [XCTestCaseEntry] { testCase(PagerWrapper_Tests.allTests), testCase(CGPoint+Angle_Tests.allTests), testCase(OnDeactivateModifier_Tests.allTests), - testCase(PagingAnimation_Tests.allTests) + testCase(PagingAnimation_Tests.allTests), + testCase(PaginationSensitivity_Tests.allTests) ] } #endif diff --git a/release_description.md b/release_description.md index 097247f..66e580c 100644 --- a/release_description.md +++ b/release_description.md @@ -1,2 +1,5 @@ ### Features -- Changes in workflows to publish Beta releases \ No newline at end of file +- New modifier to adjust pagination sensitivity + +### Fixes +- Fixed `animation` disabled with infinite pagers