refactored button group

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-28 15:24:07 -05:00
parent 94fcd7bf60
commit b0f8fbc864

View File

@ -13,7 +13,7 @@ import Combine
/// A button group contains combinations of related CTAs including ``Button``, ``TextLink``, and ``TextLinkCaret``. This group component controls a combination's orientation, spacing, size and allowable size pairings.
@objc(VDSButtonGroup)
open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, ButtongGroupPositionLayoutDelegate {
open class ButtonGroup: View {
//--------------------------------------------------
// MARK: - Enums
@ -30,23 +30,24 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
//An object containing number of Button components per row for iPhones
/// An object containing number of Button components per row for iPhones
open var rowQuantityPhone: Int = 0 { didSet { setNeedsUpdate() } }
//An object containing number of Button components per row for iPads
/// An object containing number of Button components per row for iPads
open var rowQuantityTablet: Int = 0 { didSet { setNeedsUpdate() } }
// An object containing number of Button components per row
/// An object containing number of Button components per row
open var rowQuantity: Int { UIDevice.isIPad ? rowQuantityTablet : rowQuantityPhone }
//If provided, aligns TextLink/TextLinkCaret alignment when rowQuantity is set one.
/// If provided, aligns TextLink/TextLinkCaret alignment when rowQuantity is set one.
open var alignment: Alignment = .center { didSet { setNeedsUpdate() }}
/// Array of Buttonable Views that are shown in the group.
open var buttons: [Buttonable] = [] { didSet { setNeedsUpdate() }}
/// If provided, width of Button components will be rendered based on this value. If omitted, default button widths are rendered.
private var _childWidth: ChildWidth?
/// If provided, width of Button components will be rendered based on this value. If omitted, default button widths are rendered.
open var childWidth: ChildWidth? {
get { _childWidth }
set {
@ -165,7 +166,9 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
self.collectionView.collectionViewLayout.invalidateLayout()
}
}
}
extension ButtonGroup: UICollectionViewDataSource, UICollectionViewDelegate {
//--------------------------------------------------
// MARK: - UICollectionViewDataSource
//--------------------------------------------------
@ -202,8 +205,10 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
return false
}
}
}
public func collectionView(_ collectionView: UICollectionView, buttonableAtIndexPath indexPath: IndexPath) -> Buttonable {
extension ButtonGroup : ButtongGroupPositionLayoutDelegate {
func collectionView(_ collectionView: UICollectionView, buttonableAtIndexPath indexPath: IndexPath) -> Buttonable {
buttons[indexPath.row]
}
}