Digit text box molecule
This commit is contained in:
parent
93dfde6fc6
commit
d742ef9b6a
@ -15,8 +15,6 @@
|
||||
+ (nullable instancetype)mfDigitTextFieldWithNumberOfDigits:(NSUInteger)numberOfDigits withBothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate;
|
||||
+ (nullable instancetype)mfDigitTextFieldWithNumberOfDigits:(NSUInteger)numberOfDigits withBothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate size:(CGFloat)size;
|
||||
|
||||
- (void)setMessage:(nullable NSString *)message;
|
||||
|
||||
- (void)setAsSecureTextEntry:(BOOL)secureTextEntry;
|
||||
|
||||
@property (nullable, nonatomic, strong) NSArray <MFDigitTextBox *>*textFields;
|
||||
|
||||
@ -18,33 +18,24 @@
|
||||
#import "MVMCoreUISplitViewController.h"
|
||||
#import "MVMCoreUIUtility.h"
|
||||
#import "MVMCoreUIConstants.h"
|
||||
#import <MVMCoreUI/MVMCoreUI-Swift.h>
|
||||
@import MVMCore.MVMCoreDispatchUtility;
|
||||
|
||||
@interface MFDigitTextField () <UITextFieldDelegate, MFDigitTextBoxDelegate>
|
||||
|
||||
@property (nonatomic) NSUInteger numberOfDigits;
|
||||
|
||||
@property (nullable, nonatomic, weak) IBOutlet UILabel *messageLabel;
|
||||
@property (nullable, nonatomic, weak) IBOutlet UIView *textFieldsView;
|
||||
@property (nullable, nonatomic, weak) IBOutlet NSLayoutConstraint *messageToTextFieldPin;
|
||||
@property (nullable, nonatomic, weak) IBOutlet NSLayoutConstraint *labelToTextFieldPin;
|
||||
|
||||
|
||||
@property (nonatomic) BOOL switchedAutomatically;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MFDigitTextField
|
||||
|
||||
+ (nullable instancetype)mfTextField {
|
||||
MFDigitTextField *view = [super mfTextField];
|
||||
[MFStyler styleLabelB2:view.messageLabel];
|
||||
[view setMessage:@""];
|
||||
return view;
|
||||
}
|
||||
|
||||
- (MFDigitTextBox *)digitField {
|
||||
|
||||
MFDigitTextBox *textField = [[MFDigitTextBox alloc] init];
|
||||
textField.delegate = self;
|
||||
textField.mfTextBoxDelegate = self;
|
||||
@ -128,8 +119,9 @@
|
||||
}
|
||||
|
||||
- (void)updateView:(CGFloat)size {
|
||||
[super updateView:size];
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
[MFStyler styleLabelB2:self.messageLabel];
|
||||
[self.formLabel updateView:size];
|
||||
|
||||
// Remove all current UI.
|
||||
if (self.textFields.count > 0) {
|
||||
@ -146,6 +138,29 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setupView {
|
||||
[super setupView];
|
||||
[self.formLabel styleB2:YES];
|
||||
[self setFormText:@""];
|
||||
[self alignCenterHorizontal];
|
||||
}
|
||||
|
||||
#pragma mark - Molecule
|
||||
|
||||
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||
NSNumber *digitsNumber = [json optionalNumberForKey:@"digits"];
|
||||
NSUInteger digits = digitsNumber ? digitsNumber.integerValue : 4;
|
||||
if (digits != self.numberOfDigits) {
|
||||
self.numberOfDigits = digits;
|
||||
[self buildTextFieldsViewForSize:[MVMCoreUIUtility getWidth]];
|
||||
}
|
||||
[super setWithJSON:json delegateObject:delegateObject additionalData:additionalData];
|
||||
}
|
||||
|
||||
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
|
||||
return 44;
|
||||
}
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
- (NSString *)placeholder {
|
||||
@ -172,15 +187,13 @@
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setMessage:(nullable NSString *)message {
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
if (message.length > 0) {
|
||||
self.messageToTextFieldPin.constant = 10;
|
||||
} else {
|
||||
self.messageToTextFieldPin.constant = 0;
|
||||
}
|
||||
self.messageLabel.text = message;
|
||||
}];
|
||||
- (void)setFormText:(NSString *)formText {
|
||||
if (formText.length > 0) {
|
||||
self.messageToTextFieldPin.constant = 10;
|
||||
} else {
|
||||
self.messageToTextFieldPin.constant = 0;
|
||||
}
|
||||
[super setFormText:formText];
|
||||
}
|
||||
|
||||
- (void)setAsSecureTextEntry:(BOOL)secureTextEntry {
|
||||
@ -284,6 +297,11 @@
|
||||
|
||||
- (void)enable:(BOOL)enable {
|
||||
[super enable:enable];
|
||||
if (enable) {
|
||||
[self.formLabel styleB2:YES];
|
||||
} else {
|
||||
self.formLabel.textColor = [UIColor mfBattleshipGrey];
|
||||
}
|
||||
for (UITextField *textField in self.textFields) {
|
||||
textField.userInteractionEnabled = enable;
|
||||
textField.enabled = enable;
|
||||
|
||||
@ -1,24 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<customFonts key="customFonts">
|
||||
<array key="NHaasGroteskDSStd-65Md.otf">
|
||||
<string>NHaasGroteskDSStd-65Md</string>
|
||||
</array>
|
||||
</customFonts>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MFDigitTextField">
|
||||
<connections>
|
||||
<outlet property="formLabel" destination="lBe-qk-qFb" id="Z62-sL-6ri"/>
|
||||
<outlet property="label" destination="FWB-f6-Irs" id="fcc-SH-O4s"/>
|
||||
<outlet property="labelToTextFieldPin" destination="KyA-DB-529" id="SOG-MG-gMN"/>
|
||||
<outlet property="messageLabel" destination="lBe-qk-qFb" id="x3K-fb-b4U"/>
|
||||
<outlet property="messageToTextFieldPin" destination="NPs-pX-DJ0" id="41B-cE-pax"/>
|
||||
<outlet property="textFieldsView" destination="v46-w7-vQ1" id="hh8-TK-7XM"/>
|
||||
</connections>
|
||||
@ -28,7 +23,7 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="80"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="800" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="900" verticalCompressionResistancePriority="1000" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lBe-qk-qFb">
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="800" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="900" verticalCompressionResistancePriority="1000" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lBe-qk-qFb" customClass="Label" customModule="MVMCoreUI" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="16"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<fontDescription key="fontDescription" name="NHaasGroteskDSStd-65Md" family="Neue Haas Grotesk Display Std" pointSize="13"/>
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textContainerRightPin;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *errorLableRightPin;
|
||||
@property (nonatomic) BOOL isMolecule;
|
||||
|
||||
@end
|
||||
|
||||
@ -42,7 +41,7 @@
|
||||
- (void)updateView:(CGFloat)size {
|
||||
[super updateView:size];
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
self.formLabel.font = [MFStyler fontB3];
|
||||
[self.formLabel updateView:size];
|
||||
self.label.font = [MFStyler fontForTextFieldUnderLabel];
|
||||
[MFStyler styleTextField:self.textField];
|
||||
[self.dashLine updateView:size];
|
||||
@ -55,11 +54,13 @@
|
||||
UINib *nib = [self getNib];
|
||||
NSArray *views = [nib instantiateWithOwner:self options:nil];
|
||||
UIView *view = [views firstObject];
|
||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[view setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
|
||||
[view setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
|
||||
self.view = view;
|
||||
view.frame = self.frame;
|
||||
[self addSubview:view];
|
||||
[self pinViewToSuperView:view];
|
||||
|
||||
self.textField.font = [MFStyler fontForTextField];
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
@ -556,10 +557,6 @@
|
||||
|
||||
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
||||
|
||||
- (void)setAsMolecule {
|
||||
self.isMolecule = YES;
|
||||
}
|
||||
|
||||
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||
if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) {
|
||||
[FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol];
|
||||
@ -572,6 +569,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
|
||||
return 76;
|
||||
}
|
||||
|
||||
#pragma mark - FormValidationProtocol
|
||||
|
||||
|
||||
|
||||
@ -12,23 +12,23 @@
|
||||
@interface ViewConstrainingView : MFView
|
||||
|
||||
// Dont set these directly.
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *leftPin;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *rightPin;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *topPin;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *bottomPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *leftPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *rightPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *topPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *bottomPin;
|
||||
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *alignCenterPin;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *alignCenterLeftPin;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *alignCenterRightPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterLeftPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterRightPin;
|
||||
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *alignCenterVerticalPin;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *alignCenterTopPin;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *alignCenterBottomPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterVerticalPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterTopPin;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterBottomPin;
|
||||
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *leftPinLow;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *rightPinLow;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *topPinLow;
|
||||
@property (nullable, strong, nonatomic) NSLayoutConstraint *bottomPinLow;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *leftPinLow;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *rightPinLow;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *topPinLow;
|
||||
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *bottomPinLow;
|
||||
|
||||
|
||||
// In updateView, will set horizontal padding to default if set to YES.
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
@"caretView": CaretView.class,
|
||||
@"caretButton": CaretButton.class,
|
||||
@"textField" : MFTextField.class,
|
||||
@"digitTextField" : MFDigitTextField.class,
|
||||
@"checkbox" : MVMCoreUICheckBox.class,
|
||||
@"progressBarWithLabel" : ProgressBarWithLabel.class,
|
||||
@"progressBar": ProgressBar.class,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user