Skip to content

Commit

Permalink
Bug fixed
Browse files Browse the repository at this point in the history
Fixed a bug where moving through multiple steps did not work properly.
  • Loading branch information
tkarlz committed Dec 9, 2023
1 parent 58e9904 commit 01b8514
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Supports iOS14 or later.

### Swift Package Manager

1. In Xcode, select “File” → “Add Packages...”
1. In Xcode, select “File” → “Add Package Dependencies...”
1. Enter https://github.com/tkarlz/BriefPagingControl.git

or you can add the following dependency to your `Package.swift`:
```swift
.package(url: "https://github.com/tkarlz/BriefPagingControl.git", .upToNextMajor(from: "1.0")),
.package(url: "https://github.com/tkarlz/BriefPagingControl.git", .upToNextMajor(from: "1.0.1")),
```

## Usage
Expand Down
44 changes: 26 additions & 18 deletions Sources/BriefPagingControl/BriefPagingControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,26 @@ public struct BriefPagingControl: View {
.offset(x: adjustedOffset)
.frame(width: (indicatorSize + spacing) * CGFloat(numberOfMainIndicators.rawValue + 4 + 1))
.onChange(of: currentPage) { [previousPage = currentPage] nextPage in
let step = (nextPage - previousPage).magnitude

withAnimation(animation) {
if previousPage < nextPage {
if displayedPosition + 1 > numberOfMainIndicators.halfValue {
activePage += 1
adjustedOffset -= (indicatorSize + spacing)
} else {
activePage += 1
displayedPosition += 1
}
} else {
if displayedPosition - 1 < -numberOfMainIndicators.halfValue {
activePage -= 1
adjustedOffset += (indicatorSize + spacing)
(0..<step).forEach { _ in
if previousPage < nextPage {
if displayedPosition + 1 > numberOfMainIndicators.halfValue {
activePage += 1
adjustedOffset -= (indicatorSize + spacing)
} else {
activePage += 1
displayedPosition += 1
}
} else {
activePage -= 1
displayedPosition -= 1
if displayedPosition - 1 < -numberOfMainIndicators.halfValue {
activePage -= 1
adjustedOffset += (indicatorSize + spacing)
} else {
activePage -= 1
displayedPosition -= 1
}
}
}
}
Expand All @@ -99,11 +103,15 @@ public struct BriefPagingControl: View {
}
.padding(.horizontal, (indicatorSize + spacing) / 2)
.onChange(of: currentPage) { [previousPage = currentPage] nextPage in
let step = (nextPage - previousPage).magnitude

withAnimation(animation) {
if previousPage < nextPage {
activePage += 1
} else {
activePage -= 1
(0..<step).forEach { _ in
if previousPage < nextPage {
activePage += 1
} else {
activePage -= 1
}
}
}
}
Expand Down

0 comments on commit 01b8514

Please sign in to comment.