switches
This commit is contained in:
parent
8448156ed3
commit
4bc22dbb8e
@ -391,6 +391,14 @@
|
|||||||
path = FormUIHelpers;
|
path = FormUIHelpers;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
D224798823142BF2003FCCF9 /* SwitchMolecules */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
016A1070228122180009D605 /* SwitchLineItem.swift */,
|
||||||
|
);
|
||||||
|
path = SwitchMolecules;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
D22D1F582204D2590077CEC0 /* LegacyControllers */ = {
|
D22D1F582204D2590077CEC0 /* LegacyControllers */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@ -478,12 +486,12 @@
|
|||||||
D29DF10E21E67A77003B2FB9 /* Molecules */ = {
|
D29DF10E21E67A77003B2FB9 /* Molecules */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
D224798823142BF2003FCCF9 /* SwitchMolecules */,
|
||||||
0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */,
|
0A12149F22C11A17007C7030 /* ActionDetailWithImage.swift */,
|
||||||
01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */,
|
01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */,
|
||||||
D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */,
|
D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */,
|
||||||
D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */,
|
D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */,
|
||||||
D282AACA2243C61700C46919 /* ButtonView.swift */,
|
D282AACA2243C61700C46919 /* ButtonView.swift */,
|
||||||
016A1070228122180009D605 /* SwitchLineItem.swift */,
|
|
||||||
01CA51B4229716F60071A6EE /* Switch.swift */,
|
01CA51B4229716F60071A6EE /* Switch.swift */,
|
||||||
D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */,
|
D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */,
|
||||||
D2A514662213885800345BFB /* StandardHeaderView.swift */,
|
D2A514662213885800345BFB /* StandardHeaderView.swift */,
|
||||||
|
|||||||
@ -8,10 +8,11 @@
|
|||||||
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <MVMCoreUI/MVMCoreUIMoleculeViewProtocol.h>
|
||||||
@import MVMCore.MVMCoreViewProtocol;
|
@import MVMCore.MVMCoreViewProtocol;
|
||||||
typedef void(^ValueChangeBlock)(void);
|
typedef void(^ValueChangeBlock)(void);
|
||||||
|
|
||||||
@interface MVMCoreUISwitch : UIControl <MVMCoreViewProtocol>
|
@interface MVMCoreUISwitch : UIControl <MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol>
|
||||||
|
|
||||||
@property (assign, nonatomic, getter=isOn) BOOL on;
|
@property (assign, nonatomic, getter=isOn) BOOL on;
|
||||||
@property (nullable, strong, nonatomic) UIColor *onTintColor;
|
@property (nullable, strong, nonatomic) UIColor *onTintColor;
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#import <MVMCoreUI/UIColor+MFConvenience.h>
|
#import <MVMCoreUI/UIColor+MFConvenience.h>
|
||||||
#import <MVMCoreUI/MVMCoreUICommonViewsUtility.h>
|
#import <MVMCoreUI/MVMCoreUICommonViewsUtility.h>
|
||||||
#import <MVMCoreUI/MVMCoreUIUtility.h>
|
#import <MVMCoreUI/MVMCoreUIUtility.h>
|
||||||
|
#import <MVMCoreUI/MVMCoreUI-Swift.h>
|
||||||
|
|
||||||
const CGFloat SwitchWidth = 42;
|
const CGFloat SwitchWidth = 42;
|
||||||
const CGFloat SwitchHeight = 22;
|
const CGFloat SwitchHeight = 22;
|
||||||
@ -21,7 +22,7 @@ const CGFloat SwitchKnobWidth = 20;
|
|||||||
const CGFloat SwitchKnobHeight = 20;
|
const CGFloat SwitchKnobHeight = 20;
|
||||||
const CGFloat SwitchShakeIntensity = 2;
|
const CGFloat SwitchShakeIntensity = 2;
|
||||||
|
|
||||||
@interface MVMCoreUISwitch ()
|
@interface MVMCoreUISwitch () <FormValidationProtocol, MVMCoreUIViewConstrainingProtocol>
|
||||||
|
|
||||||
@property (weak, nonatomic) UIView *baseView;
|
@property (weak, nonatomic) UIView *baseView;
|
||||||
@property (weak, nonatomic) UIView *knobView;
|
@property (weak, nonatomic) UIView *knobView;
|
||||||
@ -37,6 +38,9 @@ const CGFloat SwitchShakeIntensity = 2;
|
|||||||
|
|
||||||
@property (nonatomic) BOOL canChangeValue;
|
@property (nonatomic) BOOL canChangeValue;
|
||||||
|
|
||||||
|
@property (strong, nonatomic, nullable) NSDictionary *json;
|
||||||
|
@property (nullable, strong, nonatomic) DelegateObject *delegate;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MVMCoreUISwitch
|
@implementation MVMCoreUISwitch
|
||||||
@ -137,6 +141,50 @@ const CGFloat SwitchShakeIntensity = 2;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
||||||
|
|
||||||
|
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
|
||||||
|
self.json = json;
|
||||||
|
|
||||||
|
[FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol];
|
||||||
|
|
||||||
|
NSString *color = [json string:@"onTintColor"];
|
||||||
|
if (color) {
|
||||||
|
self.onTintColor = [UIColor mfGetColorForHex:color];
|
||||||
|
}
|
||||||
|
|
||||||
|
color = [json string:@"offTintColor"];
|
||||||
|
if (color) {
|
||||||
|
self.offTintColor = [UIColor mfGetColorForHex:color];
|
||||||
|
}
|
||||||
|
|
||||||
|
color = [json string:@"onKnobTintColor"];
|
||||||
|
if (color) {
|
||||||
|
self.onKnobTintColor = [UIColor mfGetColorForHex:color];
|
||||||
|
}
|
||||||
|
|
||||||
|
color = [json string:@"offKnobTintColor"];
|
||||||
|
if (color) {
|
||||||
|
self.offKnobTintColor = [UIColor mfGetColorForHex:color];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self setState:[json boolForKey:@"state"] animated:false];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
|
||||||
|
return [self getSwitchHeight];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
||||||
|
|
||||||
|
- (BOOL)needsToBeConstrained {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (UIStackViewAlignment)alignment {
|
||||||
|
return UIStackViewAlignmentTrailing;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - UIResponder overide
|
#pragma mark - UIResponder overide
|
||||||
|
|
||||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||||
@ -280,6 +328,11 @@ const CGFloat SwitchShakeIntensity = 2;
|
|||||||
if (self.valueChangedBlock) {
|
if (self.valueChangedBlock) {
|
||||||
self.valueChangedBlock();
|
self.valueChangedBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self.delegate && [self.delegate respondsToSelector:@selector(formValidationProtocol)] && [[self.delegate performSelector:@selector(formValidationProtocol)] respondsToSelector:@selector(formValidatorModel)]) {
|
||||||
|
FormValidator *formValidator = [[self.delegate performSelector:@selector(formValidationProtocol)] performSelector:@selector(formValidatorModel)];
|
||||||
|
[formValidator enableByValidation];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setState:(BOOL)state withoutBlockAnimated:(BOOL)animated {
|
- (void)setState:(BOOL)state withoutBlockAnimated:(BOOL)animated {
|
||||||
@ -308,7 +361,7 @@ const CGFloat SwitchShakeIntensity = 2;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)changeValue{
|
- (BOOL)changeValue {
|
||||||
self.on^=YES;
|
self.on^=YES;
|
||||||
self.shouldTouchToSwitch = NO;
|
self.shouldTouchToSwitch = NO;
|
||||||
[self setState:self.on animated:YES];
|
[self setState:self.on animated:YES];
|
||||||
@ -349,7 +402,8 @@ const CGFloat SwitchShakeIntensity = 2;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Accessibility
|
#pragma mark - Accessibility
|
||||||
- (BOOL)isAccessibilityElement{
|
|
||||||
|
- (BOOL)isAccessibilityElement {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,4 +415,18 @@ const CGFloat SwitchShakeIntensity = 2;
|
|||||||
return [MVMCoreUIUtility hardcodedStringWithKey:@"AccToggleHint"];
|
return [MVMCoreUIUtility hardcodedStringWithKey:@"AccToggleHint"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark FormValidationProtocol
|
||||||
|
|
||||||
|
- (BOOL)isValidField {
|
||||||
|
return self.isOn && [self.json boolForKey:@"required"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)formFieldName {
|
||||||
|
return [self.json string:KeyFieldKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)formFieldValue {
|
||||||
|
return @(self.isOn);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -45,7 +45,7 @@
|
|||||||
@"checkbox": MVMCoreUICheckBox.class,
|
@"checkbox": MVMCoreUICheckBox.class,
|
||||||
@"listItem": MoleculeTableViewCell.class,
|
@"listItem": MoleculeTableViewCell.class,
|
||||||
@"switchLineItem": SwitchLineItem.class,
|
@"switchLineItem": SwitchLineItem.class,
|
||||||
@"switch": Switch.class,
|
@"switch": MVMCoreUISwitch.class,
|
||||||
@"leftRightLabelView": LeftRightLabelView.class,
|
@"leftRightLabelView": LeftRightLabelView.class,
|
||||||
@"actionDetailWithImage": ActionDetailWithImage.class,
|
@"actionDetailWithImage": ActionDetailWithImage.class,
|
||||||
@"image": MFLoadImageView.class,
|
@"image": MFLoadImageView.class,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user