From 592d2c1f1f0ee5d99aeffc26c716cdc2b73f360c Mon Sep 17 00:00:00 2001 From: Vasavi Kanamarlapudi Date: Wed, 21 Aug 2024 13:39:35 +0530 Subject: [PATCH 1/4] Digital ACT-191 CXTDT-603719 defect: Added fix for pagination caret icon --- VDS/Components/Carousel/Carousel.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Carousel/Carousel.swift b/VDS/Components/Carousel/Carousel.swift index 9e14d3d3..e1f32532 100644 --- a/VDS/Components/Carousel/Carousel.swift +++ b/VDS/Components/Carousel/Carousel.swift @@ -162,19 +162,19 @@ open class Carousel: View { /// Previous button to show previous slide. private var previousButton = ButtonIcon().with { $0.kind = .lowContrast - $0.iconName = .leftCaret + $0.iconName = .paginationLeftCaret $0.iconOffset = .init(x: -2, y: 0) $0.customContainerSize = UIDevice.isIPad ? 40 : 28 - $0.icon.customSize = UIDevice.isIPad ? 16 : 12 + $0.customIconSize = UIDevice.isIPad ? 16 : 12 } /// Next button to show next slide. private var nextButton = ButtonIcon().with { $0.kind = .lowContrast - $0.iconName = .rightCaret + $0.iconName = .paginationRightCaret $0.iconOffset = .init(x: 2, y: 0) $0.customContainerSize = UIDevice.isIPad ? 40 : 28 - $0.icon.customSize = UIDevice.isIPad ? 16 : 12 + $0.customIconSize = UIDevice.isIPad ? 16 : 12 } /// A publisher for when moving the carousel. Passes parameters selectedGroupIndex (position). From 030ebdf897cec630bebcae3ea25d53ce8c4b22f2 Mon Sep 17 00:00:00 2001 From: Vasavi Kanamarlapudi Date: Wed, 21 Aug 2024 13:42:48 +0530 Subject: [PATCH 2/4] added release note --- VDS/SupportingFiles/ReleaseNotes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/VDS/SupportingFiles/ReleaseNotes.txt b/VDS/SupportingFiles/ReleaseNotes.txt index c201359e..6d5b4db6 100644 --- a/VDS/SupportingFiles/ReleaseNotes.txt +++ b/VDS/SupportingFiles/ReleaseNotes.txt @@ -3,6 +3,7 @@ - CXTDT-597984 - Table - Text wrap - CXTDT-586372 - Table - Stripes defect - CXTDT-586383 - Table - Line style +- CXTDT-603719 - Carousel - Pagination caret icon 1.0.72 ---------------- From aa013f62e3657e6135a73638759cfd686adf182a Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 26 Aug 2024 09:03:17 -0500 Subject: [PATCH 3/4] added equatable to structs Signed-off-by: Matt Bruce --- .../Breadcrumbs/BreadcrumbItemModel.swift | 8 ++++++-- .../Calendar/CalendarIndicatorModel.swift | 2 +- .../Carousel/CarouselPaginationModel.swift | 2 +- .../Carousel/CarouselSlotAlignmentModel.swift | 2 +- VDS/Components/Checkbox/CheckboxGroup.swift | 19 +++++++++++++++++-- .../DatePicker/DatePickerCalendarModel.swift | 2 +- .../DropdownSelect/DropdownOptionModel.swift | 2 +- .../ButtonIconBadgeIndicatorModel.swift | 2 +- VDS/Components/Icon/IconName.swift | 2 +- .../NotificationButtonModel.swift | 6 +++++- VDS/Components/RadioBox/RadioBoxGroup.swift | 19 ++++++++++++++++++- .../RadioButton/RadioButtonGroup.swift | 17 ++++++++++++++++- VDS/Components/Table/TableItemModel.swift | 2 +- VDS/Components/Table/TableRowModel.swift | 2 +- VDS/Components/Tabs/TabModel.swift | 7 ++++++- .../TileContainer/TileContainer.swift | 17 ++++++++++++++++- .../Tilelet/TileletBadgeModel.swift | 2 +- .../Tilelet/TileletIconModels.swift | 4 ++-- .../Tilelet/TileletSubTitleModel.swift | 10 +++++++++- .../Tilelet/TileletTitleModel.swift | 11 ++++++++++- .../Tilelet/TiletEyebrowModel.swift | 11 ++++++++++- .../TitleLockup/TitleLockupEyebrowModel.swift | 11 ++++++++++- .../TitleLockupSubTitleModel.swift | 8 ++++++++ .../TitleLockup/TitleLockupTitleModel.swift | 11 ++++++++++- VDS/Components/Tooltip/TooltipModel.swift | 2 +- 25 files changed, 154 insertions(+), 27 deletions(-) diff --git a/VDS/Components/Breadcrumbs/BreadcrumbItemModel.swift b/VDS/Components/Breadcrumbs/BreadcrumbItemModel.swift index 2c73f24f..be4419cc 100644 --- a/VDS/Components/Breadcrumbs/BreadcrumbItemModel.swift +++ b/VDS/Components/Breadcrumbs/BreadcrumbItemModel.swift @@ -8,8 +8,7 @@ import Foundation extension Breadcrumbs { - public struct BreadcrumbItemModel { - + public struct BreadcrumbItemModel: Equatable { ///Text that goes in the breadcrumb item public var text: String @@ -24,5 +23,10 @@ extension Breadcrumbs { self.selected = selected self.onClick = onClick } + + public static func == (lhs: Breadcrumbs.BreadcrumbItemModel, rhs: Breadcrumbs.BreadcrumbItemModel) -> Bool { + lhs.text == rhs.text + && lhs.selected == rhs.selected + } } } diff --git a/VDS/Components/Calendar/CalendarIndicatorModel.swift b/VDS/Components/Calendar/CalendarIndicatorModel.swift index 04ad9714..185af749 100644 --- a/VDS/Components/Calendar/CalendarIndicatorModel.swift +++ b/VDS/Components/Calendar/CalendarIndicatorModel.swift @@ -9,7 +9,7 @@ import Foundation /// Custom data type for indicators prop extension CalendarBase { - public struct CalendarIndicatorModel { + public struct CalendarIndicatorModel: Equatable { /// Text that shown to an indicator for legend public var label: String diff --git a/VDS/Components/Carousel/CarouselPaginationModel.swift b/VDS/Components/Carousel/CarouselPaginationModel.swift index ab85d6a4..67ba5052 100644 --- a/VDS/Components/Carousel/CarouselPaginationModel.swift +++ b/VDS/Components/Carousel/CarouselPaginationModel.swift @@ -10,7 +10,7 @@ import UIKit /// Custom data type for pagination prop for 'Carousel' component. extension Carousel { - public struct CarouselPaginationModel { + public struct CarouselPaginationModel: Equatable { /// Pagination supports Button icon property 'kind'. public var kind: ButtonIcon.Kind diff --git a/VDS/Components/Carousel/CarouselSlotAlignmentModel.swift b/VDS/Components/Carousel/CarouselSlotAlignmentModel.swift index ee1d491b..9774baa2 100644 --- a/VDS/Components/Carousel/CarouselSlotAlignmentModel.swift +++ b/VDS/Components/Carousel/CarouselSlotAlignmentModel.swift @@ -11,7 +11,7 @@ import Foundation extension Carousel { /// Used only when slot content have different heights or widths. - public struct CarouselSlotAlignmentModel { + public struct CarouselSlotAlignmentModel: Equatable { /// Used for vertical alignment of slot alignment. public var vertical: Carousel.Vertical diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index f2a62efa..9967bcd0 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -108,8 +108,8 @@ open class CheckboxGroup: SelectorGroupBase, SelectorGroupMultiSel } extension CheckboxGroup { - public struct CheckboxItemModel : Surfaceable, Initable, Errorable { - + public struct CheckboxItemModel : Surfaceable, Initable, Errorable, Equatable { + /// Whether this object is enabled or not public var enabled: Bool /// Current Surface and this is used to pass down to child objects that implement Surfacable @@ -146,6 +146,21 @@ extension CheckboxGroup { public init() { self.init(enabled: true) } + + public static func == (lhs: CheckboxGroup.CheckboxItemModel, rhs: CheckboxGroup.CheckboxItemModel) -> Bool { + lhs.enabled == rhs.enabled + && lhs.surface == rhs.surface + && lhs.inputId == rhs.inputId + && lhs.value == rhs.value + && lhs.accessibileText == rhs.accessibileText + && lhs.labelText == rhs.labelText + && lhs.labelTextAttributes == rhs.labelTextAttributes + && lhs.childText == rhs.childText + && lhs.childTextAttributes == rhs.childTextAttributes + && lhs.selected == rhs.selected + && lhs.showError == rhs.showError + && lhs.errorText == rhs.errorText + } } } diff --git a/VDS/Components/DatePicker/DatePickerCalendarModel.swift b/VDS/Components/DatePicker/DatePickerCalendarModel.swift index da18ab2f..84a392ad 100644 --- a/VDS/Components/DatePicker/DatePickerCalendarModel.swift +++ b/VDS/Components/DatePicker/DatePickerCalendarModel.swift @@ -9,7 +9,7 @@ import Foundation import UIKit extension DatePicker { - public struct CalendarModel { + public struct CalendarModel: Equatable { /// If set to true, the calendar will not have a border. public let hideContainerBorder: Bool diff --git a/VDS/Components/DropdownSelect/DropdownOptionModel.swift b/VDS/Components/DropdownSelect/DropdownOptionModel.swift index c82519eb..76ac8f5d 100644 --- a/VDS/Components/DropdownSelect/DropdownOptionModel.swift +++ b/VDS/Components/DropdownSelect/DropdownOptionModel.swift @@ -8,7 +8,7 @@ import Foundation extension DropdownSelect { - public struct DropdownOptionModel { + public struct DropdownOptionModel: Equatable { /// Text that goes as option to DropdownSelect public var text: String diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIconBadgeIndicatorModel.swift b/VDS/Components/Icon/ButtonIcon/ButtonIconBadgeIndicatorModel.swift index 28d731b0..f683ebf4 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIconBadgeIndicatorModel.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIconBadgeIndicatorModel.swift @@ -10,7 +10,7 @@ import Foundation extension ButtonIcon { //Model that represents the options available for the Badge Indicator - public struct BadgeIndicatorModel { + public struct BadgeIndicatorModel: Equatable { /// Enum used to describe the badge indicator direction of icon button determining the expand direction. public enum ExpandDirection: String, CaseIterable { case right, center, left diff --git a/VDS/Components/Icon/IconName.swift b/VDS/Components/Icon/IconName.swift index c3943d64..a6e951df 100644 --- a/VDS/Components/Icon/IconName.swift +++ b/VDS/Components/Icon/IconName.swift @@ -24,7 +24,7 @@ extension Icon { /// let icon = Icon() /// icon.name = .foo /// ``` - public struct Name: RawRepresentable { + public struct Name: RawRepresentable, Equatable { public typealias RawValue = String public var rawValue: String diff --git a/VDS/Components/Notification/NotificationButtonModel.swift b/VDS/Components/Notification/NotificationButtonModel.swift index 6876aa7c..c714dbd7 100644 --- a/VDS/Components/Notification/NotificationButtonModel.swift +++ b/VDS/Components/Notification/NotificationButtonModel.swift @@ -8,12 +8,16 @@ import Foundation extension Notification { - public struct ButtonModel { + public struct ButtonModel: Equatable { public var text: String public var onClick: (Button) -> () public init(text: String, onClick: @escaping (Button) -> Void) { self.text = text self.onClick = onClick } + + public static func == (lhs: Notification.ButtonModel, rhs: Notification.ButtonModel) -> Bool { + lhs.text == rhs.text + } } } diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 3b17d7d8..484b213f 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -113,7 +113,7 @@ open class RadioBoxGroup: SelectorGroupBase, SelectorGroupSingleSe } extension RadioBoxGroup { - public struct RadioBoxItemModel: Surfaceable, Initable, FormFieldable { + public struct RadioBoxItemModel: Surfaceable, Initable, FormFieldable, Equatable { /// Whether this object is enabled or not public var enabled: Bool /// Current Surface and this is used to pass down to child objects that implement Surfacable @@ -158,5 +158,22 @@ extension RadioBoxGroup { public init() { self.init(enabled: true) } + + public static func == (lhs: RadioBoxGroup.RadioBoxItemModel, rhs: RadioBoxGroup.RadioBoxItemModel) -> Bool { + lhs.enabled == rhs.enabled + && lhs.surface == rhs.surface + && lhs.inputId == rhs.inputId + && lhs.value == rhs.value + && lhs.accessibileText == rhs.accessibileText + && lhs.text == rhs.text + && lhs.textAttributes == rhs.textAttributes + && lhs.subText == rhs.subText + && lhs.subTextAttributes == rhs.subTextAttributes + && lhs.subTextRight == rhs.subTextRight + && lhs.subTextRightAttributes == rhs.subTextRightAttributes + && lhs.selected == rhs.selected + && lhs.strikethrough == rhs.strikethrough + && lhs.strikethroughAccessibileText == rhs.strikethroughAccessibileText + } } } diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 8bde87de..bbd23209 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -103,7 +103,7 @@ open class RadioButtonGroup: SelectorGroupBase, SelectorGroupSi } extension RadioButtonGroup { - public struct RadioButtonItemModel: Surfaceable, Initable, FormFieldable, Errorable { + public struct RadioButtonItemModel: Surfaceable, Initable, FormFieldable, Errorable, Equatable { /// Whether this object is enabled or not public var enabled: Bool @@ -141,5 +141,20 @@ extension RadioButtonGroup { public init() { self.init(enabled: true) } + + public static func == (lhs: RadioButtonGroup.RadioButtonItemModel, rhs: RadioButtonGroup.RadioButtonItemModel) -> Bool { + lhs.enabled == rhs.enabled + && lhs.surface == rhs.surface + && lhs.inputId == rhs.inputId + && lhs.value == rhs.value + && lhs.accessibileText == rhs.accessibileText + && lhs.labelText == rhs.labelText + && lhs.labelTextAttributes == rhs.labelTextAttributes + && lhs.childText == rhs.childText + && lhs.childTextAttributes == rhs.childTextAttributes + && lhs.selected == rhs.selected + && lhs.showError == rhs.showError + && lhs.errorText == rhs.errorText + } } } diff --git a/VDS/Components/Table/TableItemModel.swift b/VDS/Components/Table/TableItemModel.swift index 47a8e3f2..4725ad73 100644 --- a/VDS/Components/Table/TableItemModel.swift +++ b/VDS/Components/Table/TableItemModel.swift @@ -10,7 +10,7 @@ import UIKit import VDSCoreTokens /// Model that represent the content of each cell of Table component -public struct TableItemModel { +public struct TableItemModel: Equatable { public let defaultHeight: CGFloat = 50.0 diff --git a/VDS/Components/Table/TableRowModel.swift b/VDS/Components/Table/TableRowModel.swift index 22f428ce..d9472372 100644 --- a/VDS/Components/Table/TableRowModel.swift +++ b/VDS/Components/Table/TableRowModel.swift @@ -7,7 +7,7 @@ import Foundation -public struct TableRowModel { +public struct TableRowModel: Equatable { public var columns: [TableItemModel] diff --git a/VDS/Components/Tabs/TabModel.swift b/VDS/Components/Tabs/TabModel.swift index 02f5bd43..959569a0 100644 --- a/VDS/Components/Tabs/TabModel.swift +++ b/VDS/Components/Tabs/TabModel.swift @@ -8,7 +8,7 @@ import Foundation extension Tabs { - public struct TabModel { + public struct TabModel: Equatable { ///Text that goes in the Tab public var text: String @@ -24,5 +24,10 @@ extension Tabs { self.onClick = onClick self.width = width } + + public static func == (lhs: Tabs.TabModel, rhs: Tabs.TabModel) -> Bool { + lhs.text == rhs.text + && lhs.width == rhs.width + } } } diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index 6c695112..c464d2b7 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -82,10 +82,25 @@ open class TileContainerBase: View where } /// Enum used to describe the background effect choices used for this component. - public enum BackgroundEffect { + public enum BackgroundEffect: Equatable { case transparency case gradient(UIColor, UIColor) case none + + public static func == (lhs: TileContainerBase.BackgroundEffect, rhs: TileContainerBase.BackgroundEffect) -> Bool { + lhs.description == lhs.description + } + + public var description: String { + switch self { + case .transparency: + "transparency" + case .gradient(let first, let second): + "gradient(\(first), \(second)" + case .none: + "none" + } + } } /// Enum used to describe the aspect ratios used for this component. diff --git a/VDS/Components/Tilelet/TileletBadgeModel.swift b/VDS/Components/Tilelet/TileletBadgeModel.swift index 9dbd03fe..90c523da 100644 --- a/VDS/Components/Tilelet/TileletBadgeModel.swift +++ b/VDS/Components/Tilelet/TileletBadgeModel.swift @@ -11,7 +11,7 @@ import UIKit extension Tilelet { /// Model that represents the options available for the badge. - public struct BadgeModel { + public struct BadgeModel: Equatable { /// Text that will be used for the badge. public var text: String = "" diff --git a/VDS/Components/Tilelet/TileletIconModels.swift b/VDS/Components/Tilelet/TileletIconModels.swift index 03b2d225..c30f0937 100644 --- a/VDS/Components/Tilelet/TileletIconModels.swift +++ b/VDS/Components/Tilelet/TileletIconModels.swift @@ -32,7 +32,7 @@ extension Tilelet { } /// Model that represents the options available for the descriptive icon. - public struct DescriptiveIcon { + public struct DescriptiveIcon: Equatable { /// A representation that will be used to render the icon with corresponding name. public var name: Icon.Name @@ -58,7 +58,7 @@ extension Tilelet { } /// Model that represents the options available for the directional icon. - public struct DirectionalIcon { + public struct DirectionalIcon: Equatable { public enum IconType: String, CaseIterable { case rightArrow case externalLink diff --git a/VDS/Components/Tilelet/TileletSubTitleModel.swift b/VDS/Components/Tilelet/TileletSubTitleModel.swift index 4c48cc3a..9850209c 100644 --- a/VDS/Components/Tilelet/TileletSubTitleModel.swift +++ b/VDS/Components/Tilelet/TileletSubTitleModel.swift @@ -10,7 +10,7 @@ import UIKit extension Tilelet { /// Model that represents the options available for the sub title label. - public struct SubTitleModel { + public struct SubTitleModel: Equatable { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- @@ -67,5 +67,13 @@ extension Tilelet { textAttributes: textAttributes, lineBreakMode: lineBreakMode) } + + public static func == (lhs: Tilelet.SubTitleModel, rhs: Tilelet.SubTitleModel) -> Bool { + lhs.text == rhs.text + && lhs.textColor == rhs.textColor + && lhs.otherStandardStyle == rhs.otherStandardStyle + && lhs.textAttributes == rhs.textAttributes + && lhs.lineBreakMode == rhs.lineBreakMode + } } } diff --git a/VDS/Components/Tilelet/TileletTitleModel.swift b/VDS/Components/Tilelet/TileletTitleModel.swift index b9bc7bbe..877463c6 100644 --- a/VDS/Components/Tilelet/TileletTitleModel.swift +++ b/VDS/Components/Tilelet/TileletTitleModel.swift @@ -10,7 +10,7 @@ import UIKit extension Tilelet { /// Model that represents the options available for the title label. - public struct TitleModel { + public struct TitleModel: Equatable { //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- @@ -75,5 +75,14 @@ extension Tilelet { standardStyle: standardStyle.value, lineBreakMode: lineBreakMode) } + + public static func == (lhs: Tilelet.TitleModel, rhs: Tilelet.TitleModel) -> Bool { + lhs.text == rhs.text + && lhs.textColor == rhs.textColor + && lhs.isBold == rhs.isBold + && lhs.textAttributes == rhs.textAttributes + && lhs.standardStyle == rhs.standardStyle + && lhs.lineBreakMode == rhs.lineBreakMode + } } } diff --git a/VDS/Components/Tilelet/TiletEyebrowModel.swift b/VDS/Components/Tilelet/TiletEyebrowModel.swift index 3d22ab74..3c771d56 100644 --- a/VDS/Components/Tilelet/TiletEyebrowModel.swift +++ b/VDS/Components/Tilelet/TiletEyebrowModel.swift @@ -11,7 +11,7 @@ import UIKit extension Tilelet { /// Model that represents the options available for the eyebrow label. - public struct EyebrowModel { + public struct EyebrowModel: Equatable { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- @@ -60,5 +60,14 @@ extension Tilelet { standardStyle: standardStyle.value, textAttributes: textAttributes) } + + public static func == (lhs: Tilelet.EyebrowModel, rhs: Tilelet.EyebrowModel) -> Bool { + lhs.text == rhs.text + && lhs.textColor == rhs.textColor + && lhs.isBold == rhs.isBold + && lhs.textAttributes == rhs.textAttributes + && lhs.standardStyle == rhs.standardStyle + && lhs.lineBreakMode == rhs.lineBreakMode + } } } diff --git a/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift b/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift index 1139a6ee..d789205f 100644 --- a/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift +++ b/VDS/Components/TitleLockup/TitleLockupEyebrowModel.swift @@ -9,7 +9,7 @@ import Foundation extension TitleLockup { /// Model that represents the options available for the eyebrow label. - public struct EyebrowModel { + public struct EyebrowModel: Equatable { /// Text that will be used for the eyebrow label. public var text: String @@ -44,6 +44,15 @@ extension TitleLockup { /// Text style that will be used for the eyebrow label. public var textStyle: TextStyle { isBold ? standardStyle.value.bold : standardStyle.value.regular } + + public static func == (lhs: TitleLockup.EyebrowModel, rhs: TitleLockup.EyebrowModel) -> Bool { + lhs.text == rhs.text + && lhs.textColor == rhs.textColor + && lhs.isBold == rhs.isBold + && lhs.standardStyle == rhs.standardStyle + && lhs.textAttributes == rhs.textAttributes + && lhs.numberOfLines == rhs.numberOfLines + } } } diff --git a/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift b/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift index 7dcbfb85..fefb384e 100644 --- a/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift +++ b/VDS/Components/TitleLockup/TitleLockupSubTitleModel.swift @@ -46,6 +46,14 @@ extension TitleLockup { /// TextStyle used to render the text. public var textStyle: TextStyle { otherStandardStyle.value.regular } + public static func == (lhs: TitleLockup.SubTitleModel, rhs: TitleLockup.SubTitleModel) -> Bool { + lhs.text == rhs.text + && lhs.textColor == rhs.textColor + && lhs.otherStandardStyle == rhs.otherStandardStyle + && lhs.textAttributes == rhs.textAttributes + && lhs.lineBreakMode == rhs.lineBreakMode + && lhs.numberOfLines == rhs.numberOfLines + } } } diff --git a/VDS/Components/TitleLockup/TitleLockupTitleModel.swift b/VDS/Components/TitleLockup/TitleLockupTitleModel.swift index 2d7f7405..2dc431ed 100644 --- a/VDS/Components/TitleLockup/TitleLockupTitleModel.swift +++ b/VDS/Components/TitleLockup/TitleLockupTitleModel.swift @@ -10,7 +10,7 @@ import UIKit extension TitleLockup { /// Model that represents the options available for the sub title label. - public struct TitleModel { + public struct TitleModel: Equatable { /// Text that will be used for the title label. public var text: String @@ -51,5 +51,14 @@ extension TitleLockup { /// TextStyle used to render the text. public var textStyle: TextStyle { isBold ? standardStyle.value.bold : standardStyle.value.regular } + public static func == (lhs: TitleLockup.TitleModel, rhs: TitleLockup.TitleModel) -> Bool { + lhs.text == rhs.text + && lhs.textColor == rhs.textColor + && lhs.isBold == rhs.isBold + && lhs.standardStyle == rhs.standardStyle + && lhs.textAttributes == rhs.textAttributes + && lhs.numberOfLines == rhs.numberOfLines + && lhs.lineBreakMode == rhs.lineBreakMode + } } } diff --git a/VDS/Components/Tooltip/TooltipModel.swift b/VDS/Components/Tooltip/TooltipModel.swift index 461fda66..9c3e1576 100644 --- a/VDS/Components/Tooltip/TooltipModel.swift +++ b/VDS/Components/Tooltip/TooltipModel.swift @@ -11,7 +11,7 @@ import UIKit extension Tooltip { /// Model used to represent the tooltip. - public struct TooltipModel { + public struct TooltipModel: Equatable { /// Current Surface and this is used to pass down to child objects that implement Surfacable public var closeButtonText: String public var title: String? From 1f2637ed0408846fa7bddf1664a74471de341648 Mon Sep 17 00:00:00 2001 From: Vasavi Kanamarlapudi Date: Tue, 27 Aug 2024 11:54:41 +0530 Subject: [PATCH 4/4] refactoring Carousel to use a UICollectionView --- VDS.xcodeproj/project.pbxproj | 4 + VDS/Components/Carousel/Carousel.swift | 157 ++++++++---------- .../Carousel/CarouselSlotCell.swift | 90 ++++++++++ 3 files changed, 159 insertions(+), 92 deletions(-) create mode 100644 VDS/Components/Carousel/CarouselSlotCell.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index fc3417d2..10858c07 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 180636C92C29B0DF00C92D86 /* InputStepperLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 180636C82C29B0DF00C92D86 /* InputStepperLog.txt */; }; 1808BEBC2BA41C3200129230 /* CarouselScrollbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1808BEBB2BA41C3200129230 /* CarouselScrollbar.swift */; }; 1832AC572BA0791D008AE476 /* BreadcrumbCellItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1832AC562BA0791D008AE476 /* BreadcrumbCellItem.swift */; }; + 183B16F32C78CF7C00BA6A10 /* CarouselSlotCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 183B16F22C78CF7C00BA6A10 /* CarouselSlotCell.swift */; }; 184023452C61E7AD00A412C8 /* PriceLockup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 184023442C61E7AD00A412C8 /* PriceLockup.swift */; }; 184023472C61E7EC00A412C8 /* PriceLockupChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 184023462C61E7EC00A412C8 /* PriceLockupChangeLog.txt */; }; 1842B1DF2BECE28B0021AFCA /* CalendarDateViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1842B1DE2BECE28B0021AFCA /* CalendarDateViewCell.swift */; }; @@ -215,6 +216,7 @@ 1808BEBB2BA41C3200129230 /* CarouselScrollbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarouselScrollbar.swift; sourceTree = ""; }; 1808BEBF2BA456B700129230 /* CarouselScrollbarChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CarouselScrollbarChangeLog.txt; sourceTree = ""; }; 1832AC562BA0791D008AE476 /* BreadcrumbCellItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BreadcrumbCellItem.swift; sourceTree = ""; }; + 183B16F22C78CF7C00BA6A10 /* CarouselSlotCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarouselSlotCell.swift; sourceTree = ""; }; 184023442C61E7AD00A412C8 /* PriceLockup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceLockup.swift; sourceTree = ""; }; 184023462C61E7EC00A412C8 /* PriceLockupChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = PriceLockupChangeLog.txt; sourceTree = ""; }; 1842B1DE2BECE28B0021AFCA /* CalendarDateViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarDateViewCell.swift; sourceTree = ""; }; @@ -522,6 +524,7 @@ isa = PBXGroup; children = ( 18AE874F2C06FDA60075F181 /* Carousel.swift */, + 183B16F22C78CF7C00BA6A10 /* CarouselSlotCell.swift */, 18B9763E2C11BA4A009271DF /* CarouselPaginationModel.swift */, 18B42AC52C09D197008D6262 /* CarouselSlotAlignmentModel.swift */, 18AE87532C06FE610075F181 /* CarouselChangeLog.txt */, @@ -1396,6 +1399,7 @@ EA985BF02968A93600F2FF2E /* TitleLockupEyebrowModel.swift in Sources */, EA5E30532950DDA60082B959 /* TitleLockup.swift in Sources */, EAD062B02A3B873E0015965D /* BadgeIndicator.swift in Sources */, + 183B16F32C78CF7C00BA6A10 /* CarouselSlotCell.swift in Sources */, 44A952DD2BE3DA820009F874 /* TableFlowLayout.swift in Sources */, EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */, 18792A902B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift in Sources */, diff --git a/VDS/Components/Carousel/Carousel.swift b/VDS/Components/Carousel/Carousel.swift index 9e14d3d3..926df9f4 100644 --- a/VDS/Components/Carousel/Carousel.swift +++ b/VDS/Components/Carousel/Carousel.swift @@ -154,10 +154,21 @@ open class Carousel: View { $0.backgroundColor = .clear } - private var scrollView = UIScrollView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.backgroundColor = .clear - } + private lazy var collectionView: UICollectionView = { + let layout = UICollectionViewFlowLayout() + layout.scrollDirection = .horizontal + let collectionView = UICollectionView(frame: frame, collectionViewLayout: layout) + collectionView.isScrollEnabled = true + collectionView.translatesAutoresizingMaskIntoConstraints = false + collectionView.delegate = self + collectionView.dataSource = self + collectionView.showsHorizontalScrollIndicator = false + collectionView.showsVerticalScrollIndicator = false + collectionView.backgroundColor = .clear + collectionView.register(CarouselSlotCell.self, + forCellWithReuseIdentifier: CarouselSlotCell.identifier) + return collectionView + }() /// Previous button to show previous slide. private var previousButton = ButtonIcon().with { @@ -215,9 +226,9 @@ open class Carousel: View { containerView.addSubview(contentStackView) // Add scrollview - scrollContainerView.addSubview(scrollView) - scrollView.pinToSuperView() - + scrollContainerView.addSubview(collectionView) + collectionView.pinToSuperView() + // Add pagination button icons scrollContainerView.addSubview(previousButton) previousButton @@ -259,14 +270,24 @@ open class Carousel: View { /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() + updateScrollbar() + updateCarousel() + collectionView.reloadData() + } + //-------------------------------------------------- + // MARK: - Private Methods + //-------------------------------------------------- + private func updateScrollbar() { carouselScrollBar.numberOfSlides = views.count carouselScrollBar.layout = layout if (carouselScrollBar.position == 0 || carouselScrollBar.position > carouselScrollBar.numberOfSlides) { carouselScrollBar.position = 1 } carouselScrollBar.isHidden = (totalPositions() <= 1) ? true : false - + } + + private func updateCarousel() { // Mobile/Tablet layouts without peek - must show pagination controls. // If peek is ‘none’, pagination controls should show. So set to persistent. if peek == .none { @@ -284,12 +305,9 @@ open class Carousel: View { } updatePaginationControls() - addCarouselSlots() + updateContainerHeight() } - - //-------------------------------------------------- - // MARK: - Private Methods - //-------------------------------------------------- + private func addlisteners() { nextButton.onClick = { _ in self.nextButtonClick() } previousButton.onClick = { _ in self.previousButtonClick() } @@ -365,47 +383,13 @@ open class Carousel: View { return height } - // Add carousel slots and load data if any - private func addCarouselSlots() { + // update carousel size and load data if any + private func updateContainerHeight() { getSlotWidth() if containerView.frame.size.width > 0 { containerViewHeightConstraint?.isActive = false containerStackHeightConstraint?.isActive = false let slotHeight = fetchCarouselHeight() - - // Perform a loop to iterate each subView - scrollView.subviews.forEach { subView in - // Removing subView from its parent view - subView.removeFromSuperview() - } - - // Add carousel items - if views.count > 0 { - var xPos = 0.0 - for index in 0...views.count - 1 { - - // Add Carousel Slot - let carouselSlot = View().with { - $0.clipsToBounds = true - } - scrollView.addSubview(carouselSlot) - scrollView.delegate = self - - carouselSlot - .pinTop() - .pinBottom() - .pinLeading(xPos) - .width(minimumSlotWidth) - .height(slotHeight) - xPos = xPos + minimumSlotWidth + gutter.value - - let component = views[index] - carouselSlot.addSubview(component) - setSlotAlignment(contentView: component) - } - scrollView.contentSize = CGSize(width: xPos - gutter.value, height: slotHeight) - } - let containerHeight = slotHeight + scrollbarTopSpace + containerSize.height if carouselScrollBar.isHidden { containerStackHeightConstraint = contentStackView.heightAnchor.constraint(equalToConstant: slotHeight) @@ -419,43 +403,6 @@ open class Carousel: View { } } - // Set slot alignment if provided. Used only when slot content have different heights or widths. - private func setSlotAlignment(contentView: UIView) { - switch slotAlignment?.vertical { - case .top: - contentView - .pinTop() - .pinBottomLessThanOrEqualTo() - case .middle: - contentView - .pinTopGreaterThanOrEqualTo() - .pinBottomLessThanOrEqualTo() - .pinCenterY() - case .bottom: - contentView - .pinTopGreaterThanOrEqualTo() - .pinBottom() - default: break - } - - switch slotAlignment?.horizontal { - case .left: - contentView - .pinLeading() - .pinTrailingLessThanOrEqualTo() - case .center: - contentView - .pinLeadingGreaterThanOrEqualTo() - .pinTrailingLessThanOrEqualTo() - .pinCenterX() - case .right: - contentView - .pinLeadingGreaterThanOrEqualTo() - .pinTrailing() - default: break - } - } - // Get the slot width relative to the peak private func getSlotWidth() { let actualWidth = containerView.frame.size.width @@ -505,7 +452,7 @@ open class Carousel: View { } private func updateScrollbarPosition(targetContentOffsetXPos:CGFloat) { - let scrollContentSizeWidth = scrollView.contentSize.width + let scrollContentSizeWidth = collectionView.contentSize.width let totalPositions = totalPositions() let layoutSpace = Int (floor( Double(scrollContentSizeWidth / Double(totalPositions)))) let remindSpace = Int(targetContentOffsetXPos) % layoutSpace @@ -515,10 +462,11 @@ open class Carousel: View { updateScrollPosition(position: contentPos, callbackText: "ScrollViewMoved") } - // Update scrollview offset relative to scrollbar thumb position + // Update collectionview offset relative to scrollbar thumb position private func updateScrollPosition(position: Int, callbackText: String) { if carouselScrollBar.numberOfSlides > 0 { - let scrollContentSizeWidth = scrollView.contentSize.width + let scrollContentSizeWidth = collectionView.contentSize.width + let totalPositions = totalPositions() var xPos = 0.0 if position == 1 { @@ -536,8 +484,8 @@ open class Carousel: View { } } carouselScrollBar.scrubberId = position+1 - let yPos = scrollView.contentOffset.y - scrollView.setContentOffset(CGPoint(x: xPos, y: yPos), animated: true) + let yPos = collectionView.contentOffset.y + collectionView.setContentOffset(CGPoint(x: xPos, y: yPos), animated: true) showPaginationControls() groupIndex = position-1 onChangePublisher.send(groupIndex) @@ -557,5 +505,30 @@ extension Carousel: UIScrollViewDelegate { public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { updateScrollbarPosition(targetContentOffsetXPos: targetContentOffset.pointee.x) } - +} +extension Carousel: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { + //-------------------------------------------------- + // MARK: - UICollectionView Delegate & Datasource + //-------------------------------------------------- + public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + views.count + } + + public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CarouselSlotCell.identifier, for: indexPath) as? CarouselSlotCell else { return UICollectionViewCell() } + cell.contentView.subviews.forEach { $0.removeFromSuperview() } + let component = views[indexPath.row] + cell.update(with: component, slotAlignment: slotAlignment, surface: surface) + cell.layoutIfNeeded() + return cell + } + + public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { + return gutter.value + } + + public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + return CGSize(width: minimumSlotWidth, height: fetchCarouselHeight()) + } + } diff --git a/VDS/Components/Carousel/CarouselSlotCell.swift b/VDS/Components/Carousel/CarouselSlotCell.swift new file mode 100644 index 00000000..11807747 --- /dev/null +++ b/VDS/Components/Carousel/CarouselSlotCell.swift @@ -0,0 +1,90 @@ +// +// CarouselSlotCell.swift +// VDS +// +// Created by Kanamarlapudi, Vasavi on 23/08/24. +// + +import Foundation +import UIKit + +final class CarouselSlotCell: UICollectionViewCell { + + ///Identifier for the Calendar Date Cell. + static let identifier: String = String(describing: CarouselSlotCell.self) + + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + override init(frame: CGRect) { + super.init(frame: frame) + setUp() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + setUp() + } + + //-------------------------------------------------- + // MARK: - Private Properties + //-------------------------------------------------- + private var surface: Surface = .light + + //-------------------------------------------------- + // MARK: - Private Methods + //-------------------------------------------------- + + /// Configuring the cell with default setup. + private func setUp() { + isAccessibilityElement = true + } + + /// Updating UI based on data along with surface. + func update(with component: UIView, slotAlignment: Carousel.CarouselSlotAlignmentModel?, surface: Surface) { + self.surface = surface + contentView.addSubview(component) + if var surfacedView = component as? Surfaceable { + surfacedView.surface = surface + } + setSlotAlignment(alignment: slotAlignment, contentView: component) + } + + // Set slot alignment if provided. Used only when slot content have different heights or widths. + private func setSlotAlignment(alignment: Carousel.CarouselSlotAlignmentModel?, contentView: UIView) { + switch alignment?.vertical { + case .top: + contentView + .pinTop() + .pinBottomLessThanOrEqualTo() + case .middle: + contentView + .pinTopGreaterThanOrEqualTo() + .pinBottomLessThanOrEqualTo() + .pinCenterY() + case .bottom: + contentView + .pinTopGreaterThanOrEqualTo() + .pinBottom() + default: break + } + + switch alignment?.horizontal { + case .left: + contentView + .pinLeading() + .pinTrailingLessThanOrEqualTo() + case .center: + contentView + .pinLeadingGreaterThanOrEqualTo() + .pinTrailingLessThanOrEqualTo() + .pinCenterX() + case .right: + contentView + .pinLeadingGreaterThanOrEqualTo() + .pinTrailing() + default: break + } + } + +}