Digital ACT-191 ONEAPP-6827 story: Updated code as per review feedback
This commit is contained in:
parent
bf3149f567
commit
e0d1fd844d
@ -9,6 +9,7 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
1832AC572BA0791D008AE476 /* BreadcrumbCellItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1832AC562BA0791D008AE476 /* BreadcrumbCellItem.swift */; };
|
||||
18450CF12BA1B19C009FDF2A /* BreadcrumbsChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 18450CF02BA1B19C009FDF2A /* BreadcrumbsChangeLog.txt */; };
|
||||
1855EC662BAABF2A002ACAC2 /* BreadcrumbItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1855EC652BAABF2A002ACAC2 /* BreadcrumbItemModel.swift */; };
|
||||
186B2A8A2B88DA7F001AB71F /* TextAreaChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 186B2A892B88DA7F001AB71F /* TextAreaChangeLog.txt */; };
|
||||
18792A902B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18792A8F2B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift */; };
|
||||
18A65A022B96E848006602CC /* Breadcrumbs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18A65A012B96E848006602CC /* Breadcrumbs.swift */; };
|
||||
@ -184,6 +185,7 @@
|
||||
/* Begin PBXFileReference section */
|
||||
1832AC562BA0791D008AE476 /* BreadcrumbCellItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BreadcrumbCellItem.swift; sourceTree = "<group>"; };
|
||||
18450CF02BA1B19C009FDF2A /* BreadcrumbsChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = BreadcrumbsChangeLog.txt; sourceTree = "<group>"; };
|
||||
1855EC652BAABF2A002ACAC2 /* BreadcrumbItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BreadcrumbItemModel.swift; sourceTree = "<group>"; };
|
||||
186B2A892B88DA7F001AB71F /* TextAreaChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TextAreaChangeLog.txt; sourceTree = "<group>"; };
|
||||
18792A8F2B7431F2008C0D29 /* ButtonIconBadgeIndicatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonIconBadgeIndicatorModel.swift; sourceTree = "<group>"; };
|
||||
18A65A012B96E848006602CC /* Breadcrumbs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Breadcrumbs.swift; sourceTree = "<group>"; };
|
||||
@ -373,8 +375,9 @@
|
||||
18A65A002B96E7E1006602CC /* Breadcrumbs */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
18A65A012B96E848006602CC /* Breadcrumbs.swift */,
|
||||
18A65A032B96F050006602CC /* BreadcrumbItem.swift */,
|
||||
1855EC652BAABF2A002ACAC2 /* BreadcrumbItemModel.swift */,
|
||||
18A65A012B96E848006602CC /* Breadcrumbs.swift */,
|
||||
1832AC562BA0791D008AE476 /* BreadcrumbCellItem.swift */,
|
||||
18450CF02BA1B19C009FDF2A /* BreadcrumbsChangeLog.txt */,
|
||||
);
|
||||
@ -1043,6 +1046,7 @@
|
||||
EA0D1C452A6AD73000E5C127 /* RawRepresentable.swift in Sources */,
|
||||
EA985C23296E033A00F2FF2E /* TextArea.swift in Sources */,
|
||||
EAF7F0B3289B1ADC00B287F5 /* ActionLabelAttribute.swift in Sources */,
|
||||
1855EC662BAABF2A002ACAC2 /* BreadcrumbItemModel.swift in Sources */,
|
||||
EAC925832911B35400091998 /* TextLinkCaret.swift in Sources */,
|
||||
EA33622E2891EA3C0071C351 /* DispatchQueue+Once.swift in Sources */,
|
||||
EA4DB2FD28D3D0CA00103EE3 /* AnyEquatable.swift in Sources */,
|
||||
|
||||
@ -66,9 +66,9 @@ final class BreadcrumbCellItem: UICollectionViewCell {
|
||||
func update(surface: Surface, hideSlash: Bool, breadCrumbItem: BreadcrumbItem) {
|
||||
separator.surface = surface
|
||||
breadCrumbItem.surface = surface
|
||||
stackView.addArrangedSubview(separator)
|
||||
stackView.addArrangedSubview(breadCrumbItem)
|
||||
stackView.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: separator)
|
||||
stackView.addArrangedSubview(separator)
|
||||
stackView.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: breadCrumbItem)
|
||||
separator.textColor = textColorConfiguration.getColor(surface)
|
||||
separator.isHidden = hideSlash
|
||||
self.breadCrumbItem = breadCrumbItem
|
||||
|
||||
@ -40,18 +40,8 @@ open class BreadcrumbItem: ButtonBase {
|
||||
/// TextStyle used on the titleLabel.
|
||||
open override var textStyle: TextStyle { isSelected ? TextStyle.boldBodySmall : TextStyle.bodySmall }
|
||||
|
||||
/// If true, it will be rendered as selected.
|
||||
open var selectable: Bool = false {
|
||||
didSet {
|
||||
//update selected state
|
||||
if selectable{
|
||||
isSelected = true
|
||||
} else {
|
||||
isSelected = false
|
||||
}
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
/// Whether the Control is selected or not.
|
||||
open override var isSelected: Bool { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// UIColor used on the titleLabel text.
|
||||
open override var textColor: UIColor {
|
||||
|
||||
32
VDS/Components/Breadcrumbs/BreadcrumbItemModel.swift
Normal file
32
VDS/Components/Breadcrumbs/BreadcrumbItemModel.swift
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// BreadcrumbItemModel.swift
|
||||
// VDS
|
||||
//
|
||||
// Created by Kanamarlapudi, Vasavi on 20/03/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Breadcrumbs {
|
||||
public struct BreadcrumbItemModel {
|
||||
|
||||
///Text that goes in the breadcrumb item
|
||||
public var text: String
|
||||
|
||||
/// The Breadcrumb link to links to its respective page.
|
||||
public var link: String
|
||||
|
||||
/// The Breadcrumb link to links to its respective page.
|
||||
public var isSelected: Bool?
|
||||
|
||||
///Click event when you click on a breadcrumb item
|
||||
public var onClick: ((BreadcrumbItem) -> Void)?
|
||||
|
||||
public init(text: String, link: String, isSelected: Bool? = false, onClick: ((BreadcrumbItem) -> Void)? = nil) {
|
||||
self.text = text
|
||||
self.isSelected = isSelected
|
||||
self.onClick = onClick
|
||||
self.link = link
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,23 +18,32 @@ open class Breadcrumbs: View {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
/// Array of Breadcrumb Items that are shown in the group.
|
||||
open var breadcrumbItems: [BreadcrumbItem] = [] { didSet { setNeedsUpdate() } }
|
||||
/// Array of ``BreadcrumbItem`` views for the Breadcrumbs.
|
||||
open var breadcrumbs: [BreadcrumbItem] = []
|
||||
|
||||
/// Array of ``BreadcurmbItemModel`` you are wanting to show.
|
||||
open var breadcrumbModels: [BreadcrumbItemModel] = [] { didSet { updateBreadcrumbItems() } }
|
||||
|
||||
/// Whether this object is enabled or not
|
||||
override open var isEnabled: Bool {
|
||||
didSet {
|
||||
breadcrumbItems.forEach { $0.isEnabled = isEnabled }
|
||||
breadcrumbs.forEach { $0.isEnabled = isEnabled }
|
||||
}
|
||||
}
|
||||
|
||||
/// Current Surface and this is used to pass down to child objects that implement Surfacable
|
||||
override open var surface: Surface {
|
||||
didSet {
|
||||
breadcrumbItems.forEach { $0.surface = surface }
|
||||
breadcrumbs.forEach { $0.surface = surface }
|
||||
}
|
||||
}
|
||||
|
||||
/// A callback when the selected item changes. Passes parameters (crumb).
|
||||
open var onBreadcrumbDidSelect: ((BreadcrumbItem) -> Void)?
|
||||
|
||||
/// A callback when the Tab determine if a item should be selected.
|
||||
open var onBreadcrumbShouldSelect:((BreadcrumbItem) -> Bool)?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
@ -65,6 +74,35 @@ open class Breadcrumbs: View {
|
||||
return collectionView
|
||||
}()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Methods
|
||||
//--------------------------------------------------
|
||||
/// Removes all of the Breadcrumbs and creates new ones from the Breadcrumb Models property.
|
||||
private func updateBreadcrumbItems() {
|
||||
// Clear existing breadcrumbs
|
||||
for breadcrumbItem in breadcrumbs {
|
||||
breadcrumbItem.removeFromSuperview()
|
||||
}
|
||||
|
||||
breadcrumbs.removeAll()
|
||||
// Create new breadcrumb items from the models
|
||||
for model in breadcrumbModels {
|
||||
let breadcrumbItem = BreadcrumbItem()
|
||||
breadcrumbItem.text = model.text
|
||||
breadcrumbItem.link = model.link
|
||||
breadcrumbItem.isSelected = model.isSelected ?? false
|
||||
breadcrumbs.append(breadcrumbItem)
|
||||
breadcrumbItem.onClick = { [weak self] breadcrumb in
|
||||
guard let self else { return }
|
||||
if self.onBreadcrumbShouldSelect?(breadcrumb) ?? true {
|
||||
model.onClick?(breadcrumb)
|
||||
self.onBreadcrumbDidSelect?(breadcrumb)
|
||||
}
|
||||
}
|
||||
}
|
||||
setNeedsUpdate()
|
||||
}
|
||||
|
||||
//------------------------------------------s--------
|
||||
// MARK: - Overrides
|
||||
//--------------------------------------------------
|
||||
@ -88,7 +126,7 @@ open class Breadcrumbs: View {
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
shouldUpdateView = false
|
||||
breadcrumbItems.forEach { $0.reset() }
|
||||
breadcrumbs.forEach { $0.reset() }
|
||||
shouldUpdateView = true
|
||||
setNeedsUpdate()
|
||||
}
|
||||
@ -115,17 +153,17 @@ extension Breadcrumbs: UICollectionViewDelegate, UICollectionViewDataSource {
|
||||
//--------------------------------------------------
|
||||
// MARK: - UICollectionView Delegate & Datasource
|
||||
//--------------------------------------------------
|
||||
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { breadcrumbItems.count
|
||||
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { breadcrumbs.count
|
||||
}
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: BreadcrumbCellItem.identifier, for: indexPath) as? BreadcrumbCellItem else { return UICollectionViewCell() }
|
||||
let hideSlash = (indexPath.row == 0)
|
||||
cell.update(surface: surface, hideSlash: hideSlash, breadCrumbItem: breadcrumbItems[indexPath.row])
|
||||
let hideSlash = (indexPath.row == breadcrumbs.count - 1 || breadcrumbs.count == 1)
|
||||
cell.update(surface: surface, hideSlash: hideSlash, breadCrumbItem: breadcrumbs[indexPath.row])
|
||||
return cell
|
||||
}
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
|
||||
breadcrumbItems[indexPath.row].intrinsicContentSize
|
||||
breadcrumbs[indexPath.row].intrinsicContentSize
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user