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())
}
@objc public func textFieldDidDelete() {
@objc public func textInputDidDelete() {
digitBoxDelegate?.digitFieldDidDelete?(digitField)
}

View File

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

View File

@ -185,17 +185,22 @@ import UIKit
open func updateView(_ size: CGFloat) {
refreshUI()
setNeedsDisplay()
}
/// Will be called only once.
open func setupView() {
translatesAutoresizingMaskIntoConstraints = false
initialConfiguration()
}
public func initialConfiguration() {
insetsLayoutMarginsFromSafeArea = false
showsVerticalScrollIndicator = 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
clipsToBounds = true
smartQuotesType = .no
@ -208,16 +213,15 @@ import UIKit
open func reset() {
backgroundColor = .mvmWhite
text = ""
inputAccessoryView?.removeFromSuperview()
contentInset = UIEdgeInsets(top: Padding.Three, left: Padding.Three, bottom: Padding.Three, right: Padding.Three)
initialConfiguration()
}
open override func layoutSubviews() {
super.layoutSubviews()
refreshUI(bottomBarSize: showError ? 4 : 1)
setNeedsDisplay()
}
//--------------------------------------------------
@ -246,9 +250,10 @@ import UIKit
borderStrokeColor.setStroke()
borderPath.stroke()
bottomPath.lineWidth = 4
bottomPath.move(to: CGPoint(x: origin.x + size.width, y: origin.y + size.height - 2))
bottomPath.addLine(to: CGPoint(x: origin.x, y: origin.y + size.height - 2))
let lineWidth: CGFloat = showError || isSelected ? 4 : 1
bottomPath.lineWidth = lineWidth
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()
bottomPath.stroke()
@ -267,27 +272,29 @@ import UIKit
case locked
case disabled
public func setStateUI(for formField: TextView) {
public func setStateUI(for inputField: TextView) {
switch self {
case .original:
formField.originalUI()
inputField.originalUI()
case .error:
formField.errorUI()
inputField.errorUI()
case .selectedError:
formField.selectedErrorUI()
inputField.selectedErrorUI()
case .selected:
formField.selectedUI()
inputField.selectedUI()
case .locked:
formField.lockedUI()
inputField.lockedUI()
case .disabled:
formField.disabledUI()
inputField.disabledUI()
}
inputField.setNeedsDisplay()
}
}
@ -297,7 +304,6 @@ import UIKit
hideBorders = false
borderStrokeColor = .mvmCoolGray3
bottomStrokeColor = .mvmBlack
refreshUI(bottomBarSize: 1)
}
open func errorUI() {
@ -306,7 +312,6 @@ import UIKit
hideBorders = false
borderStrokeColor = .mvmOrange
bottomStrokeColor = .mvmOrange
refreshUI(bottomBarSize: 4)
}
open func selectedErrorUI() {
@ -315,7 +320,6 @@ import UIKit
hideBorders = false
borderStrokeColor = .mvmBlack
bottomStrokeColor = .mvmOrange
refreshUI(bottomBarSize: 4)
}
open func selectedUI() {
@ -324,7 +328,6 @@ import UIKit
hideBorders = false
borderStrokeColor = .mvmBlack
bottomStrokeColor = .mvmBlack
refreshUI(bottomBarSize: 1)
}
open func lockedUI() {
@ -333,7 +336,6 @@ import UIKit
hideBorders = true
borderStrokeColor = .clear
bottomStrokeColor = .clear
refreshUI(bottomBarSize: 1)
}
open func disabledUI() {
@ -342,26 +344,6 @@ import UIKit
hideBorders = false
borderStrokeColor = .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() {
super.deleteBackward()
didDeleteDelegate?.textFieldDidDelete()
didDeleteDelegate?.textInputDidDelete()
}
public func setTextAppearance() {
@ -425,6 +407,7 @@ import UIKit
@objc public func textViewDidBeginEditing(_ textView: UITextView) {
isSelected = true
setTextAppearance()
proprietorTextDelegate?.textViewDidBeginEditing?(textView)
}
@ -447,6 +430,7 @@ import UIKit
@objc public func textViewDidEndEditing(_ textView: UITextView) {
isSelected = false
setPlaceholderIfAvailable()
proprietorTextDelegate?.textViewDidEndEditing?(textView)
}
@ -476,7 +460,7 @@ extension TextView: MoleculeViewProtocol {
textColor = model.textColor.uiColor
text = model.text
uiTextViewDelegate = delegateObject?.uiTextViewDelegate
isShowingPlaceholder = model.text!.isEmpty
isShowingPlaceholder = model.text?.isEmpty ?? false
if let accessibilityText = model.accessibilityText {
accessibilityLabel = accessibilityText
@ -490,9 +474,10 @@ extension TextView: MoleculeViewProtocol {
MVMCoreUICommonViewsUtility.addDismissToolbar(to: self, delegate: delegateObject?.uiTextViewDelegate)
if model.selected ?? false {
isSelected = 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 showsPlaceholder: Bool = true
public var isEditable: Bool = true
// public var borderColor: Color?
// public var borderWidth: CGFloat = 0
//--------------------------------------------------
// MARK: - Keys
@ -42,14 +40,9 @@ open class TextViewModel: TextEntryFieldModel {
case textColor
case fontStyle
case textAlignment
case attributes
case height
// case borderColor
// case borderWidth
// case placeholder
case placeholderFontStyle
case isEditable = "editable"
// case hideBlinkingCaret
}
//--------------------------------------------------
@ -76,15 +69,10 @@ open class TextViewModel: TextEntryFieldModel {
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) {
self.fontStyle = fontStyle
}
// borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor)
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
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(textColor, forKey: .textColor)
try container.encodeIfPresent(fontStyle, forKey: .fontStyle)
// try container.encodeIfPresent(borderColor, forKey: .borderColor)
try container.encodeIfPresent(height, forKey: .height)
try container.encode(text, forKey: .text)
// try container.encode(placeholder, forKey: .placeholder)
try container.encode(placeholderFontStyle, forKey: .placeholderFontStyle)
try container.encode(textAlignment, forKey: .textAlignment)
try container.encode(isEditable, forKey: .isEditable)
// try container.encode(borderWidth, forKey: .borderWidth)
}
}