code review
This commit is contained in:
parent
d0ac49663a
commit
63f02a0c7c
@ -709,21 +709,6 @@
|
|||||||
[self setEnabledByValidity];
|
[self setEnabledByValidity];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addTextFieldsForValidation:(nonnull MFTextField *)textField {
|
|
||||||
if (self.textFields == nil) {
|
|
||||||
self.textFields = [NSMutableArray array];
|
|
||||||
}
|
|
||||||
if (textField) {
|
|
||||||
[self.textFields addObject:textField];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MFTextField *field in self.textFields) {
|
|
||||||
field.mfTextFieldDelegate = self;
|
|
||||||
[field setDefaultValidationBlock];
|
|
||||||
}
|
|
||||||
[self setEnabledByValidity];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)handleEnablingWithTextFields:(nullable NSArray <MFTextField *>*)textFields {
|
- (void)handleEnablingWithTextFields:(nullable NSArray <MFTextField *>*)textFields {
|
||||||
|
|
||||||
if (self.textFields) {
|
if (self.textFields) {
|
||||||
@ -758,9 +743,8 @@
|
|||||||
|
|
||||||
#pragma mark - FormValidationProtocol
|
#pragma mark - FormValidationProtocol
|
||||||
|
|
||||||
- (void)enableField:(BOOL) enable {
|
- (void)enableField:(BOOL)enable {
|
||||||
|
if (!self.validationRequired) {
|
||||||
if (self.validationRequired == NO) {
|
|
||||||
self.enabled = YES;
|
self.enabled = YES;
|
||||||
} else {
|
} else {
|
||||||
self.enabled = enable;
|
self.enabled = enable;
|
||||||
|
|||||||
@ -51,10 +51,9 @@
|
|||||||
[self.dashLine updateView:size];
|
[self.dashLine updateView:size];
|
||||||
|
|
||||||
if (self.isMolecule) {
|
if (self.isMolecule) {
|
||||||
[self setVerticalPadding:[MFStyler defaultHorizontalPaddingForApplicationWidth]];
|
[self setHorizontalPadding:[MFStyler defaultHorizontalPaddingForSize:size]];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
[self setVerticalPadding:0];
|
[self setHorizontalPadding:0];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -116,18 +115,17 @@
|
|||||||
return textField;
|
return textField;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setWithJSON:(NSDictionary *)json delegate:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate additionalData:(NSDictionary *)additionalData {
|
- (void)setAsMolecule {
|
||||||
|
|
||||||
self.isMolecule = YES;
|
self.isMolecule = YES;
|
||||||
[FormValidator setupValidationWithMolecule:self delegate:(id<FormValidationProtocol>)delegate];
|
|
||||||
[self setWithMap:json bothDelegates:delegate];
|
|
||||||
|
|
||||||
FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:(id<FormValidationProtocol>)delegate];
|
|
||||||
self.mfTextFieldDelegate = formValidator;
|
|
||||||
self.uiTextFieldDelegate = formValidator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVerticalPadding:(CGFloat) padding {
|
- (void)setWithJSON:(NSDictionary *)json delegate:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate additionalData:(NSDictionary *)additionalData {
|
||||||
|
[FormValidator setupValidationWithMolecule:self delegate:(id<FormValidationProtocol>)delegate];
|
||||||
|
FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:(id<FormValidationProtocol>)delegate];
|
||||||
|
[self setWithMap:json bothDelegates:formValidator];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setHorizontalPadding:(CGFloat) padding {
|
||||||
self.textContainerLeftPin.constant = padding;
|
self.textContainerLeftPin.constant = padding;
|
||||||
self.errorLableLeftPin.constant = padding;
|
self.errorLableLeftPin.constant = padding;
|
||||||
self.formLabelLeftPin.constant = padding;
|
self.formLabelLeftPin.constant = padding;
|
||||||
@ -568,7 +566,7 @@
|
|||||||
|
|
||||||
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
||||||
|
|
||||||
- (BOOL) isValidField {
|
- (BOOL)isValidField {
|
||||||
return self.valid;
|
return self.valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,7 +55,7 @@
|
|||||||
// title view for navigation bar, used for custom navigation titles
|
// title view for navigation bar, used for custom navigation titles
|
||||||
@property (weak, nonatomic) UILabel *titleLabel;
|
@property (weak, nonatomic) UILabel *titleLabel;
|
||||||
|
|
||||||
@property (strong, nonatomic) FormValidator* formValidator;
|
@property (strong, nonatomic) FormValidator *formValidator;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -254,9 +254,7 @@
|
|||||||
self.loadObject.pageJSON = page;
|
self.loadObject.pageJSON = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self updateUI];
|
[self updateUI];
|
||||||
// [self newDataBuildScreen];
|
|
||||||
// self.needToUpdateUI = YES;
|
|
||||||
[self.view setNeedsLayout];
|
[self.view setNeedsLayout];
|
||||||
[self.view layoutIfNeeded];
|
[self.view layoutIfNeeded];
|
||||||
}];
|
}];
|
||||||
@ -416,6 +414,10 @@
|
|||||||
// Since we have new data, build stuff for the screen.
|
// Since we have new data, build stuff for the screen.
|
||||||
[self updateUI];
|
[self updateUI];
|
||||||
|
|
||||||
|
// Update the UI after the view is loaded.
|
||||||
|
self.needToUpdateUI = YES;
|
||||||
|
self.needToupdateUIOnScreenSizeChanges = YES;
|
||||||
|
|
||||||
if (UIAccessibilityIsVoiceOverRunning()) {
|
if (UIAccessibilityIsVoiceOverRunning()) {
|
||||||
self.disableAnimations = YES;
|
self.disableAnimations = YES;
|
||||||
}
|
}
|
||||||
@ -428,10 +430,6 @@
|
|||||||
- (void) updateUI {
|
- (void) updateUI {
|
||||||
[self newDataBuildScreen];
|
[self newDataBuildScreen];
|
||||||
[self.formValidator enableByValidation];
|
[self.formValidator enableByValidation];
|
||||||
|
|
||||||
// Update the UI after the view is loaded.
|
|
||||||
self.needToUpdateUI = YES;
|
|
||||||
self.needToupdateUIOnScreenSizeChanges = YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didReceiveMemoryWarning {
|
- (void)didReceiveMemoryWarning {
|
||||||
|
|||||||
@ -10,23 +10,22 @@ import Foundation
|
|||||||
|
|
||||||
@objc public extension FormValidator {
|
@objc public extension FormValidator {
|
||||||
@objc public func addFormParams(requestParameters: MVMCoreRequestParameters) {
|
@objc public func addFormParams(requestParameters: MVMCoreRequestParameters) {
|
||||||
DispatchQueue.main.sync {
|
requestParameters.add(self.getFormParams())
|
||||||
requestParameters.add(self.getFormParams())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func getFormParams() -> [String: Any] {
|
@objc public func getFormParams() -> [String: Any] {
|
||||||
|
|
||||||
var extraParam: [String: Any] = [:]
|
var extraParam: [String: Any] = [:]
|
||||||
for molecule in self.molecules {
|
MVMCoreDispatchUtility.performSyncBlock(onMainThread: {
|
||||||
if let formFieldName = molecule.formFieldName,
|
for molecule in self.molecules {
|
||||||
let formFieldValue = molecule.formFieldValue,
|
if let formFieldName = molecule.formFieldName,
|
||||||
let fieldName = formFieldName(),
|
let formFieldValue = molecule.formFieldValue,
|
||||||
let fieldValue = formFieldValue() {
|
let fieldName = formFieldName(),
|
||||||
|
let fieldValue = formFieldValue() {
|
||||||
extraParam[fieldName] = fieldValue
|
|
||||||
|
extraParam[fieldName] = fieldValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return extraParam
|
return extraParam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,27 +8,67 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objc extension FormValidator: UITextFieldDelegate, UITextViewDelegate, MFTextFieldDelegate{
|
@objc extension FormValidator: UITextFieldDelegate {
|
||||||
public func textFieldDidEndEditing(_ textField: UITextField) {
|
public func textFieldDidEndEditing(_ textField: UITextField) {
|
||||||
enableByValidation()
|
enableByValidation()
|
||||||
}
|
if let delegate = delegate as? UITextFieldDelegate {
|
||||||
|
delegate.textFieldDidEndEditing?(textField)
|
||||||
public func dismissFieldInput(_ sender: Any?) {
|
|
||||||
if let delegate = delegate as? MFTextFieldDelegate,
|
|
||||||
let dismissFieldInput = delegate.dismissFieldInput {
|
|
||||||
dismissFieldInput(sender)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||||
textField.resignFirstResponder()
|
textField.resignFirstResponder()
|
||||||
|
if let delegate = delegate as? UITextFieldDelegate {
|
||||||
|
return delegate.textFieldShouldReturn?(textField) ?? true
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
public func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||||
if let delegate = delegate as? UITextFieldDelegate,
|
if let delegate = delegate as? UITextFieldDelegate {
|
||||||
let textFieldDidBeginEditing = delegate.textFieldDidBeginEditing {
|
delegate.textFieldDidBeginEditing?(textField)
|
||||||
textFieldDidBeginEditing(textField)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
|
||||||
|
if let delegate = delegate as? UITextFieldDelegate {
|
||||||
|
return delegate.textFieldShouldBeginEditing?(textField) ?? true
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
public func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
|
||||||
|
if let delegate = delegate as? UITextFieldDelegate {
|
||||||
|
return delegate.textFieldShouldEndEditing?(textField) ?? true
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
public func textFieldDidEndEditing(_ textField: UITextField, reason: UITextField.DidEndEditingReason) {
|
||||||
|
if let delegate = delegate as? UITextFieldDelegate {
|
||||||
|
delegate.textFieldDidEndEditing?(textField, reason: reason)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||||
|
if let delegate = delegate as? UITextFieldDelegate {
|
||||||
|
return delegate.textField?(textField, shouldChangeCharactersIn: range, replacementString: string) ?? true
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
public func textFieldShouldClear(_ textField: UITextField) -> Bool {
|
||||||
|
if let delegate = delegate as? UITextFieldDelegate {
|
||||||
|
return delegate.textFieldShouldClear?(textField) ?? true
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc extension FormValidator: MFTextFieldDelegate {
|
||||||
|
public func dismissFieldInput(_ sender: Any?) {
|
||||||
|
if let delegate = delegate as? MFTextFieldDelegate {
|
||||||
|
delegate.dismissFieldInput?(sender)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,11 +76,21 @@ import Foundation
|
|||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.enableByValidation()
|
self.enableByValidation()
|
||||||
}
|
}
|
||||||
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||||
|
if let delegate = self.delegate as? MFTextFieldDelegate {
|
||||||
|
delegate.entryIsValid?(textfield)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public func entryIsInvalid(_ textfield: MFTextField?) {
|
public func entryIsInvalid(_ textfield: MFTextField?) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.enableByValidation()
|
self.enableByValidation()
|
||||||
}
|
}
|
||||||
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||||
|
if let delegate = self.delegate as? MFTextFieldDelegate {
|
||||||
|
delegate.entryIsInvalid?(textfield)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user