Merge branch 'mbruce/bugfix' into 'develop'

Fixed bug in ButtonGroup

See merge request BPHV_MIPS/vds_ios!287
This commit is contained in:
Bruce, Matt R 2024-08-16 21:01:03 +00:00
commit 633a8d3b78
13 changed files with 125 additions and 83 deletions

View File

@ -111,9 +111,13 @@ open class SelectorBase: Control, SelectorControlable {
open override func setDefaults() { open override func setDefaults() {
super.setDefaults() super.setDefaults()
showError = false
onClick = { control in onClick = { control in
control.toggle() control.toggle()
} }
onChange = nil
bridge_accessibilityLabelBlock = { [weak self] in bridge_accessibilityLabelBlock = { [weak self] in
guard let self else { return "" } guard let self else { return "" }

View File

@ -123,6 +123,7 @@ open class SelectorGroupBase<SelectorItemType: Groupable>: Control, SelectorGrou
open override func setDefaults() { open override func setDefaults() {
super.setDefaults() super.setDefaults()
onChange = nil onChange = nil
items = []
} }
/// Handler for the Group to override on a select event. /// Handler for the Group to override on a select event.
@ -137,13 +138,6 @@ open class SelectorGroupBase<SelectorItemType: Groupable>: Control, SelectorGrou
self?.sendActions(for: .valueChanged) self?.sendActions(for: .valueChanged)
} }
} }
/// Resets to default settings.
open override func reset() {
super.reset()
items.forEach{ $0.reset() }
setItemsActions()
}
} }

View File

@ -117,10 +117,11 @@ open class Breadcrumbs: View {
containerView.pinToSuperView() containerView.pinToSuperView()
} }
/// Resets to default settings. open override func setDefaults() {
open override func reset() { super.setDefaults()
super.reset() breadcrumbs = []
breadcrumbs.forEach { $0.reset() } breadcrumbModels = []
isEnabled = true
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -173,6 +173,7 @@ open class ButtonGroup: View {
rowQuantityTablet = 0 rowQuantityTablet = 0
alignment = .center alignment = .center
childWidth = nil childWidth = nil
buttons = []
} }
open override func reset() { open override func reset() {

View File

@ -49,56 +49,53 @@ class ButtonCollectionViewRow {
func layout(for position: ButtonGroup.Alignment, with collectionViewWidth: CGFloat){ func layout(for position: ButtonGroup.Alignment, with collectionViewWidth: CGFloat){
var offset = 0.0 var offset = 0.0
let height = rowHeight let height = rowHeight
attributes.last?.spacing = 0 attributes.last?.spacing = 0
//filter only the buttons since this is the only
//object we can change the frames for.
let buttonAttributes = attributes.filter{$0.isButton}
//check to see if you have buttons and there is a percentage if !buttonAttributes.isEmpty {
if let buttonPercentage, hasButtons, buttonPercentage > 0 { let buttonCount = CGFloat(buttonAttributes.count)
var usedSpace = 0.0 ///Calculate the spaces between items in the row
//get the width for the buttons let totalSpacingBetweenAttributes = attributes.reduce(0.0) { $0 + $1.spacing }
for attribute in attributes {
if !attribute.isButton { //see how much of the rows width is used for
usedSpace += attribute.frame.width //non-buttons that are BaseButton Subclasses that are not "Button"
} let nonButtonSpace = attributes.filter { !$0.isButton }.reduce(0.0) { $0 + $1.frame.width }
usedSpace += attribute.spacing
} //getting available button space since textlinks need their space
let buttonAvailableSpace = collectionViewWidth - usedSpace let buttonsAvailableSpace = collectionViewWidth - nonButtonSpace - totalSpacingBetweenAttributes
let realPercentage = (buttonPercentage / 100) let buttonEqualSpacing = buttonsAvailableSpace / buttonCount
let buttonWidth = realPercentage * buttonAvailableSpace var maxButtonWidth = buttonEqualSpacing //default to equal spacing
// print("buttonPercentage :\(realPercentage)") var buttonCalculatedPercentage: CGFloat = 0.0
// print("collectionView width:\(collectionViewWidth)")
// print("usedSpace width:\(usedSpace)") //check to see if you have buttons and there is a percentage
// print("button available width:\(buttonAvailableSpace)") if let buttonPercentage, hasButtons, buttonPercentage > 0 {
// print("each button width:\(buttonWidth)\n") buttonCalculatedPercentage = CGFloat(buttonPercentage / 100.0)
// print("minimum widht:\(ButtonSize.large.minimumWidth)") let buttonPercentageWidth = buttonCalculatedPercentage * buttonsAvailableSpace
// test sizing maxButtonWidth = min(max(buttonPercentageWidth, Button.Size.large.minimumWidth), maxButtonWidth)
var testSize = 0.0
var buttonCount = 0.0
for attribute in attributes {
if attribute.isButton {
testSize += buttonWidth
buttonCount += 1
}
} }
if buttonWidth >= Button.Size.large.minimumWidth { //resize the buttonAttributes
if testSize <= buttonAvailableSpace { if maxButtonWidth >= Button.Size.large.minimumWidth {
for attribute in attributes { //if there is enough room for all buttons
if attribute.isButton { if maxButtonWidth * buttonCount <= buttonsAvailableSpace {
attribute.frame.size.width = buttonWidth for attribute in buttonAttributes {
} attribute.frame.size.width = buttonCalculatedPercentage.isZero ? min(attribute.frame.size.width, maxButtonWidth) : maxButtonWidth
} }
} else { } else {
let distributedSize = buttonAvailableSpace / buttonCount //if not enough room, give all buttons the same width
for attribute in attributes { for attribute in buttonAttributes {
if attribute.isButton { attribute.frame.size.width = buttonEqualSpacing
attribute.frame.size.width = distributedSize
}
} }
} }
} }
} }
//update the offset based on position
switch position { switch position {
case .left: case .left:
break break
@ -181,7 +178,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
var rows = [ButtonCollectionViewRow]() var rows = [ButtonCollectionViewRow]()
rows.append(ButtonCollectionViewRow()) rows.append(ButtonCollectionViewRow())
let collectionViewWidth = collectionView.frame.width let collectionViewWidth = collectionView.horizontalPinnedWidth() ?? collectionView.frame.width
for item in 0..<totalItems { for item in 0..<totalItems {
@ -200,7 +197,8 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
// determine if the current button will fit in the row // determine if the current button will fit in the row
let rowItemCount = rows.last?.attributes.count ?? 0 let rowItemCount = rows.last?.attributes.count ?? 0
if (layoutWidthIterator + itemSize.width) > collectionViewWidth || (rowQuantity > 0 && rowItemCount == rowQuantity) { if (layoutWidthIterator + itemSize.width) > collectionViewWidth && rowQuantity == 0
|| (rowQuantity > 0 && rowItemCount == rowQuantity) {
// If the current row width (after this item being laid out) is exceeding // If the current row width (after this item being laid out) is exceeding
// the width of the collection view content, put it in the next line // the width of the collection view content, put it in the next line
@ -318,3 +316,5 @@ class ButtonGroupPositionLayout: UICollectionViewLayout {
} }
} }

View File

@ -106,14 +106,15 @@ open class CarouselScrollbar: View {
/// A callback when the scrubber position changes. Passes parameters (position). /// A callback when the scrubber position changes. Passes parameters (position).
open var onScrubberDrag: ((Int) -> Void)? { open var onScrubberDrag: ((Int) -> Void)? {
get { nil } didSet {
set {
onScrubberDragCancellable?.cancel() onScrubberDragCancellable?.cancel()
if let newValue { if let onScrubberDrag {
onScrubberDragCancellable = onScrubberDragPublisher onScrubberDragCancellable = onScrubberDragPublisher
.sink { c in .sink { c in
newValue(c) onScrubberDrag(c)
} }
} else {
onScrubberDragCancellable = nil
} }
} }
} }
@ -124,14 +125,15 @@ open class CarouselScrollbar: View {
/// A callback when the thumb move forward. Passes parameters (position). /// A callback when the thumb move forward. Passes parameters (position).
open var onMoveForward: ((Int) -> Void)? { open var onMoveForward: ((Int) -> Void)? {
get { nil } didSet {
set {
onMoveForwardCancellable?.cancel() onMoveForwardCancellable?.cancel()
if let newValue { if let onMoveForward {
onMoveForwardCancellable = onMoveForwardPublisher onMoveForwardCancellable = onMoveForwardPublisher
.sink { c in .sink { c in
newValue(c) onMoveForward(c)
} }
} else {
onMoveForwardCancellable = nil
} }
} }
} }
@ -142,14 +144,15 @@ open class CarouselScrollbar: View {
/// A callback when the thumb move backward. Passes parameters (position). /// A callback when the thumb move backward. Passes parameters (position).
open var onMoveBackward: ((Int) -> Void)? { open var onMoveBackward: ((Int) -> Void)? {
get { nil } didSet {
set {
onMoveBackwardCancellable?.cancel() onMoveBackwardCancellable?.cancel()
if let newValue { if let onMoveBackward {
onMoveBackwardCancellable = onMoveBackwardPublisher onMoveBackwardCancellable = onMoveBackwardPublisher
.sink { c in .sink { c in
newValue(c) onMoveBackward(c)
} }
} else {
onMoveBackwardCancellable = nil
} }
} }
} }
@ -160,14 +163,15 @@ open class CarouselScrollbar: View {
/// A callback when the thumb touch start. Passes parameters (position). /// A callback when the thumb touch start. Passes parameters (position).
open var onThumbTouchStart: ((Int) -> Void)? { open var onThumbTouchStart: ((Int) -> Void)? {
get { nil } didSet {
set {
onThumbTouchStartCancellable?.cancel() onThumbTouchStartCancellable?.cancel()
if let newValue { if let onThumbTouchStart {
onThumbTouchStartCancellable = onThumbTouchStartPublisher onThumbTouchStartCancellable = onThumbTouchStartPublisher
.sink { c in .sink { c in
newValue(c) onThumbTouchStart(c)
} }
} else {
onThumbTouchStartCancellable = nil
} }
} }
} }
@ -178,14 +182,15 @@ open class CarouselScrollbar: View {
/// A callback when the thumb touch end. Passes parameters (position). /// A callback when the thumb touch end. Passes parameters (position).
open var onThumbTouchEnd: ((Int) -> Void)? { open var onThumbTouchEnd: ((Int) -> Void)? {
get { nil } didSet {
set {
onThumbTouchEndCancellable?.cancel() onThumbTouchEndCancellable?.cancel()
if let newValue { if let onThumbTouchEnd {
onThumbTouchEndCancellable = onThumbTouchEndPublisher onThumbTouchEndCancellable = onThumbTouchEndPublisher
.sink { c in .sink { c in
newValue(c) onThumbTouchEnd(c)
} }
} else {
onThumbTouchEndCancellable = nil
} }
} }
} }
@ -294,6 +299,19 @@ open class CarouselScrollbar: View {
thumbView.layer.addSublayer(thumbViewLayer) thumbView.layer.addSublayer(thumbViewLayer)
} }
open override func setDefaults() {
super.setDefaults()
onMoveForward = nil
onMoveBackward = nil
onScrubberDrag = nil
onThumbTouchEnd = nil
onThumbTouchStart = nil
layout = .oneUP
numberOfSlides = 1
totalPositions = 1
position = 1
}
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
trackView.backgroundColor = trackColorConfiguration.getColor(surface) trackView.backgroundColor = trackColorConfiguration.getColor(surface)

View File

@ -62,6 +62,11 @@ open class Checkbox: SelectorBase {
selectorColorConfiguration.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .selected) selectorColorConfiguration.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .selected)
} }
open override func setDefaults() {
super.setDefaults()
isAnimated = false
}
/// This will change the state of the Selector and execute the actionBlock if provided. /// This will change the state of the Selector and execute the actionBlock if provided.
open override func toggle() { open override func toggle() {
guard isEnabled else { return } guard isEnabled else { return }

View File

@ -87,6 +87,12 @@ open class CheckboxGroup: SelectorGroupBase<CheckboxItem>, SelectorGroupMultiSel
mainStackView.spacing = VDSLayout.space6X mainStackView.spacing = VDSLayout.space6X
} }
open override func setDefaults() {
super.setDefaults()
showError = false
inputId = nil
}
public override func didSelect(_ selectedControl: CheckboxItem) { public override func didSelect(_ selectedControl: CheckboxItem) {
selectedControl.toggle() selectedControl.toggle()
if selectedControl.isSelected, showError{ if selectedControl.isSelected, showError{

View File

@ -55,6 +55,11 @@ open class CheckboxItem: SelectorItemBase<Checkbox> {
print(foo.customView.isAnimated) print(foo.customView.isAnimated)
} }
open override func setDefaults() {
super.setDefaults()
isAnimated = false
}
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.
open override func updateView() { open override func updateView() {

View File

@ -82,24 +82,15 @@ open class DropdownSelect: EntryFieldBase<String> {
open var inlineDisplayLabel = Label().with { open var inlineDisplayLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.setContentCompressionResistancePriority(.required, for: .horizontal) $0.setContentCompressionResistancePriority(.required, for: .horizontal)
$0.textAlignment = .left
$0.textStyle = .boldBodyLarge
$0.numberOfLines = 1
$0.sizeToFit()
} }
open var selectedOptionLabel = Label().with { open var selectedOptionLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.setContentCompressionResistancePriority(.required, for: .horizontal) $0.setContentCompressionResistancePriority(.required, for: .horizontal)
$0.textAlignment = .left
$0.textStyle = .bodyLarge
$0.numberOfLines = 1
} }
open var dropdownField = UITextField().with { open var dropdownField = UITextField().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.tintColor = UIColor.clear
$0.font = TextStyle.bodyLarge.font
} }
open var optionsPicker = UIPickerView() open var optionsPicker = UIPickerView()
@ -163,13 +154,25 @@ open class DropdownSelect: EntryFieldBase<String> {
super.setDefaults() super.setDefaults()
showInlineLabel = false showInlineLabel = false
selectId = nil selectId = nil
inlineDisplayLabel.textAlignment = .left
inlineDisplayLabel.textStyle = .boldBodyLarge inlineDisplayLabel.textStyle = .boldBodyLarge
inlineDisplayLabel.numberOfLines = 1
selectedOptionLabel.textAlignment = .left
selectedOptionLabel.textStyle = .bodyLarge selectedOptionLabel.textStyle = .bodyLarge
selectedOptionLabel.numberOfLines = 1
dropdownField.tintColor = UIColor.clear
dropdownField.font = TextStyle.bodyLarge.font
showInlineLabel = false showInlineLabel = false
options = [] options = []
selectId = nil selectId = nil
} }
open override func reset() {
inlineDisplayLabel.reset()
selectedOptionLabel.reset()
super.reset()
}
open override func getFieldContainer() -> UIView { open override func getFieldContainer() -> UIView {
let controlStackView = UIStackView().with { let controlStackView = UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false

View File

@ -57,7 +57,7 @@ open class Pagination: View {
///Next button to select next page ///Next button to select next page
public let nextButton: PaginationButton = .init(type: .next) public let nextButton: PaginationButton = .init(type: .next)
/// A callback when the page changes. Passes parameters (selectedPage). /// A callback when the page changes. Passes parameters (selectedPage).
public var onPageDidSelect: ((Int) -> Void)? open var onPageDidSelect: ((Int) -> Void)?
/// Total number of pages, allows limit ranging from 0 to 9999. /// Total number of pages, allows limit ranging from 0 to 9999.
@Clamping(range: 0...9999) @Clamping(range: 0...9999)
public var total: Int { public var total: Int {
@ -70,7 +70,7 @@ open class Pagination: View {
} }
} }
///Selected active page number and clips to total pages if selected index is greater than the total pages. ///Selected active page number and clips to total pages if selected index is greater than the total pages.
public var selectedPage: Int { open var selectedPage: Int {
set { set {
if newValue >= total { if newValue >= total {
_selectedPageIndex = total - 1 _selectedPageIndex = total - 1

View File

@ -288,7 +288,6 @@ open class TitleLockup: View {
subTitleModel = nil subTitleModel = nil
} }
var labelViews = [UIView]()
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()

View File

@ -1,3 +1,9 @@
1.0.72
----------------
- ONEAPP-9311 - InputStepper - Finished
- ONEAPP-9314 - PriceLockup - Finished
- CXTDT-599736 - All classes refactored workflow setup(), reset(), setDefaults()
1.0.71 1.0.71
---------------- ----------------
- CXTDT-581800 - DatePicker - Selected Error state icon - CXTDT-581800 - DatePicker - Selected Error state icon