updated from Control to View and add publisher
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c76d3e7b76
commit
296703076e
@ -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.
|
///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
|
@objcMembers
|
||||||
@objc(VDSPagination)
|
@objc(VDSPagination)
|
||||||
open class Pagination: Control, Changeable {
|
open class Pagination: View {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
private let pageChangedSubject = PassthroughSubject<Pagination, Never>()
|
||||||
|
|
||||||
///Maximum component width
|
///Maximum component width
|
||||||
private let maxWidth: CGFloat = 288.0
|
private let maxWidth: CGFloat = 288.0
|
||||||
///Collectionview width anchor
|
///Collectionview width anchor
|
||||||
@ -52,8 +54,8 @@ open class Pagination: Control, Changeable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var onChangeSubscriber: AnyCancellable?
|
public var pageChangedPublisher: AnyPublisher<Pagination, Never> { pageChangedSubject.eraseToAnyPublisher() }
|
||||||
|
|
||||||
///Previous button to select previous page
|
///Previous button to select previous page
|
||||||
public let previousButton: PaginationButton = .init(type: .previous)
|
public let previousButton: PaginationButton = .init(type: .previous)
|
||||||
///Next button to select next page
|
///Next button to select next page
|
||||||
@ -147,6 +149,11 @@ open class Pagination: Control, Changeable {
|
|||||||
.sink { [weak self] value in
|
.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.
|
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)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
pageChangedPublisher.sink { [weak self] control in
|
||||||
|
guard let self else { return }
|
||||||
|
onPageDidSelect?(control.selectedPage)
|
||||||
|
}.store(in: &subscribers)
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setDefaults() {
|
open override func setDefaults() {
|
||||||
@ -197,8 +204,7 @@ open class Pagination: Control, Changeable {
|
|||||||
let isNextAction = sender == nextButton
|
let isNextAction = sender == nextButton
|
||||||
_selectedPageIndex = if isNextAction { _selectedPageIndex + 1 } else { _selectedPageIndex - 1 }
|
_selectedPageIndex = if isNextAction { _selectedPageIndex + 1 } else { _selectedPageIndex - 1 }
|
||||||
updateSelection()
|
updateSelection()
|
||||||
onPageDidSelect?(selectedPage)
|
pageChangedSubject.send(self)
|
||||||
sendActions(for: .valueChanged)
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
UIAccessibility.post(notification: .announcement, argument: paginationDescription)
|
UIAccessibility.post(notification: .announcement, argument: paginationDescription)
|
||||||
@ -253,8 +259,7 @@ extension Pagination: UICollectionViewDelegate, UICollectionViewDataSource, UICo
|
|||||||
guard _selectedPageIndex != indexPath.row else { return }
|
guard _selectedPageIndex != indexPath.row else { return }
|
||||||
_selectedPageIndex = indexPath.row
|
_selectedPageIndex = indexPath.row
|
||||||
updateSelection()
|
updateSelection()
|
||||||
onPageDidSelect?(selectedPage)
|
pageChangedSubject.send(self)
|
||||||
sendActions(for: .valueChanged)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user