Digital ACT-191 ONEAPP-7013 story: removing width, passing selectedGroupIndex through onChange, added selected index to form.

This commit is contained in:
Vasavi Kanamarlapudi 2024-07-18 12:56:07 +05:30
parent 59d2634800
commit 1ed92734a4

View File

@ -59,9 +59,7 @@ class CarouselViewController: BaseViewController<Carousel> {
var paginationFloatingSwitch = Toggle() var paginationFloatingSwitch = Toggle()
var paginationInsetField = NumericField() var paginationInsetField = NumericField()
var widthTextField = NumericField() var selectedIndexField = NumericField()
var percentageTextField = NumericField()
var exampleSwitch = Toggle()
var emptyData: [UIView] = [] var emptyData: [UIView] = []
var rows: [UIView] = [] var rows: [UIView] = []
@ -81,34 +79,20 @@ class CarouselViewController: BaseViewController<Carousel> {
addFormRow(label: "Peek", view: peekPickerSelectorView) addFormRow(label: "Peek", view: peekPickerSelectorView)
addFormRow(label: "Gutter", view: gutterPickerSelectorView) addFormRow(label: "Gutter", view: gutterPickerSelectorView)
addFormRow(label: "Layout", view: layoutPickerSelectorView) addFormRow(label: "Layout", view: layoutPickerSelectorView)
addFormRow(label: "Selected Group Index", view: selectedIndexField)
addFormRow(label: "Pagination Kind", view: paginationKindPickerSelectorView) addFormRow(label: "Pagination Kind", view: paginationKindPickerSelectorView)
addFormRow(label: "Pagination Float", view: paginationFloatingSwitch) addFormRow(label: "Pagination Float", view: paginationFloatingSwitch)
addFormRow(label: "Pagination Inset", view: paginationInsetField) addFormRow(label: "Pagination Inset", view: paginationInsetField)
addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "Percentage (1-100)", view: percentageTextField)
addFormRow(label: "Example", view: exampleSwitch)
addFormRow(label: "Slot Horizontal Alignment", view: horizAlignmtPickerSelectorView) addFormRow(label: "Slot Horizontal Alignment", view: horizAlignmtPickerSelectorView)
addFormRow(label: "Slot Vertical Alignment", view: vertAlignmtPickerSelectorView) addFormRow(label: "Slot Vertical Alignment", view: vertAlignmtPickerSelectorView)
widthTextField selectedIndexField
.numberPublisher .numberPublisher
.sink { [weak self] number in .sink { [weak self] number in
if let number { if let number, number.intValue >= 0 {
self?.component.width = .value(number.cgFloatValue) self?.component.selectedIndex = number.intValue
self?.percentageTextField.text = ""
} else { } else {
self?.component.width = nil self?.component.selectedIndex = nil
}
}.store(in: &subscribers)
percentageTextField
.numberPublisher
.sink { [weak self] number in
if let number {
self?.component.width = .percentage(number.cgFloatValue)
self?.widthTextField.text = ""
} else {
self?.component.width = nil
} }
}.store(in: &subscribers) }.store(in: &subscribers)
@ -127,12 +111,6 @@ class CarouselViewController: BaseViewController<Carousel> {
self.component.pagination = .init(kind: paginationKindPickerSelectorView.selectedItem, floating: sender.isOn) self.component.pagination = .init(kind: paginationKindPickerSelectorView.selectedItem, floating: sender.isOn)
} }
exampleSwitch.onChange = { [weak self] sender in
guard let self else { return }
component.views = sender.isOn ? rows : emptyData
component.slotAlignment = nil
}
} }
func setupModel() { func setupModel() {
@ -147,23 +125,22 @@ class CarouselViewController: BaseViewController<Carousel> {
let onClick: (ButtonBase) -> Void = { button in print("\(button.text!) clicked")} let onClick: (ButtonBase) -> Void = { button in print("\(button.text!) clicked")}
rows.append(Label().with { $0.text = "Offer you best deals on phones, tablets, home, internet and more. Pre order the new version mobiles and get 10% off"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping}) rows.append(Label().with { $0.text = "Offer you best deals on phones, tablets, home, internet and more. Pre order the new version mobiles and get 10% off"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})
rows.append(Button().with{ $0.use = .secondary; $0.text = "Secondary"; $0.onClick = onClick}) rows.append(Button().with{ $0.use = .secondary; $0.text = "Secondary"; $0.onClick = onClick})
rows.append(Label().with { $0.text = "Get iPhone 15 on us. Online only. "; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping}) rows.append(Label().with { $0.text = "Get iPhone 15 on us. Online only. "; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})
rows.append(Button().with{ $0.use = .primary; $0.text = "Primary"; $0.onClick = onClick}) rows.append(Button().with{ $0.use = .primary; $0.text = "Primary"; $0.onClick = onClick})
rows.append(Label().with { $0.text = "Unlimited plans. No trade-in required."; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping}) rows.append(Label().with { $0.text = "Unlimited plans. No trade-in required."; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})
rows.append(Label().with { $0.text = "With trade-in. Any condition guaranteed"; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping}) rows.append(Label().with { $0.text = "With trade-in. Any condition guaranteed"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})
rows.append(Label().with { $0.text = "iPhone 14 Plus get it on us."; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping}) rows.append(Label().with { $0.text = "iPhone 14 Plus get it on us."; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})
rows.append(Label().with { $0.text = "Double the storage on us"; $0.textStyle = .boldTitleSmall; $0.lineBreakMode = .byWordWrapping}) rows.append(Label().with { $0.text = "Double the storage on us"; $0.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall; $0.lineBreakMode = .byWordWrapping})
rows.append(Button().with{ $0.use = .secondary; $0.text = "Get iPhone 15"; $0.onClick = onClick}) rows.append(Button().with{ $0.use = .secondary; $0.text = "Get iPhone 15"; $0.onClick = onClick})
rows.append(Button().with{ $0.use = .secondary; $0.text = "Get iPhone 14 Plus"; $0.onClick = onClick}) rows.append(Button().with{ $0.use = .secondary; $0.text = "Get iPhone 14 Plus"; $0.onClick = onClick})
emptyData = [UIView(),UIView(),UIView(),UIView()] component.views = rows
component.views = rows //exampleSwitch.isOn ? rows : emptyData // component.renderItemStyle = .init(backgroundColor: "#d9d9d9", height: 100, width: 100, borderRadius: 12.0)
component.renderItemStyle = .init(backgroundColor: "#d9d9d9", height: 100, width: 100, borderRadius: 12.0) label.text = "0"
label.text = "1"
// Callback when moving the carousel. Returns initial visible slide's index in the carousel. // Callback when moving the carousel. Returns selectedGroupIndex.
component.onChange = { [weak self] selectedIndex in component.onChange = { [weak self] selectedGroupIndex in
guard let self else { return } guard let self else { return }
label.text = "\(selectedIndex)" label.text = "\(selectedGroupIndex)"
} }
} }
@ -208,6 +185,7 @@ class CarouselViewController: BaseViewController<Carousel> {
} }
} }
self?.component.layout = item self?.component.layout = item
self?.label.text = "0"
} }
paginationKindPickerSelectorView.onPickerDidSelect = { [weak self] item in paginationKindPickerSelectorView.onPickerDidSelect = { [weak self] item in