vds_ios_sample/VDSSample/ViewControllers/ModalViewController.swift
2024-09-20 12:38:25 +05:30

104 lines
3.5 KiB
Swift

//
// ModalViewController.swift
// VDSSample
//
// Created by Kanamarlapudi, Vasavi on 5/09/24.
//
import Foundation
import UIKit
import VDS
import VDSCoreTokens
import Combine
class ModalViewController: BaseViewController<Modal> {
var disabledSwitch = Toggle()
var showFooterSwitch = Toggle()
var fullScreenDialogSwitch = Toggle()
var singleButtonSwitch = Toggle()
var hideCloseSwitch = Toggle()
var disableAnimationSwitch = Toggle()
var disableOutsideSwitch = Toggle()
var openedSwitch = Toggle()
var enableBackSwitch = Toggle()
var titleTextField = TextField()
var bodyTextField = TextField()
var heightTextField = TextField()
var widthTextField = TextField()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: .makeWrapper(for: component, edgeSpacing: 16.0), edgeSpacing: 0.0)
setupPicker()
setupModel()
}
override func setupForm(){
super.setupForm()
addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Show Modal Footer", view: showFooterSwitch)
addFormRow(label: "Full Screen Dialog", view: fullScreenDialogSwitch)
addFormRow(label: "Single Button", view: singleButtonSwitch)
addFormRow(label: "Hide Close Button", view: hideCloseSwitch)
addFormRow(label: "Disable Animation", view: disableAnimationSwitch)
addFormRow(label: "Disable Outside Click", view: disableOutsideSwitch)
addFormRow(label: "Opened", view: openedSwitch)
addFormRow(label: "Modal Title", view: titleTextField)
addFormRow(label: "Modal Body", view: bodyTextField)
addFormRow(label: "Enable Back Button", view: enableBackSwitch)
addFormRow(label: "Max Height", view: heightTextField)
addFormRow(label: "Max Width", view: widthTextField)
disabledSwitch.onChange = { [weak self] sender in
self?.component.isEnabled = !sender.isOn
}
titleTextField
.textPublisher
.sink { [weak self] text in
self?.component.title = text
}.store(in: &subscribers)
bodyTextField
.textPublisher
.sink { [weak self] text in
self?.component.content = text
}.store(in: &subscribers)
}
func setupModel() {
component.title = "5G Ultra Wideband is available in your area."
component.content = "$799.99 (128 GB only) "
//component.contentView = Icon().with { $0.name = .addFolder; $0.size = .medium }
//setup UI
surfacePickerSelectorView.text = component.surface.rawValue
disabledSwitch.isOn = !component.isEnabled
titleTextField.text = component.title
bodyTextField.text = component.content
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.surface = item
self?.contentTopView.backgroundColor = item.color
}
}
}
extension ModalViewController: ComponentSampleable {
static func makeSample() -> ComponentSample {
let component = Self.makeComponent()
component.title = "5G Ultra Wideband is available in your area."
component.content = "$799.99 (128 GB only) "
return ComponentSample(component: component, trailingPinningType: .lessThanOrEqual, bottomPinningType: .lessThanOrEqual)
}
}