diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index 4d16f0b..65dcdbb 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -56,7 +56,6 @@ EA5E305C295111050082B959 /* TileletViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5E305B295111050082B959 /* TileletViewController.swift */; }; EA5F86CE2A1E863F00BC83E4 /* TabsContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86CD2A1E863F00BC83E4 /* TabsContainerViewController.swift */; }; EA81410E2A0ED8DC004F60D2 /* ButtonIconViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA81410D2A0ED8DC004F60D2 /* ButtonIconViewController.swift */; }; - EA84F76228BE4AE500D67ABC /* RadioSwatchGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */; }; EA89201928B56DF5006B9984 /* RadioBoxGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */; }; EA89204628B66CE2006B9984 /* ScrollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89203F28B66CE2006B9984 /* ScrollViewController.swift */; }; EA89204728B66CE2006B9984 /* KeyboardFrameChangeListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89204028B66CE2006B9984 /* KeyboardFrameChangeListener.swift */; }; @@ -153,7 +152,6 @@ EA5E305B295111050082B959 /* TileletViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileletViewController.swift; sourceTree = ""; }; EA5F86CD2A1E863F00BC83E4 /* TabsContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsContainerViewController.swift; sourceTree = ""; }; EA81410D2A0ED8DC004F60D2 /* ButtonIconViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonIconViewController.swift; sourceTree = ""; }; - EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSwatchGroupViewController.swift; sourceTree = ""; }; EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBoxGroupViewController.swift; sourceTree = ""; }; EA89203F28B66CE2006B9984 /* ScrollViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollViewController.swift; sourceTree = ""; }; EA89204028B66CE2006B9984 /* KeyboardFrameChangeListener.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardFrameChangeListener.swift; sourceTree = ""; }; @@ -329,7 +327,6 @@ EA0D1C302A673F3500E5C127 /* RadioButtonViewController.swift */, EA0D1C322A673FD400E5C127 /* RadioButtonItemViewController.swift */, EAF7F11928A14A0E00B287F5 /* RadioButtonGroupViewController.swift */, - EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */, EA5F86CD2A1E863F00BC83E4 /* TabsContainerViewController.swift */, EA596AB92A16B2ED00300C4B /* TabsViewController.swift */, EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */, @@ -535,7 +532,6 @@ EAD062A52A3B5CDF0015965D /* Slider.swift in Sources */, EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */, EA89204B28B66CE2006B9984 /* ScrollViewKeyboardAvoider.swift in Sources */, - EA84F76228BE4AE500D67ABC /* RadioSwatchGroupViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/VDSSample/Classes/TextField.swift b/VDSSample/Classes/TextField.swift index 0df3c00..20c57b8 100644 --- a/VDSSample/Classes/TextField.swift +++ b/VDSSample/Classes/TextField.swift @@ -11,7 +11,7 @@ import VDS import VDSFormControlsTokens import Combine -public class TextField: UITextField { +open class TextField: UITextField { public var resigner: AnyCancellable? public var resignAction: ((TextField) -> Void)? diff --git a/VDSSample/Protocols/CustomRotorable.swift b/VDSSample/Protocols/CustomRotorable.swift index 66c64e8..1466e60 100644 --- a/VDSSample/Protocols/CustomRotorable.swift +++ b/VDSSample/Protocols/CustomRotorable.swift @@ -13,79 +13,62 @@ public protocol CustomRotorable: UIViewController { } extension CustomRotorable { - - /// Adds CustomRotor to the accessibilityCustomRotors array. - /// - Parameters: - /// - name: Name that will show up in the Rotor picker. - /// - trait: Any UIView that has this traits will be added to this Name. + internal func addCustomRotor(with name: String, for trait: UIAccessibilityTraits) { - //filter out old rotors with same name accessibilityCustomRotors = (accessibilityCustomRotors ?? []).filter { $0.name != name } - - //create new rotor + let newRotor = UIAccessibilityCustomRotor(name: name) { [weak self] predicate in - guard let self else { return nil } - - let views = self.view.accessibleElements(with: trait) - - guard !views.isEmpty else { return nil } + guard let self = self else { return nil } + + let elements = self.view.accessibleElements(with: trait) + + guard !elements.isEmpty else { return nil } - let currentIndex = views.firstIndex(where: { $0 === predicate.currentItem.targetElement }) - let count = views.count - - //find the nextIndex + let currentIndex = elements.firstIndex(where: { ($0 as AnyObject) === predicate.currentItem.targetElement }) + let count = elements.count + let nextIndex: Int switch predicate.searchDirection { case .next: - if let currentIndex, currentIndex != count - 1{ - //go forwards - nextIndex = currentIndex + 1 - } else { - //get the first - nextIndex = 0 - } + nextIndex = currentIndex.map { ($0 + 1) % count } ?? 0 case .previous: - if let currentIndex, currentIndex != 0 { - //go backwards - nextIndex = currentIndex - 1 - } else { - //get the last - nextIndex = count - 1 - } + nextIndex = currentIndex.map { ($0 - 1 + count) % count } ?? 0 @unknown default: - //get the first nextIndex = 0 } - - return UIAccessibilityCustomRotorItemResult(targetElement: views[nextIndex], targetRange: nil) + + guard let element = elements[nextIndex] as? NSObjectProtocol else { return nil } + return UIAccessibilityCustomRotorItemResult(targetElement: element, targetRange: nil) } - - //append rotor + accessibilityCustomRotors?.append(newRotor) } - - /// Loads all of the custom rotors for the screen. + public func loadCustomRotors() { customRotors.forEach { addCustomRotor(with: $0.name, for: $0.trait) } } } public extension UIView { - - /// Gets all of the Views that has the matching accessibilityTrait. - /// - Parameter trait: This is the trailt for the accessibilityTrait property of a view. - /// - Returns: An array of RotorItemResult - func accessibleElements(with trait: UIAccessibilityTraits) -> [UIView] { - var elements: [UIView] = [] - - //add your self if you meet the requirements + + func accessibleElements(with trait: UIAccessibilityTraits) -> [Any] { + var elements: [Any] = [] + if isAccessibilityElement, accessibilityTraits.contains(trait) { elements.append(self) } - - //loop through your subviews + + if let customAccessibilityElements = accessibilityElements { + elements.append(contentsOf: customAccessibilityElements.filter { element in + if let element = element as? UIAccessibilityElement { + return element.accessibilityTraits.contains(trait) + } + return false + }) + } + subviews.forEach { elements.append(contentsOf: $0.accessibleElements(with: trait)) } - + return elements } } diff --git a/VDSSample/Protocols/PickerBase.swift b/VDSSample/Protocols/PickerBase.swift index 00bbac1..030ce1b 100644 --- a/VDSSample/Protocols/PickerBase.swift +++ b/VDSSample/Protocols/PickerBase.swift @@ -150,7 +150,7 @@ public class SurfacePickerSelectorView: PickerSelectorView{ } } -public class TextPositionPickerSelectorView: PickerSelectorView{ +public class TextPositionPickerSelectorView: PickerSelectorView{ init(picker: UIPickerView? = nil){ super.init(title: "left", picker: picker, items: [.left, .right]) } diff --git a/VDSSample/ViewControllers/BaseViewController.swift b/VDSSample/ViewControllers/BaseViewController.swift index 1449e03..910b407 100644 --- a/VDSSample/ViewControllers/BaseViewController.swift +++ b/VDSSample/ViewControllers/BaseViewController.swift @@ -300,6 +300,7 @@ public class BaseViewController: UIViewController, Initable , var activeTextField: UITextField? + /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open func setup() { if let textFields = allTextFields()?.filter({ $0.isKind(of: TextField.self) == false || $0.isKind(of: NumericField.self) }) { diff --git a/VDSSample/ViewControllers/ButtonGroupViewController.swift b/VDSSample/ViewControllers/ButtonGroupViewController.swift index ce8325e..034c9a8 100644 --- a/VDSSample/ViewControllers/ButtonGroupViewController.swift +++ b/VDSSample/ViewControllers/ButtonGroupViewController.swift @@ -48,9 +48,9 @@ class ButtonGroupViewController: BaseViewController { } lazy var buttonPositionSelectorView = { - PickerSelectorView(title: "", + PickerSelectorView(title: "", picker: self.picker, - items: ButtonGroup.ButtonPosition.allCases) + items: ButtonGroup.Alignment.allCases) }() lazy var rowQuantitySelectorView = { @@ -128,25 +128,25 @@ class ButtonGroupViewController: BaseViewController { .numberPublisher .sink { [weak self] number in if let number { - self?.component.buttonWidth = number.cgFloatValue - self?.smallButtonGroup.buttonWidth = number.cgFloatValue + self?.component.childWidth = .value(number.cgFloatValue) + self?.smallButtonGroup.childWidth = .value(number.cgFloatValue) self?.percentageTextField.text = "" } else { - self?.component.buttonWidth = nil + self?.component.childWidth = nil + self?.smallButtonGroup.childWidth = nil } }.store(in: &subscribers) percentageTextField .numberPublisher .sink { [weak self] number in - let rowQty = self?.component.rowQuantity ?? 0 - if let number, number.intValue <= 100, rowQty > 0 { - self?.component.buttonPercentage = number.cgFloatValue - self?.smallButtonGroup.buttonPercentage = number.cgFloatValue + if let number { + self?.component.childWidth = .percentage(number.cgFloatValue) + self?.smallButtonGroup.childWidth = .percentage(number.cgFloatValue) self?.widthTextField.text = "" } else { - self?.component.buttonPercentage = nil - self?.smallButtonGroup.buttonPercentage = nil + self?.component.childWidth = nil + self?.smallButtonGroup.childWidth = nil } }.store(in: &subscribers) @@ -155,7 +155,7 @@ class ButtonGroupViewController: BaseViewController { func setupModel() { //setup UI surfacePickerSelectorView.text = component.surface.rawValue - buttonPositionSelectorView.text = component.buttonPosition.rawValue + buttonPositionSelectorView.text = component.alignment.rawValue disabledSwitch.isOn = !component.isEnabled rowQuantitySelectorView.text = RowQuantity(quantity: component.rowQuantity).rawValue widthTextField.text = "" @@ -172,8 +172,8 @@ class ButtonGroupViewController: BaseViewController { } buttonPositionSelectorView.onPickerDidSelect = { [weak self] item in - self?.component.buttonPosition = item - self?.smallButtonGroup.buttonPosition = item + self?.component.alignment = item + self?.smallButtonGroup.alignment = item } rowQuantitySelectorView.onPickerDidSelect = { [weak self] item in @@ -184,8 +184,8 @@ class ButtonGroupViewController: BaseViewController { self?.percentageTextField.text = "" } else { self?.widthTextField.text = "" - self?.component.buttonWidth = nil - self?.smallButtonGroup.buttonWidth = nil + self?.component.childWidth = nil + self?.smallButtonGroup.childWidth = nil } if UIDevice.isIPad { diff --git a/VDSSample/ViewControllers/CheckBoxGroupViewController.swift b/VDSSample/ViewControllers/CheckBoxGroupViewController.swift index 4255972..4a95d7c 100644 --- a/VDSSample/ViewControllers/CheckBoxGroupViewController.swift +++ b/VDSSample/ViewControllers/CheckBoxGroupViewController.swift @@ -59,7 +59,7 @@ class CheckboxGroupViewController: BaseViewController { component.onChange = { [weak self] group in guard let label = self?.actionLabel else { return } - let selected = group.selectedHandlers? + let selected = group.selectedItems? .compactMap{"\($0.labelText!)"} .joined(separator: "\r") ?? "none selected" @@ -78,14 +78,14 @@ class CheckboxGroupViewController: BaseViewController { } func setupModel() { - var checkbox1 = CheckboxGroup.CheckboxModel() + var checkbox1 = CheckboxGroup.CheckboxItemModel() checkbox1.inputId = "model1" checkbox1.value = "model 1 Value" checkbox1.labelText = "iPhone 11 Bundle 1" checkbox1.childText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector" checkbox1.errorText = "Please Choose 1" - var checkbox2 = CheckboxGroup.CheckboxModel() + var checkbox2 = CheckboxGroup.CheckboxItemModel() checkbox2.inputId = "model2" checkbox2.value = "model 2 Value" checkbox2.labelText = "iPhone 11 Bundle 2" @@ -104,7 +104,7 @@ class CheckboxGroupViewController: BaseViewController { } var checkbox: CheckboxItem? { - component.selectorViews.first + component.items.first } //Picker @@ -122,14 +122,14 @@ extension CheckboxGroupViewController: ComponentSampleable { static func makeSample() -> ComponentSample { let component = Self.makeComponent() - var checkbox1 = CheckboxGroup.CheckboxModel() + var checkbox1 = CheckboxGroup.CheckboxItemModel() checkbox1.inputId = "model1" checkbox1.value = "model 1 Value" checkbox1.labelText = "iPhone 11 Bundle 1" checkbox1.childText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector" checkbox1.errorText = "Please Choose 1" - var checkbox2 = CheckboxGroup.CheckboxModel() + var checkbox2 = CheckboxGroup.CheckboxItemModel() checkbox2.inputId = "model2" checkbox2.value = "model 2 Value" checkbox2.labelText = "iPhone 11 Bundle 2" diff --git a/VDSSample/ViewControllers/InputFieldViewController.swift b/VDSSample/ViewControllers/InputFieldViewController.swift index e1e81b7..c935829 100644 --- a/VDSSample/ViewControllers/InputFieldViewController.swift +++ b/VDSSample/ViewControllers/InputFieldViewController.swift @@ -117,7 +117,7 @@ class InputFieldViewController: BaseViewController { } func setupModel() { - component.type = .text + component.fieldType = .text component.width = 328 component.labelText = "Street Address" component.helperText = "For example: 123 Verizon St" @@ -171,7 +171,7 @@ class InputFieldViewController: BaseViewController { extension InputFieldViewController: ComponentSampleable { static func makeSample() -> ComponentSample { let component = Self.makeComponent() - component.type = .text + component.fieldType = .text component.width = 328 component.labelText = "Street Address" component.helperText = "For example: 123 Verizon St" diff --git a/VDSSample/ViewControllers/LabelViewController.swift b/VDSSample/ViewControllers/LabelViewController.swift index adcc1d9..b4ca6b3 100644 --- a/VDSSample/ViewControllers/LabelViewController.swift +++ b/VDSSample/ViewControllers/LabelViewController.swift @@ -17,10 +17,10 @@ class LabelViewController: BaseViewController