updates
This commit is contained in:
parent
6b3bcbea6a
commit
84adccd187
@ -71,6 +71,10 @@ open class MultiItemDropdownEntryField: BaseItemPickerEntryField {
|
||||
}
|
||||
}
|
||||
|
||||
func pickerHasComponent(_ index: Int) -> Bool {
|
||||
!pickerComponents.isEmpty && !pickerComponents[index].isEmpty
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - TextField Observation
|
||||
//--------------------------------------------------
|
||||
@ -122,18 +126,14 @@ open class MultiItemDropdownEntryField: BaseItemPickerEntryField {
|
||||
|
||||
@objc public func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
||||
|
||||
guard !pickerComponents.isEmpty,
|
||||
!pickerComponents[component].isEmpty
|
||||
else { return nil }
|
||||
guard pickerHasComponent(component) else { return nil }
|
||||
|
||||
return pickerComponents[component][row]
|
||||
}
|
||||
|
||||
@objc public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
||||
|
||||
guard !pickerComponents.isEmpty,
|
||||
!pickerComponents[component].isEmpty
|
||||
else { return }
|
||||
guard pickerHasComponent(component) else { return }
|
||||
|
||||
let oldText = text ?? ""
|
||||
dropdownModel?.selectedIndexes[component] = row
|
||||
|
||||
@ -18,7 +18,7 @@ import Foundation
|
||||
|
||||
public var components: [[String]] = [[]]
|
||||
public var selectedIndexes: [Int: Int] = [:]
|
||||
public var delimiters: [String]?
|
||||
public var delimiters: [Int: String] = [:]
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Validation
|
||||
@ -31,26 +31,19 @@ import Foundation
|
||||
return selectedRowText
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
/// - parameter index: The index of the delimiter.
|
||||
/// - returns: The delimiter for a given idenx. Defaults to whitespace for valid index if no delimiters is provided. If invalid index, emoty string.
|
||||
public func delimiter(for index: Int) -> String {
|
||||
|
||||
guard let delimiters = delimiters else { return " " }
|
||||
|
||||
guard index != components.count - 1 else { return "" }
|
||||
|
||||
return delimiters[index]
|
||||
return delimiters[index] ?? " "
|
||||
}
|
||||
|
||||
/*
|
||||
public func delimiter(for index: Int) -> String {
|
||||
|
||||
guard index != components.count - 1 else { return "" }
|
||||
guard let delimiters = delimiters,
|
||||
index < delimiters.count
|
||||
else { return " " }
|
||||
|
||||
return delimiters[index]
|
||||
}
|
||||
*/
|
||||
|
||||
/// A string of the picker row concatenated by whitespace or delimiters if provided.
|
||||
public var selectedRowText: String {
|
||||
|
||||
@ -76,6 +69,18 @@ import Foundation
|
||||
return indexArray
|
||||
}
|
||||
|
||||
public var delimiterArray: [String] {
|
||||
|
||||
var array: [String] = []
|
||||
|
||||
for i in 0..<delimiters.count {
|
||||
guard let delimiterIndex = delimiters[i] else { return [] }
|
||||
array.append(delimiterIndex)
|
||||
}
|
||||
|
||||
return array
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
@ -95,7 +100,12 @@ import Foundation
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
components = try typeContainer.decode([[String]].self, forKey: .components)
|
||||
delimiters = try typeContainer.decodeIfPresent([String].self, forKey: .delimiters)
|
||||
|
||||
if let delimiters = try typeContainer.decodeIfPresent([String].self, forKey: .delimiters) {
|
||||
for (index, delimiter) in delimiters.enumerated() {
|
||||
self.delimiters[index] = delimiter
|
||||
}
|
||||
}
|
||||
|
||||
if let indexes = try typeContainer.decodeIfPresent([Int].self, forKey: .selectedIndexes) {
|
||||
for (component, index) in indexes.enumerated() {
|
||||
@ -111,6 +121,6 @@ import Foundation
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(components, forKey: .components)
|
||||
try container.encode(selectedIndexesArray, forKey: .selectedIndexes)
|
||||
try container.encodeIfPresent(delimiters, forKey: .delimiters)
|
||||
try container.encodeIfPresent(delimiterArray, forKey: .delimiters)
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,8 +52,6 @@ import UIKit
|
||||
/// Validate on each entry in the textField. Default: true
|
||||
public var validateEachCharacter: Bool = true
|
||||
|
||||
// private var observation: NSKeyValueObservation? = nil
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Computed Properties
|
||||
//--------------------------------------------------
|
||||
@ -123,7 +121,6 @@ import UIKit
|
||||
set {
|
||||
feedbackLabel.text = newValue
|
||||
feedbackLabel.accessibilityElementsHidden = feedbackLabel.text?.isEmpty ?? true
|
||||
entryFieldContainer.refreshUI(updateMoleculeLayout: true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,46 +216,6 @@ import UIKit
|
||||
layoutMarginsGuide.bottomAnchor.constraint(equalTo: feedbackLabel.bottomAnchor).isActive = true
|
||||
}
|
||||
|
||||
/*
|
||||
isAccessibilityElement = false
|
||||
setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
accessibilityElements = [titleLabel, feedbackLabel]
|
||||
backgroundColor = .mvmWhite
|
||||
|
||||
// observation = observe(\.feedbackLabel.text, options: [.new]) { [weak self] _, _ in
|
||||
// self?.entryFieldContainer.refreshUI(updateMoleculeLayout: true)
|
||||
// }
|
||||
|
||||
addSubview(titleLabel)
|
||||
addSubview(entryFieldContainer)
|
||||
addSubview(feedbackLabel)
|
||||
|
||||
|
||||
titleLabelLeading = titleLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||
titleLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: titleLabel.trailingAnchor)
|
||||
titleContainerDistance = entryFieldContainer.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: Padding.One)
|
||||
entryFieldContainerLeading = entryFieldContainer.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||
feedbackContainerDistance = feedbackLabel.topAnchor.constraint(equalTo: entryFieldContainer.bottomAnchor, constant: Padding.Two)
|
||||
entryFieldContainerTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: entryFieldContainer.trailingAnchor)
|
||||
feedbackLabelLeading = feedbackLabel.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
|
||||
feedbackLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: feedbackLabel.trailingAnchor)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
titleLabel.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
|
||||
titleLabelLeading!,
|
||||
titleLabelLeading!,
|
||||
titleContainerDistance!,
|
||||
entryFieldContainerLeading!,
|
||||
entryFieldContainerTrailing!,
|
||||
feedbackContainerDistance!,
|
||||
feedbackLabelLeading!,
|
||||
feedbackLabelTrailing!,
|
||||
layoutMarginsGuide.bottomAnchor.constraint(equalTo: feedbackLabel.bottomAnchor)
|
||||
])
|
||||
|
||||
entryFieldContainer.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
setupFieldContainerContent(entryFieldContainer)
|
||||
*/
|
||||
@objc open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user