further developmet of textView.

This commit is contained in:
Kevin G Christiano 2020-04-29 10:35:00 -04:00
parent 67b8656d63
commit 5f38596994
3 changed files with 26 additions and 51 deletions

View File

@ -38,7 +38,6 @@
//-------------------------------------------------- //--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName
case placeholder case placeholder
case enabledTextColor case enabledTextColor
case disabledTextColor case disabledTextColor
@ -67,7 +66,6 @@
public override func encode(to encoder: Encoder) throws { public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder) try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(placeholder, forKey: .placeholder) try container.encodeIfPresent(placeholder, forKey: .placeholder)
try container.encode(enabledTextColor, forKey: .enabledTextColor) try container.encode(enabledTextColor, forKey: .enabledTextColor)
try container.encode(disabledTextColor, forKey: .disabledTextColor) try container.encode(disabledTextColor, forKey: .disabledTextColor)

View File

@ -19,7 +19,10 @@ import UIKit
private var initialSetupPerformed = false private var initialSetupPerformed = false
/// If true then text textView is currently displaying the stored placeholder text as there is not content to display. /// If true then text textView is currently displaying the stored placeholder text as there is not content to display.
public var isShowingPlaceholder = true public var isShowingPlaceholder: Bool {
get { return textViewModel?.showsPlaceholder ?? false }
set { textViewModel?.showsPlaceholder = newValue }
}
/// Set to true to hide the blinking textField cursor. /// Set to true to hide the blinking textField cursor.
public var hideBlinkingCaret = false public var hideBlinkingCaret = false
@ -62,7 +65,6 @@ import UIKit
private var _isEnabled: Bool = true private var _isEnabled: Bool = true
private var _showError: Bool = false private var _showError: Bool = false
private var _isLocked: Bool = false
private var _isSelected: Bool = false private var _isSelected: Bool = false
public var isEnabled: Bool { public var isEnabled: Bool {
@ -70,7 +72,6 @@ import UIKit
set (enabled) { set (enabled) {
_isEnabled = enabled _isEnabled = enabled
_isLocked = false
_isSelected = false _isSelected = false
_showError = false _showError = false
@ -84,32 +85,17 @@ import UIKit
_showError = error _showError = error
_isEnabled = true _isEnabled = true
_isLocked = false
_isSelected = false _isSelected = false
fieldState = error ? .error : .original fieldState = error ? .error : .original
} }
} }
public var isLocked: Bool {
get { return _isLocked }
set (locked) {
_isLocked = locked
_isEnabled = true
_isSelected = false
_showError = false
fieldState = locked ? .locked : .original
}
}
public var isSelected: Bool { public var isSelected: Bool {
get { return _isSelected } get { return _isSelected }
set (selected) { set (selected) {
_isSelected = selected _isSelected = selected
_isLocked = false
_isEnabled = true _isEnabled = true
if _showError { if _showError {
@ -269,7 +255,6 @@ import UIKit
case error case error
case selectedError case selectedError
case selected case selected
case locked
case disabled case disabled
public func setStateUI(for inputField: TextView) { public func setStateUI(for inputField: TextView) {
@ -287,9 +272,6 @@ import UIKit
case .selected: case .selected:
inputField.selectedUI() inputField.selectedUI()
case .locked:
inputField.lockedUI()
case .disabled: case .disabled:
inputField.disabledUI() inputField.disabledUI()
} }
@ -300,50 +282,52 @@ import UIKit
open func originalUI() { open func originalUI() {
isEditable = true isEditable = textViewModel?.isEditable ?? true
isUserInteractionEnabled = true
hideBorders = false hideBorders = false
borderStrokeColor = .mvmCoolGray3 borderStrokeColor = .mvmCoolGray3
bottomStrokeColor = .mvmBlack bottomStrokeColor = .mvmBlack
textColor = textViewModel?.enabledTextColor.uiColor
} }
open func errorUI() { open func errorUI() {
isEditable = true isEditable = textViewModel?.isEditable ?? true
isUserInteractionEnabled = true
hideBorders = false hideBorders = false
borderStrokeColor = .mvmOrange borderStrokeColor = .mvmOrange
bottomStrokeColor = .mvmOrange bottomStrokeColor = .mvmOrange
textColor = textViewModel?.enabledTextColor.uiColor
} }
open func selectedErrorUI() { open func selectedErrorUI() {
isEditable = true isEditable = textViewModel?.isEditable ?? true
isUserInteractionEnabled = true
hideBorders = false hideBorders = false
borderStrokeColor = .mvmBlack borderStrokeColor = .mvmBlack
bottomStrokeColor = .mvmOrange bottomStrokeColor = .mvmOrange
textColor = textViewModel?.enabledTextColor.uiColor
} }
open func selectedUI() { open func selectedUI() {
isEditable = true isEditable = textViewModel?.isEditable ?? true
isUserInteractionEnabled = true
hideBorders = false hideBorders = false
borderStrokeColor = .mvmBlack borderStrokeColor = .mvmBlack
bottomStrokeColor = .mvmBlack bottomStrokeColor = .mvmBlack
} textColor = textViewModel?.enabledTextColor.uiColor
open func lockedUI() {
isEditable = false
hideBorders = true
borderStrokeColor = .clear
bottomStrokeColor = .clear
} }
open func disabledUI() { open func disabledUI() {
isEditable = false isEditable = textViewModel?.isEditable ?? false
isUserInteractionEnabled = false
hideBorders = false hideBorders = false
borderStrokeColor = .mvmCoolGray3 borderStrokeColor = .mvmCoolGray3
bottomStrokeColor = .mvmCoolGray3 bottomStrokeColor = .mvmCoolGray3
textColor = textViewModel?.disabledTextColor.uiColor
} }
//-------------------------------------------------- //--------------------------------------------------
@ -385,7 +369,7 @@ import UIKit
isShowingPlaceholder = false isShowingPlaceholder = false
text = "" text = ""
font = textViewModel?.fontStyle.getFont() font = textViewModel?.fontStyle.getFont()
textColor = textViewModel?.textColor.uiColor textColor = textViewModel?.enabledTextColor.uiColor
} }
public func setPlaceholderContentTraits() { public func setPlaceholderContentTraits() {
@ -457,10 +441,9 @@ extension TextView: MoleculeViewProtocol {
isEditable = model.isEditable isEditable = model.isEditable
textAlignment = model.textAlignment textAlignment = model.textAlignment
textColor = model.textColor.uiColor textColor = model.enabledTextColor.uiColor
text = model.text text = model.text
uiTextViewDelegate = delegateObject?.uiTextViewDelegate uiTextViewDelegate = delegateObject?.uiTextViewDelegate
isShowingPlaceholder = model.text?.isEmpty ?? false
if let accessibilityText = model.accessibilityText { if let accessibilityText = model.accessibilityText {
accessibilityLabel = accessibilityText accessibilityLabel = accessibilityText
@ -480,5 +463,9 @@ extension TextView: MoleculeViewProtocol {
} }
} }
} }
if !model.enabled {
isEnabled = false
}
} }
} }

View File

@ -19,13 +19,12 @@ open class TextViewModel: TextEntryFieldModel {
} }
public var accessibilityText: String? public var accessibilityText: String?
public var textColor: Color = Color(uiColor: .mvmBlack)
public var fontStyle: Styler.Font = Styler.Font.RegularBodySmall public var fontStyle: Styler.Font = Styler.Font.RegularBodySmall
public var textAlignment: NSTextAlignment = .left public var textAlignment: NSTextAlignment = .left
public var height: CGFloat? public var height: CGFloat?
public var placeholderTextColor: Color = Color(uiColor: .mvmCoolGray3) public var placeholderTextColor: Color = Color(uiColor: .mvmCoolGray3)
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 = false
public var isEditable: Bool = true public var isEditable: Bool = true
//-------------------------------------------------- //--------------------------------------------------
@ -33,11 +32,8 @@ open class TextViewModel: TextEntryFieldModel {
//-------------------------------------------------- //--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName
case backgroundColor
case text case text
case accessibilityText case accessibilityText
case textColor
case fontStyle case fontStyle
case textAlignment case textAlignment
case height case height
@ -61,10 +57,6 @@ open class TextViewModel: TextEntryFieldModel {
self.textAlignment = textAlignment self.textAlignment = textAlignment
} }
if let textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) {
self.textColor = textColor
}
if let isEditable = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEditable) { if let isEditable = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEditable) {
self.isEditable = isEditable self.isEditable = isEditable
} }
@ -79,9 +71,7 @@ open class TextViewModel: TextEntryFieldModel {
public override func encode(to encoder: Encoder) throws { public override func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText)
try container.encodeIfPresent(textColor, forKey: .textColor)
try container.encodeIfPresent(fontStyle, forKey: .fontStyle) try container.encodeIfPresent(fontStyle, forKey: .fontStyle)
try container.encodeIfPresent(height, forKey: .height) try container.encodeIfPresent(height, forKey: .height)
try container.encode(text, forKey: .text) try container.encode(text, forKey: .text)