little fixes and delegate updates.

This commit is contained in:
Kevin G Christiano 2020-04-29 09:08:08 -04:00
parent 2a251649af
commit 67b8656d63
4 changed files with 33 additions and 63 deletions

View File

@ -125,7 +125,7 @@ import UIKit
updateView(MVMCoreUIUtility.getWidth()) updateView(MVMCoreUIUtility.getWidth())
} }
@objc public func textFieldDidDelete() { @objc public func textInputDidDelete() {
digitBoxDelegate?.digitFieldDidDelete?(digitField) digitBoxDelegate?.digitFieldDidDelete?(digitField)
} }

View File

@ -9,7 +9,7 @@
import UIKit import UIKit
public protocol TextInputDidDeleteProtocol: class { public protocol TextInputDidDeleteProtocol: class {
func textFieldDidDelete() func textInputDidDelete()
} }
@ -69,7 +69,7 @@ public protocol TextInputDidDeleteProtocol: class {
open override func deleteBackward() { open override func deleteBackward() {
super.deleteBackward() super.deleteBackward()
didDeleteDelegate?.textFieldDidDelete() didDeleteDelegate?.textInputDidDelete()
} }
} }

View File

@ -185,17 +185,22 @@ import UIKit
open func updateView(_ size: CGFloat) { open func updateView(_ size: CGFloat) {
refreshUI() setNeedsDisplay()
} }
/// Will be called only once. /// Will be called only once.
open func setupView() { open func setupView() {
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
initialConfiguration()
}
public func initialConfiguration() {
insetsLayoutMarginsFromSafeArea = false insetsLayoutMarginsFromSafeArea = false
showsVerticalScrollIndicator = false showsVerticalScrollIndicator = false
showsHorizontalScrollIndicator = false showsHorizontalScrollIndicator = false
contentInset = UIEdgeInsets(top: Padding.Three, left: Padding.Three, bottom: Padding.Three, right: Padding.Three) textContainerInset = UIEdgeInsets(top: Padding.Three, left: Padding.Three, bottom: Padding.Three, right: Padding.Three)
backgroundColor = .mvmWhite backgroundColor = .mvmWhite
clipsToBounds = true clipsToBounds = true
smartQuotesType = .no smartQuotesType = .no
@ -208,16 +213,15 @@ import UIKit
open func reset() { open func reset() {
backgroundColor = .mvmWhite
text = "" text = ""
inputAccessoryView?.removeFromSuperview() inputAccessoryView?.removeFromSuperview()
contentInset = UIEdgeInsets(top: Padding.Three, left: Padding.Three, bottom: Padding.Three, right: Padding.Three) initialConfiguration()
} }
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
refreshUI(bottomBarSize: showError ? 4 : 1) setNeedsDisplay()
} }
//-------------------------------------------------- //--------------------------------------------------
@ -246,9 +250,10 @@ import UIKit
borderStrokeColor.setStroke() borderStrokeColor.setStroke()
borderPath.stroke() borderPath.stroke()
bottomPath.lineWidth = 4 let lineWidth: CGFloat = showError || isSelected ? 4 : 1
bottomPath.move(to: CGPoint(x: origin.x + size.width, y: origin.y + size.height - 2)) bottomPath.lineWidth = lineWidth
bottomPath.addLine(to: CGPoint(x: origin.x, y: origin.y + size.height - 2)) bottomPath.move(to: CGPoint(x: origin.x + size.width, y: origin.y + size.height - (lineWidth / 2)))
bottomPath.addLine(to: CGPoint(x: origin.x, y: origin.y + size.height - (lineWidth / 2)))
bottomStrokeColor.setStroke() bottomStrokeColor.setStroke()
bottomPath.stroke() bottomPath.stroke()
@ -267,27 +272,29 @@ import UIKit
case locked case locked
case disabled case disabled
public func setStateUI(for formField: TextView) { public func setStateUI(for inputField: TextView) {
switch self { switch self {
case .original: case .original:
formField.originalUI() inputField.originalUI()
case .error: case .error:
formField.errorUI() inputField.errorUI()
case .selectedError: case .selectedError:
formField.selectedErrorUI() inputField.selectedErrorUI()
case .selected: case .selected:
formField.selectedUI() inputField.selectedUI()
case .locked: case .locked:
formField.lockedUI() inputField.lockedUI()
case .disabled: case .disabled:
formField.disabledUI() inputField.disabledUI()
} }
inputField.setNeedsDisplay()
} }
} }
@ -297,7 +304,6 @@ import UIKit
hideBorders = false hideBorders = false
borderStrokeColor = .mvmCoolGray3 borderStrokeColor = .mvmCoolGray3
bottomStrokeColor = .mvmBlack bottomStrokeColor = .mvmBlack
refreshUI(bottomBarSize: 1)
} }
open func errorUI() { open func errorUI() {
@ -306,7 +312,6 @@ import UIKit
hideBorders = false hideBorders = false
borderStrokeColor = .mvmOrange borderStrokeColor = .mvmOrange
bottomStrokeColor = .mvmOrange bottomStrokeColor = .mvmOrange
refreshUI(bottomBarSize: 4)
} }
open func selectedErrorUI() { open func selectedErrorUI() {
@ -315,7 +320,6 @@ import UIKit
hideBorders = false hideBorders = false
borderStrokeColor = .mvmBlack borderStrokeColor = .mvmBlack
bottomStrokeColor = .mvmOrange bottomStrokeColor = .mvmOrange
refreshUI(bottomBarSize: 4)
} }
open func selectedUI() { open func selectedUI() {
@ -324,7 +328,6 @@ import UIKit
hideBorders = false hideBorders = false
borderStrokeColor = .mvmBlack borderStrokeColor = .mvmBlack
bottomStrokeColor = .mvmBlack bottomStrokeColor = .mvmBlack
refreshUI(bottomBarSize: 1)
} }
open func lockedUI() { open func lockedUI() {
@ -333,7 +336,6 @@ import UIKit
hideBorders = true hideBorders = true
borderStrokeColor = .clear borderStrokeColor = .clear
bottomStrokeColor = .clear bottomStrokeColor = .clear
refreshUI(bottomBarSize: 1)
} }
open func disabledUI() { open func disabledUI() {
@ -342,26 +344,6 @@ import UIKit
hideBorders = false hideBorders = false
borderStrokeColor = .mvmCoolGray3 borderStrokeColor = .mvmCoolGray3
bottomStrokeColor = .mvmCoolGray3 bottomStrokeColor = .mvmCoolGray3
refreshUI(bottomBarSize: 1)
}
open func refreshUI(bottomBarSize: CGFloat? = nil, updateMoleculeLayout: Bool = false) {
if !disableAllBorders {
// let size: CGFloat = bottomBarSize ?? (showError ? 4 : 1)
// var heightChanged = false
// if let bottomHeight = bottomBar?.bounds.height {
// heightChanged = size != bottomHeight
// }
if updateMoleculeLayout {//|| heightChanged {
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}
setNeedsDisplay()
layoutIfNeeded()
}
} }
//-------------------------------------------------- //--------------------------------------------------
@ -381,7 +363,7 @@ import UIKit
open override func deleteBackward() { open override func deleteBackward() {
super.deleteBackward() super.deleteBackward()
didDeleteDelegate?.textFieldDidDelete() didDeleteDelegate?.textInputDidDelete()
} }
public func setTextAppearance() { public func setTextAppearance() {
@ -425,6 +407,7 @@ import UIKit
@objc public func textViewDidBeginEditing(_ textView: UITextView) { @objc public func textViewDidBeginEditing(_ textView: UITextView) {
isSelected = true
setTextAppearance() setTextAppearance()
proprietorTextDelegate?.textViewDidBeginEditing?(textView) proprietorTextDelegate?.textViewDidBeginEditing?(textView)
} }
@ -447,6 +430,7 @@ import UIKit
@objc public func textViewDidEndEditing(_ textView: UITextView) { @objc public func textViewDidEndEditing(_ textView: UITextView) {
isSelected = false
setPlaceholderIfAvailable() setPlaceholderIfAvailable()
proprietorTextDelegate?.textViewDidEndEditing?(textView) proprietorTextDelegate?.textViewDidEndEditing?(textView)
} }
@ -476,7 +460,7 @@ extension TextView: MoleculeViewProtocol {
textColor = model.textColor.uiColor textColor = model.textColor.uiColor
text = model.text text = model.text
uiTextViewDelegate = delegateObject?.uiTextViewDelegate uiTextViewDelegate = delegateObject?.uiTextViewDelegate
isShowingPlaceholder = model.text!.isEmpty isShowingPlaceholder = model.text?.isEmpty ?? false
if let accessibilityText = model.accessibilityText { if let accessibilityText = model.accessibilityText {
accessibilityLabel = accessibilityText accessibilityLabel = accessibilityText
@ -490,9 +474,10 @@ extension TextView: MoleculeViewProtocol {
MVMCoreUICommonViewsUtility.addDismissToolbar(to: self, delegate: delegateObject?.uiTextViewDelegate) MVMCoreUICommonViewsUtility.addDismissToolbar(to: self, delegate: delegateObject?.uiTextViewDelegate)
if model.selected ?? false { if model.selected ?? false {
isSelected = true
model.wasInitiallySelected = true model.wasInitiallySelected = true
becomeFirstResponder() DispatchQueue.main.async {
self.becomeFirstResponder()
}
} }
} }
} }

View File

@ -27,8 +27,6 @@ open class TextViewModel: TextEntryFieldModel {
public var placeholderFontStyle: Styler.Font = Styler.Font.RegularMicro public var placeholderFontStyle: Styler.Font = Styler.Font.RegularMicro
public var showsPlaceholder: Bool = true public var showsPlaceholder: Bool = true
public var isEditable: Bool = true public var isEditable: Bool = true
// public var borderColor: Color?
// public var borderWidth: CGFloat = 0
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Keys // MARK: - Keys
@ -42,14 +40,9 @@ open class TextViewModel: TextEntryFieldModel {
case textColor case textColor
case fontStyle case fontStyle
case textAlignment case textAlignment
case attributes
case height case height
// case borderColor
// case borderWidth
// case placeholder
case placeholderFontStyle case placeholderFontStyle
case isEditable = "editable" case isEditable = "editable"
// case hideBlinkingCaret
} }
//-------------------------------------------------- //--------------------------------------------------
@ -76,15 +69,10 @@ open class TextViewModel: TextEntryFieldModel {
self.isEditable = isEditable self.isEditable = isEditable
} }
// if let borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) {
// self.borderWidth = borderWidth
// }
if let fontStyle = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .fontStyle) { if let fontStyle = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .fontStyle) {
self.fontStyle = fontStyle self.fontStyle = fontStyle
} }
// borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor)
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height)
} }
@ -95,13 +83,10 @@ open class TextViewModel: TextEntryFieldModel {
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
try container.encodeIfPresent(textColor, forKey: .textColor) try container.encodeIfPresent(textColor, forKey: .textColor)
try container.encodeIfPresent(fontStyle, forKey: .fontStyle) try container.encodeIfPresent(fontStyle, forKey: .fontStyle)
// try container.encodeIfPresent(borderColor, forKey: .borderColor)
try container.encodeIfPresent(height, forKey: .height) try container.encodeIfPresent(height, forKey: .height)
try container.encode(text, forKey: .text) try container.encode(text, forKey: .text)
// try container.encode(placeholder, forKey: .placeholder)
try container.encode(placeholderFontStyle, forKey: .placeholderFontStyle) try container.encode(placeholderFontStyle, forKey: .placeholderFontStyle)
try container.encode(textAlignment, forKey: .textAlignment) try container.encode(textAlignment, forKey: .textAlignment)
try container.encode(isEditable, forKey: .isEditable) try container.encode(isEditable, forKey: .isEditable)
// try container.encode(borderWidth, forKey: .borderWidth)
} }
} }