Merge branch 'bugfix/textfield_fixes' into 'develop'

Textfield fixes

See merge request BPHV_MIPS/mvm_core_ui!328
This commit is contained in:
Pan, Xinlei (Ryan) 2020-03-24 15:41:10 -04:00
commit 8fd2757501
6 changed files with 30 additions and 17 deletions

View File

@ -207,7 +207,7 @@ import UIKit
let digitBox = DigitBox()
digitBox.isAccessibilityElement = true
MVMCoreUICommonViewsUtility.addDismissToolbar(digitBox.digitField, delegate: self)
digitBox.digitField.inputAccessoryView = MVMCoreUICommonViewsUtility.getToolbarWithDoneButton(delegate: self)
digitBox.digitField.delegate = self
digitBox.digitBoxDelegate = self
return digitBox
@ -329,12 +329,10 @@ import UIKit
}
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
guard let model = model as? DigitEntryFieldModel else { return }
numberOfDigits = model.digits
setAsSecureTextEntry(model.secureEntry)
for digitBox in digitBoxes {

View File

@ -116,8 +116,7 @@ import UIKit
set (newFeedback) {
feedbackLabel.text = newFeedback
feedbackLabel.accessibilityElementsHidden = feedbackLabel.text?.isEmpty ?? true
entryFieldContainer.refreshUI()
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
entryFieldContainer.refreshUI(updateMoleculeLayout: true)
}
}

View File

@ -49,6 +49,10 @@ import UIKit
/// Validate when user resigns editing. Default: true
public var validateWhenDoneEditing: Bool = true
public var textEntryFieldModel: TextEntryFieldModel? {
return model as? TextEntryFieldModel
}
//--------------------------------------------------
// MARK: - Computed Properties
@ -87,7 +91,7 @@ import UIKit
get { return textField.text }
set {
textField.text = newValue
(model as? TextEntryFieldModel)?.text = newValue
textEntryFieldModel?.text = newValue
}
}
@ -167,7 +171,8 @@ import UIKit
textField.heightAnchor.constraint(equalToConstant: 24),
textField.topAnchor.constraint(equalTo: container.topAnchor, constant: 12),
textField.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 16),
container.bottomAnchor.constraint(equalTo: textField.bottomAnchor, constant: 12)])
container.bottomAnchor.constraint(equalTo: textField.bottomAnchor, constant: 12)
])
textFieldTrailingConstraint = container.trailingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 16)
textFieldTrailingConstraint?.isActive = true
@ -366,7 +371,6 @@ extension TextEntryField {
defaultValidationBlock()
}
uiTextFieldDelegate = delegateObject.uiTextFieldDelegate
observingTextFieldDelegate = delegateObject.observingTextFieldDelegate
MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: uiTextFieldDelegate)

View File

@ -36,7 +36,7 @@ import UIKit
/// Checks if the screen width has changed
open func screenSizeChanged() -> Bool {
return MVMCoreGetterUtility.cgfequalwiththreshold(previousScreenSize.width, view.bounds.size.width, 0.1)
return !MVMCoreGetterUtility.cgfequalwiththreshold(previousScreenSize.width, view.bounds.size.width, 0.1)
}
// MARK: - Response handling
@ -276,17 +276,18 @@ import UIKit
open override func viewDidLayoutSubviews() {
// Add to fix a constraint bug where the width is zero and things get messed up.
guard isViewLoaded,
view.bounds.width > 1 else {
super.viewDidLayoutSubviews()
return
guard isViewLoaded, view.bounds.width > 1 else {
super.viewDidLayoutSubviews()
return
}
if needsUpdateUI || screenSizeChanged() {
updateViews()
needsUpdateUI = false
}
previousScreenSize = view.bounds.size;
super.viewDidLayoutSubviews()
}

View File

@ -260,13 +260,21 @@ import UIKit
refreshUI(bottomBarSize: 1)
}
open func refreshUI(bottomBarSize: CGFloat? = nil) {
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
}
bottomBar?.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size)
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
if updateMoleculeLayout || heightChanged {
delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}
setNeedsDisplay()
layoutIfNeeded()
}

View File

@ -9,12 +9,15 @@
import Foundation
public extension MVMCoreUICommonViewsUtility {
static func getToolbarWithDoneButton(delegate: ObservingTextFieldDelegate) -> UIToolbar {
let toolbar = self.makeEmptyToolbar()
let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let button = UIBarButtonItem(barButtonSystemItem: .done, target: delegate, action: #selector(ObservingTextFieldDelegate.dismissFieldInput(sender:)))
button.tintColor = .black
toolbar.setItems([space, button], animated: false)
return toolbar
}
}