fixed resue issue

This commit is contained in:
Kevin G Christiano 2020-05-13 12:07:33 -04:00
parent 268ee222bb
commit e5ac0127d1
3 changed files with 40 additions and 14 deletions

View File

@ -82,8 +82,9 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
public var placeholder: String? { public var placeholder: String? {
get { return textViewEntryFieldModel?.placeholder } get { return textViewEntryFieldModel?.placeholder }
set { set {
textViewEntryFieldModel?.placeholder = newValue
textView.placeholder = newValue ?? "" textView.placeholder = newValue ?? ""
textViewEntryFieldModel?.placeholder = newValue
textView.setPlaceholderIfAvailable()
} }
} }
@ -92,6 +93,19 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
//-------------------------------------------------- //--------------------------------------------------
public var heightConstraint: NSLayoutConstraint? public var heightConstraint: NSLayoutConstraint?
private var topConstraint: NSLayoutConstraint?
private var leadingConstraint: NSLayoutConstraint?
private var trailingConstraint: NSLayoutConstraint?
private var bottomConstraint: NSLayoutConstraint?
private func adjustMarginConstraints(constant: CGFloat) {
topConstraint?.constant = constant
leadingConstraint?.constant = constant
trailingConstraint?.constant = constant
bottomConstraint?.constant = constant
layoutIfNeeded()
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Delegate Properties // MARK: - Delegate Properties
@ -139,14 +153,17 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
@objc open override func setupFieldContainerContent(_ container: UIView) { @objc open override func setupFieldContainerContent(_ container: UIView) {
container.addSubview(textView) container.addSubview(textView)
NSLayoutConstraint.activate([ topConstraint = textView.topAnchor.constraint(equalTo: container.topAnchor, constant: Padding.Three)
textView.topAnchor.constraint(equalTo: container.topAnchor, constant: Padding.Three), leadingConstraint = textView.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: Padding.Three)
textView.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: Padding.Three), trailingConstraint = container.trailingAnchor.constraint(equalTo: textView.trailingAnchor, constant: Padding.Three)
container.trailingAnchor.constraint(equalTo: textView.trailingAnchor, constant: Padding.Three), bottomConstraint = container.bottomAnchor.constraint(equalTo: textView.bottomAnchor, constant: Padding.Three)
container.bottomAnchor.constraint(equalTo: textView.bottomAnchor, constant: Padding.Three)
]) topConstraint?.isActive = true
leadingConstraint?.isActive = true
trailingConstraint?.isActive = true
bottomConstraint?.isActive = true
heightConstraint = textView.heightAnchor.constraint(equalToConstant: 0) heightConstraint = textView.heightAnchor.constraint(equalToConstant: 0)
accessibilityElements = [titleLabel, textView, feedbackLabel] accessibilityElements = [titleLabel, textView, feedbackLabel]
} }
@ -160,6 +177,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
super.reset() super.reset()
textView.reset() textView.reset()
adjustMarginConstraints(constant: Padding.Three)
heightConstraint?.constant = 0 heightConstraint?.constant = 0
heightConstraint?.isActive = false heightConstraint?.isActive = false
} }
@ -224,7 +242,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
textView.placeholder = model.placeholder ?? "" textView.placeholder = model.placeholder ?? ""
textView.placeholderFontStyle = model.placeholderFontStyle textView.placeholderFontStyle = model.placeholderFontStyle
textView.placeholderTextColor = model.placeholderTextColor.uiColor textView.placeholderTextColor = model.placeholderTextColor.uiColor
textView.setPlaceholderIfAvailable()
switch model.type { switch model.type {
case .secure, .password: case .secure, .password:
@ -251,8 +269,13 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
} }
} }
if !model.enabled { if model.hideBorders {
isEnabled = false adjustMarginConstraints(constant: 0)
} }
textView.setPlaceholderIfAvailable()
// if !model.enabled {
// isEnabled = false
// }
} }
} }

View File

@ -19,7 +19,7 @@ class TextViewEntryFieldModel: TextEntryFieldModel {
} }
public var accessibilityText: String? public var accessibilityText: String?
public var fontStyle: Styler.Font = Styler.Font.RegularBodySmall public var fontStyle: Styler.Font = Styler.Font.RegularBodyLarge
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

View File

@ -72,7 +72,7 @@ import UIKit
} }
open func updateView(_ size: CGFloat) { open func updateView(_ size: CGFloat) {
font = fontStyle.getFont() font = (isShowingPlaceholder ? placeholderFontStyle : fontStyle).getFont()
} }
/// Will be called only once. /// Will be called only once.
@ -109,7 +109,10 @@ import UIKit
fontStyle = Styler.Font.RegularBodyLarge fontStyle = Styler.Font.RegularBodyLarge
placeholderFontStyle = Styler.Font.RegularMicro placeholderFontStyle = Styler.Font.RegularMicro
placeholderTextColor = .mvmCoolGray3 placeholderTextColor = .mvmCoolGray3
textColor = .mvmBlack
isEnabled = true isEnabled = true
text = ""
isShowingPlaceholder = false
inputAccessoryView?.removeFromSuperview() inputAccessoryView?.removeFromSuperview()
defaultConfiguration() defaultConfiguration()
} }