Skip to content

Commit

Permalink
Merge pull request #65 from fermoya/fix/issue-63
Browse files Browse the repository at this point in the history
Fixing infinitePager with no elements
  • Loading branch information
fermoya authored Jul 1, 2020
2 parents e9464e5 + c50dba9 commit aae612f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Sources/SwiftUIPager/Pager+Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extension Pager {
let newPage = -Int((totalOffset / pageDistance).rounded()) + page

guard isInifinitePager else { return max(min(newPage, numberOfPages - 1), 0) }
guard numberOfPages > 0 else { return 0 }
return max((newPage + numberOfPages) % numberOfPages, 0)
}

Expand Down Expand Up @@ -139,12 +140,14 @@ extension Pager {
/// Lower bound of the data displaed
var lowerPageDisplayed: Int {
guard isInifinitePager else { return max(0, page - maximumNumberOfPages / 2) }
guard numberOfPages > 0 else { return 0 }
return ((page - maximumNumberOfPages / 2) + numberOfPages) % numberOfPages
}

/// Upper bound of the data displaed
var upperPageDisplayed: Int {
guard isInifinitePager else { return min(numberOfPages - 1, page + maximumNumberOfPages / 2) }
guard numberOfPages > 0 else { return 0 }
return (Int((Float(maximumNumberOfPages) / 2).rounded(.up)) + page) % numberOfPages
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftUIPager.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SwiftUIPager"
s.version = "1.6.1"
s.version = "1.6.2"
s.summary = "Native pager for SwiftUI. Easily to use, easy to customize."

s.description = <<-DESC
Expand Down
20 changes: 10 additions & 10 deletions SwiftUIPager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@
"$(inherited)",
"$(SDKROOT)/usr/lib/swift",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SDKROOT = macosx;
Expand Down Expand Up @@ -577,7 +577,7 @@
"$(inherited)",
"$(SDKROOT)/usr/lib/swift",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SDKROOT = macosx;
Expand Down Expand Up @@ -609,7 +609,7 @@
"$(inherited)",
"$(SDKROOT)/usr/lib/swift",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SDKROOT = watchos;
Expand Down Expand Up @@ -642,7 +642,7 @@
"$(inherited)",
"$(SDKROOT)/usr/lib/swift",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SDKROOT = watchos;
Expand Down Expand Up @@ -673,7 +673,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -702,7 +702,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -731,7 +731,7 @@
"$(inherited)",
"$(SDKROOT)/usr/lib/swift",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SDKROOT = appletvos;
Expand Down Expand Up @@ -763,7 +763,7 @@
"$(inherited)",
"$(SDKROOT)/usr/lib/swift",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SDKROOT = appletvos;
Expand Down Expand Up @@ -940,7 +940,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -970,7 +970,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.6.1;
MARKETING_VERSION = 1.6.2;
PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.SwiftUIPager;
PRODUCT_NAME = SwiftUIPager;
SKIP_INSTALL = YES;
Expand Down

0 comments on commit aae612f

Please sign in to comment.