updated from Control to View and add publisher

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-08-27 14:28:51 -05:00
parent c76d3e7b76
commit 296703076e

View File

@ -13,11 +13,13 @@ import Combine
///Pagination is a control that enables customers to navigate multiple pages of content by selecting either a specific page or the next or previous set of four pages.
@objcMembers
@objc(VDSPagination)
open class Pagination: Control, Changeable {
open class Pagination: View {
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
private let pageChangedSubject = PassthroughSubject<Pagination, Never>()
///Maximum component width
private let maxWidth: CGFloat = 288.0
///Collectionview width anchor
@ -52,8 +54,8 @@ open class Pagination: Control, Changeable {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public var onChangeSubscriber: AnyCancellable?
public var pageChangedPublisher: AnyPublisher<Pagination, Never> { pageChangedSubject.eraseToAnyPublisher() }
///Previous button to select previous page
public let previousButton: PaginationButton = .init(type: .previous)
///Next button to select next page
@ -147,6 +149,11 @@ open class Pagination: Control, Changeable {
.sink { [weak self] value in
self?.collectionViewWidthAnchor?.constant = value //As cell width is dynamic i.e cell may contain 2 or 3 or 4 charcters. Make sure that all the visible cells are displayed.
}.store(in: &subscribers)
pageChangedPublisher.sink { [weak self] control in
guard let self else { return }
onPageDidSelect?(control.selectedPage)
}.store(in: &subscribers)
}
open override func setDefaults() {
@ -197,8 +204,7 @@ open class Pagination: Control, Changeable {
let isNextAction = sender == nextButton
_selectedPageIndex = if isNextAction { _selectedPageIndex + 1 } else { _selectedPageIndex - 1 }
updateSelection()
onPageDidSelect?(selectedPage)
sendActions(for: .valueChanged)
pageChangedSubject.send(self)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
guard let self else { return }
UIAccessibility.post(notification: .announcement, argument: paginationDescription)
@ -253,8 +259,7 @@ extension Pagination: UICollectionViewDelegate, UICollectionViewDataSource, UICo
guard _selectedPageIndex != indexPath.row else { return }
_selectedPageIndex = indexPath.row
updateSelection()
onPageDidSelect?(selectedPage)
sendActions(for: .valueChanged)
pageChangedSubject.send(self)
}
}