Digital ACT-191 ONEAPP-6827 story: updating cell data
This commit is contained in:
parent
f25e9af766
commit
812fac5a59
@ -13,16 +13,28 @@ final class BreadcrumbCellItem: UICollectionViewCell {
|
|||||||
|
|
||||||
///Identifier for the BreadcrumbCellItem
|
///Identifier for the BreadcrumbCellItem
|
||||||
static let identifier: String = String(describing: BreadcrumbCellItem.self)
|
static let identifier: String = String(describing: BreadcrumbCellItem.self)
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
internal var crumbWidthConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
|
var crumb : BreadcrumbItem? {
|
||||||
|
didSet {
|
||||||
|
guard let crumb = crumb else { return }
|
||||||
|
breadcrumb = crumb
|
||||||
|
crumbWidthConstraint?.constant = crumb.intrinsicContentSize.width
|
||||||
|
crumbWidthConstraint?.isActive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal var stackView: UIStackView = {
|
internal var stackView: UIStackView = {
|
||||||
return UIStackView().with {
|
return UIStackView().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.axis = .horizontal
|
$0.axis = .horizontal
|
||||||
$0.distribution = .fill
|
$0.distribution = .fill
|
||||||
$0.alignment = .top
|
$0.alignment = .top
|
||||||
|
$0.spacing = VDSLayout.Spacing.space1X.value
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -41,6 +53,12 @@ final class BreadcrumbCellItem: UICollectionViewCell {
|
|||||||
|
|
||||||
private let textColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
|
private let textColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
|
||||||
|
|
||||||
|
private var crumbTextColorConfiguration = ControlColorConfiguration().with {
|
||||||
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
|
||||||
|
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||||
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected)
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -56,27 +74,22 @@ final class BreadcrumbCellItem: UICollectionViewCell {
|
|||||||
|
|
||||||
///Configuring the cell with default setup
|
///Configuring the cell with default setup
|
||||||
private func setUp() {
|
private func setUp() {
|
||||||
//add stackview
|
//add stackview - this is the horizontal stack that contains breadcrumb and separator
|
||||||
//this is the horizontal stack that contains breadcrumb and separator
|
|
||||||
stackView.addArrangedSubview(breadcrumb)
|
stackView.addArrangedSubview(breadcrumb)
|
||||||
|
crumbWidthConstraint = breadcrumb.widthAnchor.constraint(greaterThanOrEqualToConstant: 0).activate()
|
||||||
stackView.addArrangedSubview(separator)
|
stackView.addArrangedSubview(separator)
|
||||||
stackView.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: breadcrumb)
|
stackView.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: breadcrumb)
|
||||||
stackView
|
stackView.pinToSuperView()
|
||||||
.pinTop()
|
|
||||||
.pinLeading()
|
|
||||||
.pinTrailing(0, .defaultHigh)
|
|
||||||
.pinBottom(0, .defaultHigh)
|
|
||||||
contentView.addSubview(stackView)
|
contentView.addSubview(stackView)
|
||||||
separator.backgroundColor = .clear
|
separator.backgroundColor = .clear
|
||||||
|
|
||||||
// stackView.backgroundColor = .red
|
|
||||||
// breadcrumb.backgroundColor = .green
|
|
||||||
// separator.backgroundColor = .yellow
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///Updating UI based on selected index, current index along with surface
|
///Updating UI based on selected index, current index along with surface
|
||||||
func update(_ selectedIndex: Int, currentIndex: Int, surface: Surface, showSlash: Bool) {
|
func update(surface: Surface, hideSlash: Bool, breadCrumbItem: BreadcrumbItem) {
|
||||||
|
breadcrumb = breadCrumbItem
|
||||||
|
breadcrumb.text = breadCrumbItem.text
|
||||||
separator.textColor = textColorConfiguration.getColor(surface)
|
separator.textColor = textColorConfiguration.getColor(surface)
|
||||||
separator.isHidden = showSlash
|
separator.isHidden = hideSlash
|
||||||
|
print("selected: \(breadcrumb.isSelected), hideSlash: \(hideSlash), text: \(String(describing: breadCrumbItem.text)))")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,24 +88,24 @@ open class BreadcrumbItem: ButtonBase {
|
|||||||
/// Used to make changes to the View based off a change events or from local properties.
|
/// Used to make changes to the View based off a change events or from local properties.
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
//always call last so the label is rendered
|
//always call last so the label is rendered
|
||||||
if (text != nil) {
|
// if (text != nil) {
|
||||||
var newText: String = text ?? ""
|
// var newText: String = text ?? ""
|
||||||
if isSelected {
|
// if isSelected {
|
||||||
if newText.contains(separator) {
|
// if newText.contains(separator) {
|
||||||
let result = newText.dropLast(2)
|
// let result = newText.dropLast(2)
|
||||||
newText = String(result)
|
// newText = String(result)
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if !newText.contains(separator) {
|
// if !newText.contains(separator) {
|
||||||
newText = (text ?? "") + separator
|
// newText = (text ?? "") + separator
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
print("newText:\(newText), isSelected: \(isSelected)")
|
// print("newText:\(newText), isSelected: \(isSelected)")
|
||||||
text = newText
|
// text = newText
|
||||||
if let titleLabel {
|
// if let titleLabel {
|
||||||
titleLabel.text = text
|
// titleLabel.text = text
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
super.updateView()
|
super.updateView()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,21 +18,11 @@ open class Breadcrumbs: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
///Collectionview width anchor
|
|
||||||
private var collectionViewWidthAnchor: NSLayoutConstraint?
|
|
||||||
///Selected page index
|
|
||||||
private var _selectedPageIndex: Int = 0
|
|
||||||
///A root view for the Breadcrumbs
|
|
||||||
private let containerView: View = View().with {
|
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
}
|
|
||||||
|
|
||||||
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
|
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
|
||||||
|
|
||||||
///Collectionview to render Breadcrumbs indexes
|
///Collectionview to render Breadcrumbs indexes
|
||||||
private lazy var collectionView: UICollectionView = {
|
private lazy var collectionView: UICollectionView = {
|
||||||
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
||||||
layout.itemSize = CGSize(width: 50, height: 25)
|
|
||||||
layout.minimumInteritemSpacing = VDSLayout.Spacing.space1X.value
|
layout.minimumInteritemSpacing = VDSLayout.Spacing.space1X.value
|
||||||
collectionView.isScrollEnabled = false
|
collectionView.isScrollEnabled = false
|
||||||
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
@ -49,15 +39,15 @@ open class Breadcrumbs: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// /// Array of Breadcrumb Items Titles that are shown as Breadcrumbs.
|
|
||||||
// open var breadcrumbs: [String?] = [] { didSet { setNeedsUpdate() } }
|
|
||||||
|
|
||||||
/// Array of Breadcrumb Items that are shown in the group.
|
/// Array of Breadcrumb Items that are shown in the group.
|
||||||
open var breadcrumbItems: [ButtonBase] = [] { didSet { setNeedsUpdate() } }
|
open var breadcrumbItems: [ButtonBase] = [] { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// Whether this object is enabled or not
|
/// Whether this object is enabled or not
|
||||||
open var selected: Bool = false { didSet { setNeedsUpdate() } }
|
override open var isEnabled: Bool {
|
||||||
|
didSet {
|
||||||
|
breadcrumbItems.forEach { $0.isEnabled = isEnabled }
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Current Surface and this is used to pass down to child objects that implement Surfacable
|
/// Current Surface and this is used to pass down to child objects that implement Surfacable
|
||||||
override open var surface: Surface {
|
override open var surface: Surface {
|
||||||
didSet {
|
didSet {
|
||||||
@ -76,13 +66,9 @@ open class Breadcrumbs: View {
|
|||||||
/// Executed on initialization for this View.
|
/// Executed on initialization for this View.
|
||||||
open override func initialSetup() {
|
open override func initialSetup() {
|
||||||
super.initialSetup()
|
super.initialSetup()
|
||||||
|
addSubview(collectionView)
|
||||||
addSubview(containerView)
|
collectionView.pinToSuperView()
|
||||||
containerView.pinToSuperView()
|
collectionView.heightAnchor.constraint(equalToConstant: 100).activate()
|
||||||
//for TEST
|
|
||||||
containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 288).activate()
|
|
||||||
containerView.heightAnchor.constraint(equalToConstant: 150).activate()
|
|
||||||
containerView.addSubview(collectionView)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets to default settings.
|
/// Resets to default settings.
|
||||||
@ -94,6 +80,7 @@ open class Breadcrumbs: View {
|
|||||||
/// Used to make changes to the View based off a change events or from local properties.
|
/// Used to make changes to the View based off a change events or from local properties.
|
||||||
open override func updateView() {
|
open override func updateView() {
|
||||||
super.updateView()
|
super.updateView()
|
||||||
|
collectionView.reloadData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,19 +88,22 @@ extension Breadcrumbs: UICollectionViewDelegate, UICollectionViewDataSource, UIC
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - UICollectionView Delegate & Datasource
|
// MARK: - UICollectionView Delegate & Datasource
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { breadcrumbItems.count }
|
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { breadcrumbItems.count
|
||||||
|
}
|
||||||
|
|
||||||
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: BreadcrumbCellItem.identifier, for: indexPath) as? BreadcrumbCellItem else { return UICollectionViewCell() }
|
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: BreadcrumbCellItem.identifier, for: indexPath) as? BreadcrumbCellItem else { return UICollectionViewCell() }
|
||||||
|
let breadcrumb : BreadcrumbItem = breadcrumbItems[indexPath.row] as! BreadcrumbItem
|
||||||
let showSlash = (indexPath.row == (breadcrumbItems.count - 1))
|
let hideSlash = (indexPath.row == (breadcrumbItems.count - 1))
|
||||||
cell.update(_selectedPageIndex, currentIndex: indexPath.row, surface: surface, showSlash: showSlash)
|
cell.crumb = breadcrumb
|
||||||
|
cell.update(surface: surface, hideSlash: hideSlash, breadCrumbItem: breadcrumb)
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func collectionView(_ collectionView: UICollectionView, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
|
||||||
|
breadcrumbItems[indexPath.row].intrinsicContentSize
|
||||||
|
}
|
||||||
|
|
||||||
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
// _selectedPageIndex = indexPath.row
|
|
||||||
// updateSelection()
|
|
||||||
// onPageDidSelect?(selectedPage)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user