From 4f79547bf8f947a0d8a3ef5329399111359c3a08 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Wed, 7 Feb 2024 20:14:43 +0530 Subject: [PATCH 01/12] Updated constraints for NotificationView for layout horizontal --- .../Notification/Notification.swift | 78 +++++++++++++------ 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/VDS/Components/Notification/Notification.swift b/VDS/Components/Notification/Notification.swift index 274ad8af..bd2f778c 100644 --- a/VDS/Components/Notification/Notification.swift +++ b/VDS/Components/Notification/Notification.swift @@ -69,17 +69,25 @@ open class Notification: View { } private var labelsView = UIStackView().with { + $0.spacing = 1.0 $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top + $0.alignment = .fill + $0.distribution = .equalSpacing $0.axis = .vertical } - private var labelButtonView = UIStackView().with { + private var labelButtonView = View().with { $0.translatesAutoresizingMaskIntoConstraints = false - $0.alignment = .top - $0.distribution = .fillEqually - $0.axis = .vertical - $0.spacing = VDSLayout.Spacing.space2X.value + } + + private var labelButtonViewSpacing: CGFloat { + let spacing: CGFloat = UIDevice.isIPad ? 20 : 16 + return switch layout { + case .vertical: + 0 + case .horizontal: + spacing + } } internal var onCloseSubscriber: AnyCancellable? @@ -215,6 +223,15 @@ open class Notification: View { return 1232 } + private var labelViewWidthConstraint: NSLayoutConstraint? + private var labelViewBottomConstraint: NSLayoutConstraint? + private var labelViewAndButtonViewConstraint: NSLayoutConstraint? + private var buttonViewTopConstraint: NSLayoutConstraint? + private var typeIconWidthConstraint: NSLayoutConstraint? + private var closeIconWidthConstraint: NSLayoutConstraint? + private var buttonGroupCenterYConstraint: NSLayoutConstraint? + private var buttonGroupBottomConstraint: NSLayoutConstraint? + //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- @@ -240,12 +257,29 @@ open class Notification: View { ]) maxWidthConstraint = layoutGuide.widthAnchor.constraint(lessThanOrEqualToConstant: maxViewWidth) - labelButtonView.addArrangedSubview(labelsView) - + labelButtonView.addSubview(labelsView) + labelsView + .pinTop() + .pinLeading() + labelViewWidthConstraint = labelsView.widthAnchor.constraint(equalTo: labelButtonView.widthAnchor, multiplier: 1.0) + labelViewWidthConstraint?.activate() + labelViewBottomConstraint = labelButtonView.bottomAnchor.constraint(equalTo: labelsView.bottomAnchor) + + labelButtonView.addSubview(buttonGroup) + buttonGroup + .pinTrailing() + buttonGroupBottomConstraint = labelButtonView.bottomAnchor.constraint(equalTo: buttonGroup.bottomAnchor) + buttonGroupCenterYConstraint = buttonGroup.centerYAnchor.constraint(equalTo: labelButtonView.centerYAnchor) + labelViewAndButtonViewConstraint = buttonGroup.topAnchor.constraint(equalTo: labelsView.bottomAnchor, constant: 3.0) + buttonGroup.widthAnchor.constraint(equalTo: labelsView.widthAnchor).activate() + mainStackView.addArrangedSubview(typeIcon) mainStackView.addArrangedSubview(labelButtonView) mainStackView.addArrangedSubview(closeButton) - + + typeIconWidthConstraint = typeIcon.width(constant: typeIcon.size.dimensions.width) + closeIconWidthConstraint = closeButton.width(constant: closeButton.size.dimensions.width) + //labels titleLabel.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() subTitleLabel.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() @@ -342,28 +376,28 @@ open class Notification: View { secondaryButton.onClick = secondaryButtonModel.onClick buttons.append(secondaryButton) } - + labelViewWidthConstraint?.deactivate() if buttons.isEmpty { - labelsView.setCustomSpacing(0, after: subTitleLabel) - buttonGroup.removeFromSuperview() + buttonGroup.isHidden = true + labelViewWidthConstraint = labelsView.widthAnchor.constraint(equalTo: labelButtonView.widthAnchor) + buttonGroup.buttons.removeAll() } else { labelsView.setCustomSpacing(VDSLayout.Spacing.space3X.value, after: subTitleLabel) - buttonGroup.buttons = buttons - labelButtonView.axis = layout == .vertical ? .vertical : .horizontal - labelButtonView.addArrangedSubview(buttonGroup) - - buttonGroup - .pinLeading() - .pinTrailing() + buttonGroup.isHidden = false + labelViewWidthConstraint = labelsView.widthAnchor.constraint(equalTo: labelButtonView.widthAnchor, multiplier: layout == .vertical ? 1.0 : 0.5, constant: layout == .vertical ? 0 : -labelButtonViewSpacing) } + labelViewWidthConstraint?.activate() } private func setConstraints() { - maxWidthConstraint?.constant = maxViewWidth maxWidthConstraint?.isActive = UIDevice.isIPad - + labelViewAndButtonViewConstraint?.isActive = layout == .vertical && !buttonGroup.buttons.isEmpty + typeIconWidthConstraint?.constant = typeIcon.size.dimensions.width + closeIconWidthConstraint?.constant = closeButton.size.dimensions.width + labelViewBottomConstraint?.isActive = layout == .horizontal || buttonGroup.buttons.isEmpty + buttonGroupCenterYConstraint?.isActive = layout == .horizontal + buttonGroupBottomConstraint?.isActive = layout == .vertical } } - From 3dc55db8eaab31eb967174938be422f44dc225bb Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 13 Feb 2024 22:18:03 +0530 Subject: [PATCH 02/12] added spacing constants --- VDS/Components/Notification/Notification.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Notification/Notification.swift b/VDS/Components/Notification/Notification.swift index bd2f778c..5caebaa7 100644 --- a/VDS/Components/Notification/Notification.swift +++ b/VDS/Components/Notification/Notification.swift @@ -65,7 +65,7 @@ open class Notification: View { $0.translatesAutoresizingMaskIntoConstraints = false $0.alignment = .top $0.axis = .horizontal - $0.spacing = VDSLayout.Spacing.space2X.value + $0.spacing = UIDevice.isIPad ? VDSLayout.Spacing.space3X.value : VDSLayout.Spacing.space2X.value } private var labelsView = UIStackView().with { @@ -270,7 +270,7 @@ open class Notification: View { .pinTrailing() buttonGroupBottomConstraint = labelButtonView.bottomAnchor.constraint(equalTo: buttonGroup.bottomAnchor) buttonGroupCenterYConstraint = buttonGroup.centerYAnchor.constraint(equalTo: labelButtonView.centerYAnchor) - labelViewAndButtonViewConstraint = buttonGroup.topAnchor.constraint(equalTo: labelsView.bottomAnchor, constant: 3.0) + labelViewAndButtonViewConstraint = buttonGroup.topAnchor.constraint(equalTo: labelsView.bottomAnchor, constant: VDSLayout.Spacing.space3X.value) buttonGroup.widthAnchor.constraint(equalTo: labelsView.widthAnchor).activate() mainStackView.addArrangedSubview(typeIcon) @@ -358,7 +358,6 @@ open class Notification: View { } else { subTitleLabel.removeFromSuperview() } - } private func updateButtons() { From 3b3d7eff600a3fdac7df72b70e49c2e632700259 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 13 Feb 2024 22:36:50 +0530 Subject: [PATCH 03/12] added Notification Type --- VDS/Components/Notification/Notification.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Notification/Notification.swift b/VDS/Components/Notification/Notification.swift index 5caebaa7..6e63a8aa 100644 --- a/VDS/Components/Notification/Notification.swift +++ b/VDS/Components/Notification/Notification.swift @@ -58,6 +58,11 @@ open class Notification: View { case vertical, horizontal } + /// Enum used to describe the type of the Notification. + public enum `Type`: String, CaseIterable { + case fullBleed, inLine + } + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- @@ -69,7 +74,7 @@ open class Notification: View { } private var labelsView = UIStackView().with { - $0.spacing = 1.0 + $0.spacing = VDSLayout.Spacing.space1X.value $0.translatesAutoresizingMaskIntoConstraints = false $0.alignment = .fill $0.distribution = .equalSpacing @@ -173,7 +178,10 @@ open class Notification: View { /// Add this attribute determine your type of Notification. open var style: Style = .info { didSet { setNeedsUpdate()}} - var _layout: Layout = .vertical + /// If true, will hide the close button. + open var type: Type = .inLine { didSet { setNeedsUpdate()} } + + private var _layout: Layout = .vertical /// Determines the orientation of buttons and text in the Notification. open var layout: Layout { @@ -323,6 +331,7 @@ open class Notification: View { open override func updateView() { super.updateView() + layer.cornerRadius = type == .fullBleed ? 0 : 4.0 backgroundColor = backgroundColorConfiguration.getColor(self) updateIcons() updateLabels() From e8a03cbea29a60473763692b9d6646f455720603 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 13 Feb 2024 22:41:59 +0530 Subject: [PATCH 04/12] Added change log --- VDS.xcodeproj/project.pbxproj | 4 ++ .../Notification/NotificationChangeLog.txt | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 VDS/Components/Notification/NotificationChangeLog.txt diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index c28da8f9..00ef0933 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 44604AD729CE196600E62B51 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD629CE196600E62B51 /* Line.swift */; }; 5F21D7BF28DCEB3D003E7CD6 /* Useable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */; }; 5FC35BE328D51405004EBEAC /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE228D51405004EBEAC /* Button.swift */; }; + 71C02B382B7BD98F00E93E66 /* NotificationChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 71C02B372B7BD98F00E93E66 /* NotificationChangeLog.txt */; }; EA0B18022A9E236900F2D0CD /* SelectorGroupBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0B18012A9E236900F2D0CD /* SelectorGroupBase.swift */; }; EA0B18052A9E2D2D00F2D0CD /* SelectorBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0B18032A9E2D2D00F2D0CD /* SelectorBase.swift */; }; EA0B18062A9E2D2D00F2D0CD /* SelectorItemBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0B18042A9E2D2D00F2D0CD /* SelectorItemBase.swift */; }; @@ -173,6 +174,7 @@ 44604AD629CE196600E62B51 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = ""; }; 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Useable.swift; sourceTree = ""; }; 5FC35BE228D51405004EBEAC /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = ""; }; + 71C02B372B7BD98F00E93E66 /* NotificationChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = NotificationChangeLog.txt; sourceTree = ""; }; EA0B18012A9E236900F2D0CD /* SelectorGroupBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectorGroupBase.swift; sourceTree = ""; }; EA0B18032A9E2D2D00F2D0CD /* SelectorBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectorBase.swift; sourceTree = ""; }; EA0B18042A9E2D2D00F2D0CD /* SelectorItemBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectorItemBase.swift; sourceTree = ""; }; @@ -347,6 +349,7 @@ children = ( 445BA07729C07B3D0036A7C5 /* Notification.swift */, 44604AD329CE186A00E62B51 /* NotificationButtonModel.swift */, + 71C02B372B7BD98F00E93E66 /* NotificationChangeLog.txt */, ); path = Notification; sourceTree = ""; @@ -928,6 +931,7 @@ files = ( EAEEECA42B1F934600531FC2 /* IconChangeLog.txt in Resources */, EA3362042891E14D0071C351 /* VerizonNHGeTX-Bold.otf in Resources */, + 71C02B382B7BD98F00E93E66 /* NotificationChangeLog.txt in Resources */, EAEEECA72B1F952000531FC2 /* TabsChangeLog.txt in Resources */, EAEEEC962B1F893B00531FC2 /* ButtonChangeLog.txt in Resources */, EA5F86CC2A1D28B500BC83E4 /* ReleaseNotes.txt in Resources */, diff --git a/VDS/Components/Notification/NotificationChangeLog.txt b/VDS/Components/Notification/NotificationChangeLog.txt new file mode 100644 index 00000000..e8026180 --- /dev/null +++ b/VDS/Components/Notification/NotificationChangeLog.txt @@ -0,0 +1,55 @@ +MM/DD/YYYY +---------------- + +12/30/2021 +---------------- +- Updated Hover and Active state trigger specs. If triggered by mouse, Active same as Hover. If not, Active same as Default. + +03/03/2022 +---------------- +- Initial Brand 3.0 handoff + +03/07/2022 +---------------- +- Added Native positioning examples + +05/03/2022 +---------------- +- Finalized Native Positioning and Triggers sections. + +07/28/2022 +---------------- +- Added note to Anatomy that Border radius is only for Inline Notifications. + +11/30/2022 +---------------- +- Added "(web only)" to any instance of "keyboard focus" + +12/13/2022 +---------------- +- Replaced focus border pixel and style & spacing values with tokens. + +01/12/2023 +---------------- +- Change VDS Button to Button in Anatomy
Moved Button combinations from Anatomy to Elements. + +04/12/2023 +---------------- +- Updated hex colors to reflect updated color tokens values. +- Updated visuals on the Native frame to reflect new guideline that the notification surface color should be based on whatever it is placed upon, or based on the color of the top navigation bar when displaying above the global nav. Added spec notation about this also. + +05/04/2023 +---------------- +- Button Icon Threading - CloseButton +- Anatomy section updated with info on Button Icon +- CloseButton updated with VDS Button Icon details +- Updated Viewport section with Button Icon Config +- Removed Elements section. Button combination is now part of Configurations section +- Updated visuals in all sections to cater to changes caused by Button Icon threading + +11/21/2023 +---------------- +- Added hideCloseButton property to align with React component build +- Added dev note to Error variant +- Removed close button from Error variant examples +- Removed Web/App Discrepancies list From 78a63cdc3ecb8e9a1cd2623a09399d93f3c724fd Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 13 Feb 2024 23:18:40 +0530 Subject: [PATCH 05/12] Added Publisher for layoutHeight to update collectionViewHeight dynamically --- VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 6 ++++++ .../Buttons/ButtonGroup/ButtonGroupPositionLayout.swift | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 1fdbc56d..296a5224 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -64,6 +64,8 @@ open class ButtonGroup: View { private var _childWidth: ChildWidth? + private var anyCancellable: AnyCancellable? + /// 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 } @@ -134,6 +136,10 @@ open class ButtonGroup: View { collectionView.pinToSuperView() collectionViewHeight = heightAnchor.constraint(equalToConstant: VDS.Button.Size.large.height) collectionViewHeight?.activate() + anyCancellable = positionLayout.$layoutHeight.receive(on: RunLoop.main).sink { [weak self] _ in + guard let self else { return } + self.collectionViewHeight?.constant = self.collectionView.intrinsicContentSize.height + } } //-------------------------------------------------- diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index c1a315eb..7c099a7c 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -149,7 +149,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { weak var delegate: ButtongGroupPositionLayoutDelegate? // Total height of the content. Will be used to configure the scrollview content - var layoutHeight: CGFloat = 0.0 + @Published var layoutHeight: CGFloat = 0.0 var position: ButtonGroup.Alignment = .left var rowQuantity: Int = 0 var buttonPercentage: CGFloat? From c98b103092dc1e25b158cbea84a8cf090270105d Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Wed, 14 Feb 2024 00:47:28 +0530 Subject: [PATCH 06/12] Added TODO --- VDS/Components/Notification/Notification.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/VDS/Components/Notification/Notification.swift b/VDS/Components/Notification/Notification.swift index 6e63a8aa..f24d2bd6 100644 --- a/VDS/Components/Notification/Notification.swift +++ b/VDS/Components/Notification/Notification.swift @@ -291,6 +291,8 @@ open class Notification: View { //labels titleLabel.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() subTitleLabel.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() + + //TODO: Need to add setup animation for displaying the Notification view for iOS. } /// Resets to default settings. From 83bead926fd7c1f5cfd3121bf62e58752904998f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 13 Feb 2024 16:45:17 -0600 Subject: [PATCH 07/12] fixed bug for ButtonGroupPositionLayout - take the min between collectionViewWidth and button width 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 7c099a7c..c87f8989 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -229,7 +229,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { // create the custom layout attribute let attributes = ButtonLayoutAttributes(spacing: itemSpacing, button: itemButtonBase, forCellWith: indexPath) - attributes.frame = CGRect(x: 0, y: 0, width: itemSize.width, height: itemSize.height) + attributes.frame = CGRect(x: 0, y: 0, width: min(itemSize.width, collectionViewWidth), height: itemSize.height) // add it to the array rows.last?.add(attribute: attributes) From ba33824576704b02c34116b1d3b906732bfe7c22 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 13 Feb 2024 16:45:17 -0600 Subject: [PATCH 08/12] fixed bug for ButtonGroupPositionLayout - take the min between collectionViewWidth and button width 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 c1a315eb..040ac1b3 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -229,7 +229,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { // create the custom layout attribute let attributes = ButtonLayoutAttributes(spacing: itemSpacing, button: itemButtonBase, forCellWith: indexPath) - attributes.frame = CGRect(x: 0, y: 0, width: itemSize.width, height: itemSize.height) + attributes.frame = CGRect(x: 0, y: 0, width: min(itemSize.width, collectionViewWidth), height: itemSize.height) // add it to the array rows.last?.add(attribute: attributes) From 0aea28663099d94f2cb1d0f6af7c1ae2751ff8e2 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 14 Feb 2024 09:05:41 -0600 Subject: [PATCH 09/12] pushing the heightConstraint into the selfsizingcv Signed-off-by: Matt Bruce --- VDS/Classes/SelfSizingCollectionView.swift | 8 ++++++++ VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/VDS/Classes/SelfSizingCollectionView.swift b/VDS/Classes/SelfSizingCollectionView.swift index 3a99404a..c50082c4 100644 --- a/VDS/Classes/SelfSizingCollectionView.swift +++ b/VDS/Classes/SelfSizingCollectionView.swift @@ -7,6 +7,7 @@ import Foundation import UIKit +import Combine /// UICollectionView subclassed to deal with Changing the size of itself based on its children and layout and changes of its contentSize. @objc(VDSSelfSizingCollectionView) @@ -34,10 +35,13 @@ public final class SelfSizingCollectionView: UICollectionView { // MARK: - Private Properties //-------------------------------------------------- private var contentSizeObservation: NSKeyValueObservation? + private var collectionViewHeight: NSLayoutConstraint? + private var anyCancellable: AnyCancellable? //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- + /// The natural size for the receiving view, considering only properties of the view itself. public override var intrinsicContentSize: CGSize { let contentSize = self.contentSize @@ -63,12 +67,16 @@ public final class SelfSizingCollectionView: UICollectionView { //ensure autoLayout uses intrinsic height setContentHuggingPriority(.required, for: .vertical) setContentCompressionResistancePriority(.required, for: .vertical) + collectionViewHeight = heightAnchor.constraint(equalToConstant: 0).activate() // Observing the value of contentSize seems to be the only reliable way to get the contentSize after the collection view lays out its subviews. self.contentSizeObservation = self.observe(\.contentSize, options: [.old, .new]) { [weak self] _, change in // If we don't specify `options: [.old, .new]`, the change.oldValue and .newValue will always be `nil`. if change.newValue != change.oldValue { self?.invalidateIntrinsicContentSize() + if let height = change.newValue?.height { + self?.collectionViewHeight?.constant = height + } } } } diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 113d19f5..a80594fc 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -103,7 +103,6 @@ open class ButtonGroup: View { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - fileprivate var collectionViewHeight: NSLayoutConstraint? fileprivate lazy var positionLayout = ButtonGroupPositionLayout().with { $0.position = .center @@ -132,8 +131,6 @@ open class ButtonGroup: View { super.setup() addSubview(collectionView) collectionView.pinToSuperView() - collectionViewHeight = heightAnchor.constraint(equalToConstant: VDS.Button.Size.large.height) - collectionViewHeight?.activate() } //-------------------------------------------------- @@ -184,7 +181,6 @@ open class ButtonGroup: View { DispatchQueue.main.async { [weak self] in guard let self else { return } self.collectionView.collectionViewLayout.invalidateLayout() - self.collectionViewHeight?.constant = self.collectionView.intrinsicContentSize.height } } } From e9df7018363f38d57ce2f187b33a729c7282841a Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 14 Feb 2024 09:32:14 -0600 Subject: [PATCH 10/12] fixed other issue with button group layout Signed-off-by: Matt Bruce --- .../Buttons/ButtonGroup/ButtonGroupPositionLayout.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index 040ac1b3..353bd4f5 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -193,6 +193,9 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { // get the rect size of the button itemSize = delegate.collectionView(collectionView, sizeForItemAtIndexPath: indexPath) + // ensure the width is not greater than the collectionViewWidth + itemSize.width = min(itemSize.width, collectionViewWidth) + // determine if the current button will fit in the row let rowItemCount = rows.last?.attributes.count ?? 0 @@ -229,7 +232,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { // create the custom layout attribute let attributes = ButtonLayoutAttributes(spacing: itemSpacing, button: itemButtonBase, forCellWith: indexPath) - attributes.frame = CGRect(x: 0, y: 0, width: min(itemSize.width, collectionViewWidth), height: itemSize.height) + attributes.frame = CGRect(x: 0, y: 0, width: itemSize.width, height: itemSize.height) // add it to the array rows.last?.add(attribute: attributes) From 3b6e8948bb3bb51377e5031ab14bb30c03020c59 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 14 Feb 2024 09:46:23 -0600 Subject: [PATCH 11/12] removed @PUblished, since this is no longer needed Signed-off-by: Matt Bruce --- .../Buttons/ButtonGroup/ButtonGroupPositionLayout.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift index ba0cec7c..f4ccf276 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroupPositionLayout.swift @@ -8,7 +8,6 @@ import Foundation import UIKit - class ButtonCollectionViewRow { var attributes = [ButtonLayoutAttributes]() @@ -149,7 +148,7 @@ class ButtonGroupPositionLayout: UICollectionViewLayout { weak var delegate: ButtongGroupPositionLayoutDelegate? // Total height of the content. Will be used to configure the scrollview content - @Published var layoutHeight: CGFloat = 0.0 + var layoutHeight: CGFloat = 0.0 var position: ButtonGroup.Alignment = .left var rowQuantity: Int = 0 var buttonPercentage: CGFloat? From e15a4321b33da841020910db0239b1f305754799 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 14 Feb 2024 10:48:44 -0600 Subject: [PATCH 12/12] removed Type/type added layoutSubViews to deal with cornerRadius logic. Signed-off-by: Matt Bruce --- VDS/Components/Notification/Notification.swift | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/VDS/Components/Notification/Notification.swift b/VDS/Components/Notification/Notification.swift index f24d2bd6..2ed84116 100644 --- a/VDS/Components/Notification/Notification.swift +++ b/VDS/Components/Notification/Notification.swift @@ -58,11 +58,6 @@ open class Notification: View { case vertical, horizontal } - /// Enum used to describe the type of the Notification. - public enum `Type`: String, CaseIterable { - case fullBleed, inLine - } - //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- @@ -177,9 +172,6 @@ open class Notification: View { /// Add this attribute determine your type of Notification. open var style: Style = .info { didSet { setNeedsUpdate()}} - - /// If true, will hide the close button. - open var type: Type = .inLine { didSet { setNeedsUpdate()} } private var _layout: Layout = .vertical @@ -333,7 +325,6 @@ open class Notification: View { open override func updateView() { super.updateView() - layer.cornerRadius = type == .fullBleed ? 0 : 4.0 backgroundColor = backgroundColorConfiguration.getColor(self) updateIcons() updateLabels() @@ -341,6 +332,12 @@ open class Notification: View { setConstraints() } + /// Override to check the screen width to determine cornerRadius + open override func layoutSubviews() { + super.layoutSubviews() + layer.cornerRadius = UIScreen.main.bounds.width == bounds.width ? 0 : 4.0 + } + //-------------------------------------------------- // MARK: - Private Methods //--------------------------------------------------