Digital ACT-191 ONEAPP-6827 story: Updated code as per review feedback

This commit is contained in:
vasavk 2024-03-20 17:16:56 +05:30
parent 3fe3ede2f8
commit 16857ade9f
2 changed files with 46 additions and 21 deletions

View File

@ -99,11 +99,4 @@ extension BaseViewController {
$0.labelPublisher(label)
}
}
func makeBreadcrumbItem(_ text: String, label: UILabel) -> BreadcrumbItem {
return BreadcrumbItem().with{
$0.text = text
$0.labelPublisher(label)
}
}
}

View File

@ -14,33 +14,51 @@ import Combine
class BreadcrumbsViewController: BaseViewController<Breadcrumbs> {
var selectedSwitch = Toggle()
var sampleSwitch = Toggle()
var selectedCrumbLabel = Label().with { $0.textStyle = .boldBodyMedium }
var allBreadcrumbs: [Breadcrumbs.BreadcrumbItemModel] = [
.init(text: "Home", link: "https://www.verizon.com/"),
.init(text: "Support", link: "https://www.verizon.com/"),
.init(text: "Servie & Apps", link: "https://www.verizon.com/"),
.init(text: "My Verizon", link: "https://www.verizon.com/"),
.init(text: "Bill", link: "https://www.verizon.com/"),
.init(text: "Mobile Billing & Payments", link: "https://www.verizon.com/"),
.init(text: "Billing statement FAQs", link: "https://www.verizon.com/", isSelected: true)
]
var some: [Breadcrumbs.BreadcrumbItemModel] = [
.init(text: "Plans", link: "https://www.verizon.com/"),
.init(text: "Upgrade Plan", link: "https://www.verizon.com/", isSelected: true)
]
override func viewDidLoad() {
super.viewDidLoad()
let label = actionLabel
component.breadcrumbItems = [
makeBreadcrumbItem("Home", label: label).with{ $0.link = "https://www.verizon.com/" },
makeBreadcrumbItem("Support", label: label).with{ $0.link = "https://www.verizon.com/"; $0.selectable = false },
makeBreadcrumbItem("Servie & Apps", label: label).with{ $0.link = "https://www.verizon.com/" },
makeBreadcrumbItem("My Verizon", label: label).with{ $0.link = "https://www.verizon.com/"; $0.selectable = false },
makeBreadcrumbItem("Bill", label: label).with{ $0.link = "https://www.verizon.com/" },
makeBreadcrumbItem("Billing statement FAQs", label: label).with{ $0.link = "https://www.verizon.com/"; $0.selectable = true }
]
addContentTopView(view: component)
let stack = UIStackView(arrangedSubviews: [component, selectedCrumbLabel]).with {
$0.axis = .vertical
$0.spacing = 4
}
addContentTopView(view: stack)
setupPicker()
setupModel()
}
override func setupForm(){
super.setupForm()
addActionRow()
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Last Crumb Selected", view: selectedSwitch)
addFormRow(label: "Large Sample", view: sampleSwitch)
selectedSwitch.onChange = { [weak self] sender in
guard let self else { return }
component.breadcrumbItems.last?.selectable = sender.isOn
component.breadcrumbs.last?.isSelected = sender.isOn
}
sampleSwitch.onChange = { [weak self] sender in
guard let self else { return }
self.component.breadcrumbModels = sender.isOn ? self.allBreadcrumbs : self.some
selectedSwitch.isOn = true
updatedCrumbLabel(crumb: component.breadcrumbs.last ?? nil)
}
}
@ -51,9 +69,23 @@ class BreadcrumbsViewController: BaseViewController<Breadcrumbs> {
}
}
func updatedCrumbLabel(crumb: BreadcrumbItem?) {
selectedCrumbLabel.text = "Selected Crumb : \(crumb?.text ?? "")"
}
func setupModel() {
//setup UI
component.breadcrumbModels = allBreadcrumbs
selectedSwitch.isOn = true
sampleSwitch.isOn = true
surfacePickerSelectorView.text = component.surface.rawValue
updatedCrumbLabel(crumb: component.breadcrumbs.last ?? nil)
//test setup to show component was picked
component.onBreadcrumbDidSelect = { [weak self] crumb in
guard let self else { return }
self.updatedCrumbLabel(crumb: crumb)
}
}
}