-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from guardian/aml/separate-out-progress-buttons
iOS - Separate out pagination button from progress bar component
- Loading branch information
Showing
4 changed files
with
84 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import SwiftUI | ||
|
||
public struct PaginationButtons: View { | ||
let iconColor: Color | ||
let borderColor: Color | ||
@Binding var selectedIndex: Int? | ||
let pageCount: Int | ||
|
||
public init( | ||
iconColor: Color, | ||
borderColor: Color, | ||
selectedIndex: Binding<Int?>, | ||
pageCount: Int | ||
) { | ||
self.iconColor = iconColor | ||
self.borderColor = borderColor | ||
self._selectedIndex = selectedIndex | ||
self.pageCount = pageCount | ||
} | ||
|
||
private var backDisabled: Bool { | ||
guard let selectedIndex else { return true } | ||
return selectedIndex == 0 | ||
} | ||
|
||
private var forwardDisabled: Bool { | ||
guard let selectedIndex else { return true } | ||
return selectedIndex >= pageCount - 1 | ||
} | ||
|
||
public var body: some View { | ||
HStack { | ||
IconButton( | ||
icon: Image(.chevronLeft), | ||
size: .small, | ||
iconColor: iconColor, | ||
borderColor: borderColor, | ||
disabled: backDisabled | ||
) { | ||
withAnimation { | ||
if let selectedIndex { | ||
self.selectedIndex = selectedIndex - 1 | ||
} | ||
} | ||
} | ||
IconButton( | ||
icon: Image(.chevronRight), | ||
size: .small, | ||
iconColor: iconColor, | ||
borderColor: borderColor, | ||
disabled: forwardDisabled | ||
) { | ||
withAnimation { | ||
if let selectedIndex { | ||
self.selectedIndex = selectedIndex + 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
PaginationButtons(iconColor: .blue, borderColor: .red, selectedIndex: .constant(0), pageCount: 10) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters