Switch molecule

This commit is contained in:
Priya 2019-05-23 16:22:32 -04:00
parent 2e99c7baff
commit 344163de49
4 changed files with 123 additions and 32 deletions

View File

@ -14,6 +14,7 @@
0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; }; 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; };
0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; };
0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0198F7A22256A80A0066C936 /* MFRadioButton.m */; }; 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0198F7A22256A80A0066C936 /* MFRadioButton.m */; };
01CA51B5229716F60071A6EE /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01CA51B4229716F60071A6EE /* Switch.swift */; };
01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; }; 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; };
01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; }; 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; };
01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
@ -175,6 +176,7 @@
0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = "<group>"; }; 0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = "<group>"; };
0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = "<group>"; }; 0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = "<group>"; };
0198F7A22256A80A0066C936 /* MFRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFRadioButton.m; sourceTree = "<group>"; }; 0198F7A22256A80A0066C936 /* MFRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFRadioButton.m; sourceTree = "<group>"; };
01CA51B4229716F60071A6EE /* Switch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Switch.swift; sourceTree = "<group>"; };
01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = "<group>"; }; 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = "<group>"; };
01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = "<group>"; }; 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = "<group>"; };
D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = "<group>"; }; D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = "<group>"; };
@ -445,6 +447,7 @@
D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */,
D282AACA2243C61700C46919 /* ButtonView.swift */, D282AACA2243C61700C46919 /* ButtonView.swift */,
016A1070228122180009D605 /* SwitchLineItem.swift */, 016A1070228122180009D605 /* SwitchLineItem.swift */,
01CA51B4229716F60071A6EE /* Switch.swift */,
D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */,
D2A514662213885800345BFB /* StandardHeaderView.swift */, D2A514662213885800345BFB /* StandardHeaderView.swift */,
D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */,
@ -940,6 +943,7 @@
D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */,
D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */,
DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */,
01CA51B5229716F60071A6EE /* Switch.swift in Sources */,
0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */,
D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */, D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */,
D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */,
@ -1101,10 +1105,10 @@
buildSettings = { buildSettings = {
BITCODE_GENERATION_MODE = bitcode; BITCODE_GENERATION_MODE = bitcode;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = FCMA4QKS77;
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1; DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
@ -1119,7 +1123,6 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@ -1132,10 +1135,10 @@
buildSettings = { buildSettings = {
BITCODE_GENERATION_MODE = bitcode; BITCODE_GENERATION_MODE = bitcode;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = FCMA4QKS77;
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1; DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
@ -1150,7 +1153,6 @@
); );
PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI; PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCoreUI;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";

View File

@ -0,0 +1,87 @@
//
// Switch.swift
// MVMCoreUI
//
// Created by Priya on 5/23/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import UIKit
@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{
public var mvmSwitch = MVMCoreUISwitch()
var isRequired = false
var delegateObject: DelegateObject?
@objc func switchChanged() {
let delegate = delegateObject as? MVMCoreUIDelegateObject
if let delegate = delegate {
let formValidator = delegate.formValidationProtocol?.formValidatorModel?()
formValidator?.enableByValidation()
}
}
open override func setupView() {
super.setupView()
mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged)
self.clipsToBounds = true
addSubview(mvmSwitch)
mvmSwitch.translatesAutoresizingMaskIntoConstraints = false
setupContainerConstraints()
}
public override func updateView(_ size: CGFloat) {
super.updateView(size)
mvmSwitch.updateView(size)
}
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
isRequired = json?[KeyRequired] as? Bool ?? false
self.delegateObject = delegateObject
if let delegateObject = delegateObject as? MVMCoreUIDelegateObject {
FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol)
}
if let onColorString = json?.optionalStringForKey("onTintColor") {
mvmSwitch.onTintColor = .mfGet(forHex: onColorString)
}
if let offColorString = json?.optionalStringForKey("offTintColor") {
mvmSwitch.offTintColor = .mfGet(forHex: offColorString)
}
if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") {
mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString)
}
if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") {
mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString)
}
mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true)
}
func setupContainerConstraints() {
mvmSwitch.topAnchor.constraint(equalTo: topAnchor).isActive = true
mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
mvmSwitch.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
mvmSwitch.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
}
public func isValidField() -> Bool {
return (isRequired == false) ? true : mvmSwitch.isOn
}
public func formFieldName() -> String? {
return json?.optionalStringForKey(KeyFieldKey)
}
public func formFieldValue() -> Any? {
return mvmSwitch.isOn
}
public override func needsToBeConstrained() -> Bool {
return true
}
public override func moleculeAlignment() -> UIStackView.Alignment {
return UIStackView.Alignment.leading
}
}

View File

@ -8,8 +8,8 @@
import UIKit import UIKit
@objcMembers public class Switch: ViewConstrainingView, FormValidationProtocol{ @objcMembers public class SwitchLineItem: ViewConstrainingView, FormValidationProtocol{
public var mvmSwitch = MVMCoreUISwitch() public var mvmSwitch = Switch()
public var label = Label() public var label = Label()
public var leftContainerView = UIView() public var leftContainerView = UIView()
public var mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: 0) public var mfTextButton = MFTextButton(nil, constrainHeight: true, forWidth: 0)
@ -26,7 +26,7 @@ import UIKit
open override func setupView() { open override func setupView() {
super.setupView() super.setupView()
mvmSwitch.addTarget(self, action: #selector(Switch.switchChanged), for: .valueChanged) // mvmSwitch.addTarget(self, action: #selector(SwitchLineItem.switchChanged), for: .valueChanged)
leftContainerView.addSubview(label) leftContainerView.addSubview(label)
leftContainerView.addSubview(mfTextButton) leftContainerView.addSubview(mfTextButton)
addSubview(leftContainerView) addSubview(leftContainerView)
@ -50,24 +50,25 @@ import UIKit
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
isRequired = json?[KeyRequired] as? Bool ?? false isRequired = json?[KeyRequired] as? Bool ?? false
self.delegateObject = delegateObject self.delegateObject = delegateObject
mvmSwitch.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData)
mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) mfTextButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData)
if let delegateObject = delegateObject as? MVMCoreUIDelegateObject { // if let delegateObject = delegateObject as? MVMCoreUIDelegateObject {
FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol) // FormValidator.setupValidation(molecule: self, delegate: delegateObject.formValidationProtocol)
} // }
if let onColorString = json?.optionalStringForKey("onTintColor") { // if let onColorString = json?.optionalStringForKey("onTintColor") {
mvmSwitch.onTintColor = .mfGet(forHex: onColorString) // mvmSwitch.onTintColor = .mfGet(forHex: onColorString)
} // }
if let offColorString = json?.optionalStringForKey("offTintColor") { // if let offColorString = json?.optionalStringForKey("offTintColor") {
mvmSwitch.offTintColor = .mfGet(forHex: offColorString) // mvmSwitch.offTintColor = .mfGet(forHex: offColorString)
} // }
if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") { // if let onKnobColorString = json?.optionalStringForKey("onKnobTintColor") {
mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString) // mvmSwitch.onKnobTintColor = .mfGet(forHex: onKnobColorString)
} // }
if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") { // if let offKnobColorString = json?.optionalStringForKey("offKnobTintColor") {
mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString) // mvmSwitch.offKnobTintColor = .mfGet(forHex: offKnobColorString)
} // }
mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true) // mvmSwitch.setState(json?.optionalBoolForKey("state") ?? false, animated: true)
// if left container no width // if left container no width
if (label.text?.count ?? 0) <= 0 && (mfTextButton.titleLabel?.text?.count ?? 0) <= 0 { if (label.text?.count ?? 0) <= 0 && (mfTextButton.titleLabel?.text?.count ?? 0) <= 0 {
mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true mvmSwitch.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true
@ -129,17 +130,17 @@ import UIKit
} }
public func isValidField() -> Bool { // public func isValidField() -> Bool {
return (isRequired == false) ? true : mvmSwitch.isOn // return (isRequired == false) ? true : mvmSwitch.isOn
} // }
public func formFieldName() -> String? { public func formFieldName() -> String? {
return json?.optionalStringForKey(KeyFieldKey) return json?.optionalStringForKey(KeyFieldKey)
} }
//
public func formFieldValue() -> Any? { // public func formFieldValue() -> Any? {
return mvmSwitch.isOn // return mvmSwitch.isOn
} // }
public override func needsToBeConstrained() -> Bool { public override func needsToBeConstrained() -> Bool {
return true return true

View File

@ -34,6 +34,7 @@
@"caretButton": CaretButton.class, @"caretButton": CaretButton.class,
@"textField" : MFTextField.class, @"textField" : MFTextField.class,
@"checkbox" : MVMCoreUICheckBox.class, @"checkbox" : MVMCoreUICheckBox.class,
@"switchLineItem" : SwitchLineItem.class,
@"switch" : Switch.class @"switch" : Switch.class
} mutableCopy]; } mutableCopy];
}); });