From 47a38e5d3f3470b8741f9cb7a9e294ecb8d02e52 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Sat, 10 Aug 2024 11:46:51 -0500 Subject: [PATCH 1/8] release notes update Signed-off-by: Matt Bruce --- VDS/SupportingFiles/ReleaseNotes.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/VDS/SupportingFiles/ReleaseNotes.txt b/VDS/SupportingFiles/ReleaseNotes.txt index 69b82096..80d0131b 100644 --- a/VDS/SupportingFiles/ReleaseNotes.txt +++ b/VDS/SupportingFiles/ReleaseNotes.txt @@ -1,3 +1,8 @@ +1.0.72 +---------------- +- ONEAPP-9311 - InputStepper - Finished +- CXTDT-599736 - All classes refactored workflow setup(), reset(), setDefaults() + 1.0.71 ---------------- - CXTDT-581800 - DatePicker - Selected Error state icon From bbf521b1e52196d0d172707b90d12f20022c51a4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 15 Aug 2024 14:00:17 -0500 Subject: [PATCH 2/8] updated setDefaults() Signed-off-by: Matt Bruce --- VDS/BaseClasses/Selector/SelectorBase.swift | 4 ++ .../Selector/SelectorGroupBase.swift | 8 +-- VDS/Components/Breadcrumbs/Breadcrumbs.swift | 9 +-- .../Buttons/ButtonGroup/ButtonGroup.swift | 1 + .../CarouselScrollbar/CarouselScrollbar.swift | 58 ++++++++++++------- VDS/Components/Checkbox/Checkbox.swift | 5 ++ VDS/Components/Checkbox/CheckboxGroup.swift | 6 ++ VDS/Components/Checkbox/CheckboxItem.swift | 5 ++ .../DropdownSelect/DropdownSelect.swift | 21 ++++--- 9 files changed, 77 insertions(+), 40 deletions(-) diff --git a/VDS/BaseClasses/Selector/SelectorBase.swift b/VDS/BaseClasses/Selector/SelectorBase.swift index 05c8a1e8..6af003fd 100644 --- a/VDS/BaseClasses/Selector/SelectorBase.swift +++ b/VDS/BaseClasses/Selector/SelectorBase.swift @@ -111,9 +111,13 @@ open class SelectorBase: Control, SelectorControlable { open override func setDefaults() { super.setDefaults() + showError = false + onClick = { control in control.toggle() } + + onChange = nil bridge_accessibilityLabelBlock = { [weak self] in guard let self else { return "" } diff --git a/VDS/BaseClasses/Selector/SelectorGroupBase.swift b/VDS/BaseClasses/Selector/SelectorGroupBase.swift index 5cda9c82..e04b5e5a 100644 --- a/VDS/BaseClasses/Selector/SelectorGroupBase.swift +++ b/VDS/BaseClasses/Selector/SelectorGroupBase.swift @@ -123,6 +123,7 @@ open class SelectorGroupBase: Control, SelectorGrou open override func setDefaults() { super.setDefaults() onChange = nil + items = [] } /// Handler for the Group to override on a select event. @@ -137,13 +138,6 @@ open class SelectorGroupBase: Control, SelectorGrou self?.sendActions(for: .valueChanged) } } - - /// Resets to default settings. - open override func reset() { - super.reset() - items.forEach{ $0.reset() } - setItemsActions() - } } diff --git a/VDS/Components/Breadcrumbs/Breadcrumbs.swift b/VDS/Components/Breadcrumbs/Breadcrumbs.swift index 1179807d..808b5548 100644 --- a/VDS/Components/Breadcrumbs/Breadcrumbs.swift +++ b/VDS/Components/Breadcrumbs/Breadcrumbs.swift @@ -117,10 +117,11 @@ open class Breadcrumbs: View { containerView.pinToSuperView() } - /// Resets to default settings. - open override func reset() { - super.reset() - breadcrumbs.forEach { $0.reset() } + open override func setDefaults() { + super.setDefaults() + breadcrumbs = [] + breadcrumbModels = [] + isEnabled = true } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 486301c7..520c8d1f 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -173,6 +173,7 @@ open class ButtonGroup: View { rowQuantityTablet = 0 alignment = .center childWidth = nil + buttons = [] } open override func reset() { diff --git a/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift b/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift index 8a4d4a50..5b91acb7 100644 --- a/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift +++ b/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift @@ -106,14 +106,15 @@ open class CarouselScrollbar: View { /// A callback when the scrubber position changes. Passes parameters (position). open var onScrubberDrag: ((Int) -> Void)? { - get { nil } - set { + didSet { onScrubberDragCancellable?.cancel() - if let newValue { + if let onScrubberDrag { onScrubberDragCancellable = onScrubberDragPublisher .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). open var onMoveForward: ((Int) -> Void)? { - get { nil } - set { + didSet { onMoveForwardCancellable?.cancel() - if let newValue { + if let onMoveForward { onMoveForwardCancellable = onMoveForwardPublisher .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). open var onMoveBackward: ((Int) -> Void)? { - get { nil } - set { + didSet { onMoveBackwardCancellable?.cancel() - if let newValue { + if let onMoveBackward { onMoveBackwardCancellable = onMoveBackwardPublisher .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). open var onThumbTouchStart: ((Int) -> Void)? { - get { nil } - set { + didSet { onThumbTouchStartCancellable?.cancel() - if let newValue { + if let onThumbTouchStart { onThumbTouchStartCancellable = onThumbTouchStartPublisher .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). open var onThumbTouchEnd: ((Int) -> Void)? { - get { nil } - set { + didSet { onThumbTouchEndCancellable?.cancel() - if let newValue { + if let onThumbTouchEnd { onThumbTouchEndCancellable = onThumbTouchEndPublisher .sink { c in - newValue(c) + onThumbTouchEnd(c) } + } else { + onThumbTouchEndCancellable = nil } } } @@ -294,6 +299,19 @@ open class CarouselScrollbar: View { 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() { super.updateView() trackView.backgroundColor = trackColorConfiguration.getColor(surface) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 5b2afdc5..f1c99691 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -62,6 +62,11 @@ open class Checkbox: SelectorBase { 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. open override func toggle() { guard isEnabled else { return } diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 1431d9dc..226083fe 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -87,6 +87,12 @@ open class CheckboxGroup: SelectorGroupBase, SelectorGroupMultiSel mainStackView.spacing = VDSLayout.space6X } + open override func setDefaults() { + super.setDefaults() + showError = false + inputId = nil + } + public override func didSelect(_ selectedControl: CheckboxItem) { selectedControl.toggle() if selectedControl.isSelected, showError{ diff --git a/VDS/Components/Checkbox/CheckboxItem.swift b/VDS/Components/Checkbox/CheckboxItem.swift index c115fe79..d3af344b 100644 --- a/VDS/Components/Checkbox/CheckboxItem.swift +++ b/VDS/Components/Checkbox/CheckboxItem.swift @@ -55,6 +55,11 @@ open class CheckboxItem: SelectorItemBase { 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. open override func updateView() { diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index 794fe808..2c243a26 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -82,24 +82,15 @@ open class DropdownSelect: EntryFieldBase { open var inlineDisplayLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .horizontal) - $0.textAlignment = .left - $0.textStyle = .boldBodyLarge - $0.numberOfLines = 1 - $0.sizeToFit() } open var selectedOptionLabel = Label().with { $0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .horizontal) - $0.textAlignment = .left - $0.textStyle = .bodyLarge - $0.numberOfLines = 1 } open var dropdownField = UITextField().with { $0.translatesAutoresizingMaskIntoConstraints = false - $0.tintColor = UIColor.clear - $0.font = TextStyle.bodyLarge.font } open var optionsPicker = UIPickerView() @@ -163,13 +154,25 @@ open class DropdownSelect: EntryFieldBase { super.setDefaults() showInlineLabel = false selectId = nil + inlineDisplayLabel.textAlignment = .left inlineDisplayLabel.textStyle = .boldBodyLarge + inlineDisplayLabel.numberOfLines = 1 + selectedOptionLabel.textAlignment = .left selectedOptionLabel.textStyle = .bodyLarge + selectedOptionLabel.numberOfLines = 1 + dropdownField.tintColor = UIColor.clear + dropdownField.font = TextStyle.bodyLarge.font showInlineLabel = false options = [] selectId = nil } + open override func reset() { + inlineDisplayLabel.reset() + selectedOptionLabel.reset() + super.reset() + } + open override func getFieldContainer() -> UIView { let controlStackView = UIStackView().with { $0.translatesAutoresizingMaskIntoConstraints = false From 67bdcf51040d1c1dab6656d60e86a8d6afc3b245 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 15 Aug 2024 14:41:36 -0500 Subject: [PATCH 3/8] more updaets for setDefaults Signed-off-by: Matt Bruce --- VDS/Components/Pagination/Pagination.swift | 4 ++-- VDS/Components/TitleLockup/TitleLockup.swift | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Pagination/Pagination.swift b/VDS/Components/Pagination/Pagination.swift index 6234e155..1e51f4ef 100644 --- a/VDS/Components/Pagination/Pagination.swift +++ b/VDS/Components/Pagination/Pagination.swift @@ -57,7 +57,7 @@ open class Pagination: View { ///Next button to select next page public let nextButton: PaginationButton = .init(type: .next) /// 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. @Clamping(range: 0...9999) 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. - public var selectedPage: Int { + open var selectedPage: Int { set { if newValue >= total { _selectedPageIndex = total - 1 diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 25aaf248..1711939c 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -288,7 +288,6 @@ open class TitleLockup: View { subTitleModel = nil } - var labelViews = [UIView]() /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() From aae72b435b132425d15bb14bceca7a9f17b2ed53 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 15 Aug 2024 15:48:29 -0500 Subject: [PATCH 4/8] updated notes Signed-off-by: Matt Bruce --- VDS/SupportingFiles/ReleaseNotes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/VDS/SupportingFiles/ReleaseNotes.txt b/VDS/SupportingFiles/ReleaseNotes.txt index 80d0131b..ec14a5f7 100644 --- a/VDS/SupportingFiles/ReleaseNotes.txt +++ b/VDS/SupportingFiles/ReleaseNotes.txt @@ -1,6 +1,7 @@ 1.0.72 ---------------- - ONEAPP-9311 - InputStepper - Finished +- ONEAPP-9314 - PriceLockup - Finished - CXTDT-599736 - All classes refactored workflow setup(), reset(), setDefaults() 1.0.71 From 5a255aac52ce5a80f7031fab03bb6526d539cb88 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 16 Aug 2024 15:18:33 -0500 Subject: [PATCH 5/8] refactored for bugs in missing buttons for 2 rowCount Signed-off-by: Matt Bruce --- .../ButtonGroupPositionLayout.swift | 81 +++++++++---------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 5d3a339f..8c71ac4e 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -49,52 +49,45 @@ class ButtonCollectionViewRow { func layout(for position: ButtonGroup.Alignment, with collectionViewWidth: CGFloat){ var offset = 0.0 let height = rowHeight + let buttonAttributes = attributes.filter{$0.isButton} + attributes.last?.spacing = 0 + ///Calculate the available space in the row + let totalSpacingBetweenAttributes = attributes.reduce(0.0) { $0 + $1.spacing } + let availableWidthAfterSpacing = collectionViewWidth - totalSpacingBetweenAttributes + let buttonCount = CGFloat(buttonAttributes.count) + + //see how much of the rows width is used for + //non-buttons that are BaseButton Subclasses that are not "Button" + let nonButtonSpace = attributes.filter { !$0.isButton }.reduce(0.0) { $0 + $1.frame.width + $1.spacing } + let maxButtonWidth = availableWidthAfterSpacing / buttonCount + + //getting available button space since textlinks need their space + let buttonsAvailableSpace = collectionViewWidth - nonButtonSpace + var buttonWidth = maxButtonWidth + var buttonCalculatedPercentage: CGFloat = 0.0 + let buttonEqualSpacing = buttonsAvailableSpace / buttonCount + + // test sizing + let testSize = buttonWidth * CGFloat(buttonAttributes.count) + //check to see if you have buttons and there is a percentage if let buttonPercentage, hasButtons, buttonPercentage > 0 { - - var usedSpace = 0.0 - //get the width for the buttons - for attribute in attributes { - if !attribute.isButton { - usedSpace += attribute.frame.width + buttonCalculatedPercentage = CGFloat(buttonPercentage / 100.0) + let buttonPercentageWidth = buttonCalculatedPercentage * buttonsAvailableSpace + buttonWidth = min(max(buttonPercentageWidth, Button.Size.large.minimumWidth), maxButtonWidth) + } + + //resize the buttonAttributes + if buttonWidth >= Button.Size.large.minimumWidth && !buttonAttributes.isEmpty { + if testSize <= buttonsAvailableSpace { + for attribute in buttonAttributes { + attribute.frame.size.width = buttonCalculatedPercentage.isZero ? min(attribute.frame.size.width, buttonWidth) : buttonWidth } - usedSpace += attribute.spacing - } - let buttonAvailableSpace = collectionViewWidth - usedSpace - let realPercentage = (buttonPercentage / 100) - let buttonWidth = realPercentage * buttonAvailableSpace -// print("buttonPercentage :\(realPercentage)") -// print("collectionView width:\(collectionViewWidth)") -// print("usedSpace width:\(usedSpace)") -// print("button available width:\(buttonAvailableSpace)") -// print("each button width:\(buttonWidth)\n") -// print("minimum widht:\(ButtonSize.large.minimumWidth)") - // test sizing - 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 { - if testSize <= buttonAvailableSpace { - for attribute in attributes { - if attribute.isButton { - attribute.frame.size.width = buttonWidth - } - } - } else { - let distributedSize = buttonAvailableSpace / buttonCount - for attribute in attributes { - if attribute.isButton { - attribute.frame.size.width = distributedSize - } - } + } else { + for attribute in buttonAttributes { + attribute.frame.size.width = buttonEqualSpacing } } } @@ -181,7 +174,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { var rows = [ButtonCollectionViewRow]() rows.append(ButtonCollectionViewRow()) - let collectionViewWidth = collectionView.frame.width + let collectionViewWidth = collectionView.horizontalPinnedWidth() ?? collectionView.frame.width for item in 0.. 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 // the width of the collection view content, put it in the next line @@ -318,3 +312,4 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { } } + From 7efc0096afddea6c949e7c6ce4ddc41ade2dd592 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 16 Aug 2024 15:25:26 -0500 Subject: [PATCH 6/8] refactored more code Signed-off-by: Matt Bruce --- .../ButtonGroupPositionLayout.swift | 80 ++++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 8c71ac4e..02a93556 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -49,49 +49,54 @@ class ButtonCollectionViewRow { func layout(for position: ButtonGroup.Alignment, with collectionViewWidth: CGFloat){ var offset = 0.0 let height = rowHeight + + 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} - attributes.last?.spacing = 0 - - ///Calculate the available space in the row - let totalSpacingBetweenAttributes = attributes.reduce(0.0) { $0 + $1.spacing } - let availableWidthAfterSpacing = collectionViewWidth - totalSpacingBetweenAttributes - let buttonCount = CGFloat(buttonAttributes.count) - - //see how much of the rows width is used for - //non-buttons that are BaseButton Subclasses that are not "Button" - let nonButtonSpace = attributes.filter { !$0.isButton }.reduce(0.0) { $0 + $1.frame.width + $1.spacing } - let maxButtonWidth = availableWidthAfterSpacing / buttonCount - - //getting available button space since textlinks need their space - let buttonsAvailableSpace = collectionViewWidth - nonButtonSpace - var buttonWidth = maxButtonWidth - var buttonCalculatedPercentage: CGFloat = 0.0 - let buttonEqualSpacing = buttonsAvailableSpace / buttonCount - - // test sizing - let testSize = buttonWidth * CGFloat(buttonAttributes.count) - - //check to see if you have buttons and there is a percentage - if let buttonPercentage, hasButtons, buttonPercentage > 0 { - buttonCalculatedPercentage = CGFloat(buttonPercentage / 100.0) - let buttonPercentageWidth = buttonCalculatedPercentage * buttonsAvailableSpace - buttonWidth = min(max(buttonPercentageWidth, Button.Size.large.minimumWidth), maxButtonWidth) - } - - //resize the buttonAttributes - if buttonWidth >= Button.Size.large.minimumWidth && !buttonAttributes.isEmpty { - if testSize <= buttonsAvailableSpace { - for attribute in buttonAttributes { - attribute.frame.size.width = buttonCalculatedPercentage.isZero ? min(attribute.frame.size.width, buttonWidth) : buttonWidth - } - } else { - for attribute in buttonAttributes { - attribute.frame.size.width = buttonEqualSpacing + if !buttonAttributes.isEmpty { + let buttonCount = CGFloat(buttonAttributes.count) + + ///Calculate the spaces between items in the row + let totalSpacingBetweenAttributes = attributes.reduce(0.0) { $0 + $1.spacing } + + //see how much of the rows width is used for + //non-buttons that are BaseButton Subclasses that are not "Button" + let nonButtonSpace = attributes.filter { !$0.isButton }.reduce(0.0) { $0 + $1.frame.width + $1.spacing } + + //getting available button space since textlinks need their space + let buttonsAvailableSpace = collectionViewWidth - nonButtonSpace - totalSpacingBetweenAttributes + var maxButtonWidth = buttonsAvailableSpace / buttonCount + var buttonCalculatedPercentage: CGFloat = 0.0 + let buttonEqualSpacing = buttonsAvailableSpace / buttonCount + + // test sizing + let testSize = maxButtonWidth * CGFloat(buttonAttributes.count) + + //check to see if you have buttons and there is a percentage + if let buttonPercentage, hasButtons, buttonPercentage > 0 { + buttonCalculatedPercentage = CGFloat(buttonPercentage / 100.0) + let buttonPercentageWidth = buttonCalculatedPercentage * buttonsAvailableSpace + maxButtonWidth = min(max(buttonPercentageWidth, Button.Size.large.minimumWidth), maxButtonWidth) + } + + //resize the buttonAttributes + if maxButtonWidth >= Button.Size.large.minimumWidth && !buttonAttributes.isEmpty { + if testSize <= buttonsAvailableSpace { + for attribute in buttonAttributes { + attribute.frame.size.width = buttonCalculatedPercentage.isZero ? min(attribute.frame.size.width, maxButtonWidth) : maxButtonWidth + } + } else { + for attribute in buttonAttributes { + attribute.frame.size.width = buttonEqualSpacing + } } } } + //update the offset based on position switch position { case .left: break @@ -313,3 +318,4 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { } + From 30a4b1e0f749f62671334d57fd1b706f042e537c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 16 Aug 2024 15:41:50 -0500 Subject: [PATCH 7/8] refactored more code Signed-off-by: Matt Bruce --- .../ButtonGroup/ButtonGroupPositionLayout.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 02a93556..00ff747c 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -68,13 +68,10 @@ class ButtonCollectionViewRow { //getting available button space since textlinks need their space let buttonsAvailableSpace = collectionViewWidth - nonButtonSpace - totalSpacingBetweenAttributes - var maxButtonWidth = buttonsAvailableSpace / buttonCount - var buttonCalculatedPercentage: CGFloat = 0.0 let buttonEqualSpacing = buttonsAvailableSpace / buttonCount - - // test sizing - let testSize = maxButtonWidth * CGFloat(buttonAttributes.count) - + var maxButtonWidth = buttonEqualSpacing //default to equal spacing + var buttonCalculatedPercentage: CGFloat = 0.0 + //check to see if you have buttons and there is a percentage if let buttonPercentage, hasButtons, buttonPercentage > 0 { buttonCalculatedPercentage = CGFloat(buttonPercentage / 100.0) @@ -83,12 +80,14 @@ class ButtonCollectionViewRow { } //resize the buttonAttributes - if maxButtonWidth >= Button.Size.large.minimumWidth && !buttonAttributes.isEmpty { - if testSize <= buttonsAvailableSpace { + if maxButtonWidth >= Button.Size.large.minimumWidth { + //if there is enough room for all buttons + if maxButtonWidth * buttonCount <= buttonsAvailableSpace { for attribute in buttonAttributes { attribute.frame.size.width = buttonCalculatedPercentage.isZero ? min(attribute.frame.size.width, maxButtonWidth) : maxButtonWidth } } else { + //if not enough room, give all buttons the same width for attribute in buttonAttributes { attribute.frame.size.width = buttonEqualSpacing } From dcc0307e9b3ae881a9990103cc0f470bfedf22e7 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 16 Aug 2024 15:56:48 -0500 Subject: [PATCH 8/8] fixed bug of adding space between 2 times Signed-off-by: Matt Bruce --- .../Buttons/ButtonGroup/ButtonGroupPositionLayout.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 00ff747c..433fa58f 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -64,7 +64,7 @@ class ButtonCollectionViewRow { //see how much of the rows width is used for //non-buttons that are BaseButton Subclasses that are not "Button" - let nonButtonSpace = attributes.filter { !$0.isButton }.reduce(0.0) { $0 + $1.frame.width + $1.spacing } + let nonButtonSpace = attributes.filter { !$0.isButton }.reduce(0.0) { $0 + $1.frame.width } //getting available button space since textlinks need their space let buttonsAvailableSpace = collectionViewWidth - nonButtonSpace - totalSpacingBetweenAttributes