diff --git a/MVMCoreUI/Atoms/TextFields/DigitBox.swift b/MVMCoreUI/Atoms/TextFields/DigitBox.swift index 05e60146..b8f04db6 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitBox.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitBox.swift @@ -77,7 +77,7 @@ import UIKit backgroundColor = .white textAlignment = .center keyboardType = .numberPad - layer.borderWidth = 1 +// layer.borderWidth = 1 showErrorState(false) widthConstraint = widthAnchor.constraint(equalToConstant: 39) @@ -157,10 +157,12 @@ import UIKit }) sizeObject?.performBlockBase(onSize: size) - self.widthConstraint?.constant = digitWidth - self.heightConstraint?.constant = digitHeight +// self.widthConstraint?.constant = digitWidth +// self.heightConstraint?.constant = digitHeight self.previousSize = size } + + self.setNeedsLayout() } } diff --git a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift index d7533162..a705587d 100644 --- a/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DigitEntryField.swift @@ -16,6 +16,7 @@ import UIKit // MARK: - Outlets //-------------------------------------------------- + /// UI Container of digitFields public private(set) var digitFieldsStack: UIStackView? //-------------------------------------------------- @@ -29,7 +30,7 @@ import UIKit public override var isEnabled: Bool { didSet { - titleLabel.textColor = isEnabled ? .black : .black + titleLabel.textColor = isEnabled ? .black : .mfBattleshipGrey() for digitBox in digitFields { digitBox.isUserInteractionEnabled = isEnabled @@ -65,11 +66,11 @@ import UIKit feedback = "" } - if let feedback = feedback, !feedback.isEmpty { - feedbackContainerDistance?.constant = 10 - } else { - feedbackContainerDistance?.constant = 0 - } +// if let feedback = feedback, !feedback.isEmpty { +// feedbackContainerDistance?.constant = 10 +// } else { +// feedbackContainerDistance?.constant = 0 +// } /* * adding missing accessibilityLabel value @@ -109,7 +110,6 @@ import UIKit self.appearance = appearance isUserInteractionEnabled = true titleLabel.textColor = .mfBattleshipGrey() - hideBorder = false feedback = showError ? errorMessage : nil switch appearance { @@ -127,7 +127,6 @@ import UIKit case .lock: digitFields.forEach { $0.isUserInteractionEnabled = false - $0.hideBorder = true $0.bottomBar.backgroundColor = UIColor.clear.cgColor } case .select: @@ -143,8 +142,6 @@ import UIKit } titleLabel.textColor = self.isEnabled ? .mfBattleshipGrey() : .mfSilver() } - - refreshBorderUI(bottomBarSize: appearance == .error ? 4 : 1) } //-------------------------------------------------- @@ -160,19 +157,18 @@ import UIKit self.init(frame: .zero) } - public convenience init(numberOfDigits: Int) { - self.init(frame: .zero) + public init(numberOfDigits: Int) { + super.init(frame: .zero) self.numberOfDigits = numberOfDigits - buildTextFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth()) + setup() } public init(numberOfDigits: Int, bothDelegates delegate: (UITextFieldDelegate & TextFieldDelegate)?, size: CGFloat? = nil) { super.init(bothDelegates: delegate) - setup() self.numberOfDigits = numberOfDigits - buildTextFieldsView(size: size ?? MVMCoreUISplitViewController.getDetailViewWidth()) + setup() } required public init?(coder: NSCoder) { @@ -186,19 +182,23 @@ import UIKit open func setup() { - // Border for Field Container will not be shown. - hideBorder = true alignCenterHorizontal() isAccessibilityElement = false + hideBorder = true + bottomBar.backgroundColor = UIColor.clear.cgColor + bottomBar.frame = CGRect(x: 0, y: fieldContainer.bounds.height, width: 0, height: 0) + setupDigitFieldsView(size: MVMCoreUISplitViewController.getDetailViewWidth()) } open override func setupFieldContainerContent(_ container: UIView) { + // Will not be using textField. + // TODO: May subclass from FormEntry if minimal overriding. textField.removeFromSuperview() - setupTextFieldsView(forSize: CGFloat(numberOfDigits)) + setupDigitFieldsView(size: MVMCoreUIUtility.getWidth()) } - func createDigitField() -> DigitBox { + private func createDigitField() -> DigitBox { let textField = DigitBox() textField.isAccessibilityElement = true @@ -207,26 +207,49 @@ import UIKit return textField } - func buildTextFieldsView(size: CGFloat) { + func setupDigitFieldsView(size: CGFloat) { + + self.digitFieldsStack?.subviews.forEach { $0.removeFromSuperview() } + digitFieldsStack?.removeFromSuperview() var accessibleElements: [Any] = [titleLabel] - // Remove all current UI. - if !digitFields.isEmpty { - digitFieldsStack?.subviews.forEach { $0.removeFromSuperview() } + // Remove all current views in UI. + if let stackViews = digitFieldsStack?.subviews, !stackViews.isEmpty { + stackViews.forEach { $0.removeFromSuperview() } } if numberOfDigits > 0 { let digitFields = [DigitBox](repeating: createDigitField(), count: numberOfDigits) - - digitFields.forEach { - $0.updateView(size) - accessibleElements.append($0) - } - self.digitFields = digitFields - setupTextFieldsView(forSize: size) + guard let space = MFSizeObject(standardSize: 5, smalliPhoneSize: 3)?.getValueBasedOnScreenSize() else { return } + var prevBox: DigitBox? + + for (index, box) in digitFields.enumerated() { + // $0.updateView(size) + accessibleElements.append(box) + fieldContainer.addSubview(box) + + box.widthAnchor.constraint(equalToConstant: 39).isActive = true + box.heightAnchor.constraint(equalToConstant: 44).isActive = true + + box.topAnchor.constraint(equalTo: fieldContainer.topAnchor).isActive = true + fieldContainer.bottomAnchor.constraint(equalTo: box.bottomAnchor).isActive = true + + if index == 0 { + box.leadingAnchor.constraint(equalTo: fieldContainer.leadingAnchor).isActive = true + + } else if index == digitFields.count - 1 { + + box.leadingAnchor.constraint(equalTo: prevBox!.trailingAnchor, constant: space).isActive = true + fieldContainer.trailingAnchor.constraint(greaterThanOrEqualTo: box.trailingAnchor).isActive = true + } else { + box.leadingAnchor.constraint(equalTo: prevBox!.trailingAnchor).isActive = true + } + + prevBox = box + } } else { digitFields = [] } @@ -244,45 +267,37 @@ import UIKit DispatchQueue.main.async { [weak self] in guard let self = self else { return } - self.titleLabel.updateView(size) - if !self.digitFields.isEmpty { self.digitFieldsStack?.subviews.forEach { $0.removeFromSuperview() } self.digitFields.forEach { $0.updateView(size) } + self.layoutIfNeeded() } // Layout text boxes. - self.setupTextFieldsView(forSize: size) +// self.setupDigitFieldsView(size: size) } +// hideBorder = true } //-------------------------------------------------- // MARK: - Methods //-------------------------------------------------- - func removeError() { - - DispatchQueue.main.async { [weak self] in - guard let self = self else { return } - - self.digitFields.forEach { $0.showErrorState(false) } - } - } - override func valueChanged() { super.valueChanged() - DispatchQueue.main.async { [weak self] in - guard let self = self else { return } - - if let feedback = self.feedback, !feedback.isEmpty { - self.feedbackContainerDistance?.constant = 10 - - } else { - self.feedbackContainerDistance?.constant = 0 - } - } + // TODO: is feedbackContainerDistance needed? +// DispatchQueue.main.async { [weak self] in +// guard let self = self else { return } +// +// if let feedback = self.feedback, !feedback.isEmpty { +// self.feedbackContainerDistance?.constant = 10 +// +// } else { +// self.feedbackContainerDistance?.constant = 0 +// } +// } } func setAsSecureTextEntry(_ secureEntry: Bool) { @@ -299,17 +314,6 @@ import UIKit } } - func setupTextFieldsView(forSize size: CGFloat) { - - guard let space = MFSizeObject(standardSize: 5, smalliPhoneSize: 3)?.getValueBasedOnScreenSize() else { return } - - let stack = UIStackView(arrangedSubviews: digitFields) - self.digitFieldsStack = stack - textField.addSubview(stack) - stack.distribution = .equalSpacing - stack.spacing = space - } - public override func defaultValidationBlock() { validationBlock = { enteredValue in @@ -319,7 +323,7 @@ import UIKit } } - func selectPreviousTextField(_ currentTextField: UITextField?, clear: Bool) { + public func selectPreviousTextField(_ currentTextField: UITextField?, clear: Bool) { var selectNextField = false @@ -340,7 +344,7 @@ import UIKit } } - func selectNextTextField(_ currentTextField: UITextField?, clear: Bool) { + public func selectNextTextField(_ currentTextField: UITextField?, clear: Bool) { var selectNextField = false @@ -380,7 +384,7 @@ import UIKit } } - buildTextFieldsView(size: MVMCoreUIUtility.getWidth()) + setupDigitFieldsView(size: MVMCoreUIUtility.getWidth()) } open override class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { diff --git a/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift b/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift index 4d418ede..84f1d83f 100644 --- a/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift @@ -16,10 +16,8 @@ import UIKit let dropDownCaretView: CaretView = { let caret = CaretView() -// caret.size = .medium caret.direction = .down caret.lineWidth = 1.5 -// caret.isHidden = true caret.isUserInteractionEnabled = true caret.heightAnchor.constraint(equalToConstant: 9).isActive = true caret.widthAnchor.constraint(equalToConstant: 16).isActive = true @@ -162,7 +160,7 @@ extension DropdownEntryField { if let calendar = calendar, calendar.isDate(fromDate, inSameDayAs: Date()) { text = MVMCoreUIUtility.hardcodedString(withKey: "textfield_today_string") } else { - self.text = formatter.string(from: fromDate) + text = formatter.string(from: fromDate) } } diff --git a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift index c40042b3..275a2925 100644 --- a/MVMCoreUI/Atoms/TextFields/TextEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/TextEntryField.swift @@ -174,7 +174,6 @@ import UIKit open func clearErrorState() { /* - [MVMCoreDispatchUtility performBlockOnMainThread:^{ self.separatorHeightConstraint.constant = 1; self.separatorView.backgroundColor = [UIColor blackColor];