merge feature/coding

This commit is contained in:
Xinlei(Ryan) Pan 2020-01-22 10:24:18 -05:00
commit 85675a1d0e
22 changed files with 114 additions and 111 deletions

View File

@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
01004F3022721C3800991ECC /* RadioButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01004F2F22721C3800991ECC /* RadioButton.swift */; }; 01004F3022721C3800991ECC /* RadioButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01004F2F22721C3800991ECC /* RadioButton.swift */; };
0103B84E23D7E33A009C315C /* HeadlineBodyToggleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */; };
0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; }; 0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; };
0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; };
0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; };
@ -311,6 +312,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
01004F2F22721C3800991ECC /* RadioButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButton.swift; sourceTree = "<group>"; }; 01004F2F22721C3800991ECC /* RadioButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButton.swift; sourceTree = "<group>"; };
0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyToggleModel.swift; sourceTree = "<group>"; };
0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = "<group>"; }; 0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = "<group>"; };
0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = "<group>"; }; 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = "<group>"; };
0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = "<group>"; }; 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = "<group>"; };
@ -658,7 +660,6 @@
children = ( children = (
011B58EE23A2AA850085F53C /* ModelProtocols */, 011B58EE23A2AA850085F53C /* ModelProtocols */,
946EE1B5237B663A0036751F /* Extensions */, 946EE1B5237B663A0036751F /* Extensions */,
01EB368723609801006832FA /* Molecules */,
); );
path = Models; path = Models;
sourceTree = "<group>"; sourceTree = "<group>";
@ -674,16 +675,6 @@
path = FormUIHelpers; path = FormUIHelpers;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
01EB368723609801006832FA /* Molecules */ = {
isa = PBXGroup;
children = (
012A88AE238C626E00FE3DA1 /* CarouselModel.swift */,
012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */,
012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */,
);
path = Molecules;
sourceTree = "<group>";
};
0A5D59C323AD488600EFD9E9 /* Protocols */ = { 0A5D59C323AD488600EFD9E9 /* Protocols */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -811,6 +802,7 @@
01C851D223CF9E740021F976 /* LabelToggleModel.swift */, 01C851D223CF9E740021F976 /* LabelToggleModel.swift */,
D22479892314445E003FCCF9 /* LabelSwitch.swift */, D22479892314445E003FCCF9 /* LabelSwitch.swift */,
D224798B231450C8003FCCF9 /* HeadlineBodySwitch.swift */, D224798B231450C8003FCCF9 /* HeadlineBodySwitch.swift */,
0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */,
); );
path = SwitchMolecules; path = SwitchMolecules;
sourceTree = "<group>"; sourceTree = "<group>";
@ -858,6 +850,7 @@
D260105C23D0BCD400764D80 /* Stack.swift */, D260105C23D0BCD400764D80 /* Stack.swift */,
01EB368B23609801006832FA /* MoleculeStackModel.swift */, 01EB368B23609801006832FA /* MoleculeStackModel.swift */,
D2A5145E2211DDC100345BFB /* MoleculeStackView.swift */, D2A5145E2211DDC100345BFB /* MoleculeStackView.swift */,
012A88AE238C626E00FE3DA1 /* CarouselModel.swift */,
D2A6390022CBB1820052ED1F /* Carousel.swift */, D2A6390022CBB1820052ED1F /* Carousel.swift */,
); );
path = Organisms; path = Organisms;
@ -869,6 +862,7 @@
D2755D7A23689C7500485468 /* TableViewCell.swift */, D2755D7A23689C7500485468 /* TableViewCell.swift */,
01EB368923609801006832FA /* ListItemModel.swift */, 01EB368923609801006832FA /* ListItemModel.swift */,
01509D8E2327EC6F00EF99AA /* MoleculeTableViewCell.swift */, 01509D8E2327EC6F00EF99AA /* MoleculeTableViewCell.swift */,
012A88C1238D7BCA00FE3DA1 /* CarouselItemModel.swift */,
D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */, D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */,
D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */, D28A838023CCB0D800DFE4FC /* AccordionListItemModel.swift */,
D224799A231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift */, D224799A231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift */,
@ -997,6 +991,7 @@
012A88EB238F084D00FE3DA1 /* FooterModel.swift */, 012A88EB238F084D00FE3DA1 /* FooterModel.swift */,
D274CA322236A78900B01B62 /* FooterView.swift */, D274CA322236A78900B01B62 /* FooterView.swift */,
0116A4E4228B19640094F3ED /* RadioButtonModel.swift */, 0116A4E4228B19640094F3ED /* RadioButtonModel.swift */,
012A88C5238DA34000FE3DA1 /* ModuleMoleculeModel.swift */,
D29B770F22C281F400D6ACE0 /* ModuleMolecule.swift */, D29B770F22C281F400D6ACE0 /* ModuleMolecule.swift */,
D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */, D28A838423CCCA8900DFE4FC /* ScrollerModel.swift */,
D2D6CD3F22E78C1A00D701B8 /* Scroller.swift */, D2D6CD3F22E78C1A00D701B8 /* Scroller.swift */,
@ -1543,6 +1538,7 @@
D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */, D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */,
D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */, D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */,
94C2D9A723872DA90006CF46 /* LabelAttributeColorModel.swift in Sources */, 94C2D9A723872DA90006CF46 /* LabelAttributeColorModel.swift in Sources */,
0103B84E23D7E33A009C315C /* HeadlineBodyToggleModel.swift in Sources */,
D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */, D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */,
0A21DB85235E06EF00C160A2 /* MFTextField.m in Sources */, 0A21DB85235E06EF00C160A2 /* MFTextField.m in Sources */,
014AA72623C501E2006F3E93 /* ContainerModelProtocol.swift in Sources */, 014AA72623C501E2006F3E93 /* ContainerModelProtocol.swift in Sources */,

View File

@ -22,13 +22,13 @@ public class ButtonModel: MoleculeModelProtocol {
public static var identifier: String = "button" public static var identifier: String = "button"
public var backgroundColor: Color? public var backgroundColor: Color?
public var title: String public var title: String
public var action: ActionProtocol public var action: ActionModelProtocol
public var style: ButtonStyle? public var style: ButtonStyle?
public var size: ButtonSize? = .standard public var size: ButtonSize? = .standard
public var required: Bool? public var required: Bool?
public var requiredGroups: [String]? public var requiredGroups: [String]?
init(with title: String, action: ActionProtocol) { init(with title: String, action: ActionModelProtocol) {
self.title = title self.title = title
self.action = action self.action = action
} }

View File

@ -13,12 +13,12 @@ public class CaretLinkModel: MoleculeModelProtocol {
public static var identifier: String = "caretLink" public static var identifier: String = "caretLink"
public var backgroundColor: Color? public var backgroundColor: Color?
public var title: String public var title: String
public var action: ActionProtocol public var action: ActionModelProtocol
public var enabledColor: Color = Color(uiColor: .black) public var enabledColor: Color = Color(uiColor: .black)
public var disabledColor: Color? = Color(uiColor: .mfSilver()) public var disabledColor: Color? = Color(uiColor: .mfSilver())
public var enabled: Bool = true public var enabled: Bool = true
public init(title: String, action: ActionProtocol) { public init(title: String, action: ActionModelProtocol) {
self.title = title self.title = title
self.action = action self.action = action
} }

View File

@ -12,12 +12,12 @@ public class LinkModel: MoleculeModelProtocol {
public static var identifier: String = "link" public static var identifier: String = "link"
public var backgroundColor: Color? public var backgroundColor: Color?
public var title: String public var title: String
public var action: ActionProtocol public var action: ActionModelProtocol
public var enabled = true public var enabled = true
public var textColor = Color(uiColor: .mvmBlack) public var textColor = Color(uiColor: .mvmBlack)
public var disabledColor = Color(uiColor: .mvmCoolGray6) public var disabledColor = Color(uiColor: .mvmCoolGray6)
public init(title: String, action: ActionProtocol) { public init(title: String, action: ActionModelProtocol) {
self.title = title self.title = title
self.action = action self.action = action
} }

View File

@ -9,7 +9,7 @@
import Foundation import Foundation
public extension MFCustomButton { public extension MFCustomButton {
func set(with action: ActionProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { func set(with action: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
buttonDelegate = delegateObject?.buttonDelegate buttonDelegate = delegateObject?.buttonDelegate
add({ [weak self] sender in add({ [weak self] sender in
guard let self = self else { return } guard let self = self else { return }

View File

@ -12,7 +12,7 @@ class LabelAttributeActionModel: LabelAttributeModel {
override public class var identifier: String { override public class var identifier: String {
return "action" return "action"
} }
var action: ActionProtocol var action: ActionModelProtocol
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)

View File

@ -66,7 +66,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
} else { } else {
guard let label = label else { return } guard let label = label else { return }
let accessibleAction = UIAccessibilityCustomAction(name: actionText ?? "", target: label, selector: #selector(label.accessibilityCustomAction(_:))) let accessibleAction = UIAccessibilityCustomAction(name: actionText ?? "label", target: label, selector: #selector(label.accessibilityCustomAction(_:)))
label.clauses = [Label.ActionableClause(range: actionRange, actionBlock: newActionBlock, accessibilityID: accessibleAction.hash)] label.clauses = [Label.ActionableClause(range: actionRange, actionBlock: newActionBlock, accessibilityID: accessibleAction.hash)]
label.accessibilityCustomActions = [accessibleAction] label.accessibilityCustomActions = [accessibleAction]

View File

@ -43,6 +43,7 @@ import UIKit
public static var identifier: String = "line" public static var identifier: String = "line"
public var type: Style = .standard public var type: Style = .standard
public var frequency: Frequency? = .allExceptTop public var frequency: Frequency? = .allExceptTop
public var color: Color?
public var backgroundColor: Color? public var backgroundColor: Color?
public init(type: Style) { public init(type: Style) {
@ -53,6 +54,7 @@ import UIKit
case moleculeName case moleculeName
case type case type
case backgroundColor case backgroundColor
case color
case frequency case frequency
} }
@ -64,7 +66,7 @@ import UIKit
if let frequency = try typeContainer.decodeIfPresent(Frequency.self, forKey: .frequency) { if let frequency = try typeContainer.decodeIfPresent(Frequency.self, forKey: .frequency) {
self.frequency = frequency self.frequency = frequency
} }
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) color = try typeContainer.decodeIfPresent(Color.self, forKey: .color)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -72,6 +74,6 @@ import UIKit
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(type, forKey: .type) try container.encode(type, forKey: .type)
try container.encodeIfPresent(frequency, forKey: .frequency) try container.encodeIfPresent(frequency, forKey: .frequency)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(color, forKey: .color)
} }
} }

View File

@ -13,7 +13,8 @@ public class ToggleModel: MoleculeModelProtocol {
public var moleculeName: String? public var moleculeName: String?
public var backgroundColor: Color? public var backgroundColor: Color?
public var state: Bool = true public var state: Bool = true
public var action: ActionProtocol? public var action: ActionModelProtocol?
public var alternateAction: ActionModelProtocol?
public var required: Bool? public var required: Bool?
public var fieldKey: String? public var fieldKey: String?
@ -24,6 +25,7 @@ public class ToggleModel: MoleculeModelProtocol {
case backgroundColor case backgroundColor
case required case required
case fieldKey case fieldKey
case alternateAction
} }
public init(_ state: Bool) { public init(_ state: Bool) {
@ -36,6 +38,7 @@ public class ToggleModel: MoleculeModelProtocol {
self.state = state self.state = state
} }
action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType)
alternateAction = try typeContainer.decodeModelIfPresent(codingKey: .alternateAction, typeCodingKey: ActionCodingKey.actionType)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required) required = try typeContainer.decodeIfPresent(Bool.self, forKey: .required)
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
@ -45,6 +48,7 @@ public class ToggleModel: MoleculeModelProtocol {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeModelIfPresent(action, forKey: .action) try container.encodeModelIfPresent(action, forKey: .action)
try container.encodeModelIfPresent(alternateAction, forKey: .alternateAction)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(state, forKey: .state) try container.encodeIfPresent(state, forKey: .state)
try container.encodeIfPresent(required, forKey: .required) try container.encodeIfPresent(required, forKey: .required)

View File

@ -8,14 +8,11 @@
public typealias ButtonAction = (Button) -> () public typealias ButtonAction = (Button) -> ()
@objcMembers open class Button: UIButton, MFButtonProtocol { @objcMembers open class Button: UIButton, MFButtonProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
public var actionModel: ActionModelProtocol?
public var json: [AnyHashable: Any]?
public var actionMap: [AnyHashable: Any]?
private var initialSetupPerformed = false private var initialSetupPerformed = false
@ -71,15 +68,15 @@ public typealias ButtonAction = (Button) -> ()
buttonAction?(self) buttonAction?(self)
} }
public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { public func setWithAction(_ actionModel: ActionModelProtocol, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
self.actionMap = actionMap self.actionModel = actionModel
buttonDelegate = delegateObject?.buttonDelegate buttonDelegate = delegateObject?.buttonDelegate
addActionBlock(event: .touchUpInside) { [weak self] sender in addActionBlock(event: .touchUpInside) { [weak self] sender in
guard let self = self else { return } guard let self = self else { return }
if let data = try? actionModel.encode(using: JSONEncoder()),
if self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { let actionMap = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any],
delegateObject?.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true {
MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject)
} }
} }
@ -98,29 +95,6 @@ public typealias ButtonAction = (Button) -> ()
} }
} }
// MARK: - MVMCoreUIMoleculeViewProtocol
extension Button: MVMCoreUIMoleculeViewProtocol {
public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
setWithActionMap(json, delegateObject: delegateObject, additionalData: additionalData)
self.json = json
guard let dictionary = json else { return }
if let backgroundColorString = dictionary[KeyBackgroundColor] as? String {
backgroundColor = UIColor.mfGet(forHex: backgroundColorString)
}
if let title = dictionary[KeyTitle] as? String {
setTitle(title, for: .normal)
}
}
public func reset() {
backgroundColor = .clear
}
}
// MARK: - MVMCoreViewProtocol // MARK: - MVMCoreViewProtocol
extension Button: MVMCoreViewProtocol { extension Button: MVMCoreViewProtocol {
@ -129,7 +103,6 @@ extension Button: MVMCoreViewProtocol {
/// Will be called only once. /// Will be called only once.
public func setupView() { public func setupView() {
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false insetsLayoutMarginsFromSafeArea = false
titleLabel?.numberOfLines = 0 titleLabel?.numberOfLines = 0

View File

@ -24,8 +24,12 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) {
@interface MVMCoreUISplitViewController : UIViewController @interface MVMCoreUISplitViewController : UIViewController
// Reference to the panels. // Reference to the panels.
@property (nullable, weak, nonatomic, readonly) UIViewController <MVMCoreUIPanelProtocol> *leftPanel; @property (nullable, weak, nonatomic) UIViewController <MVMCoreUIPanelProtocol> *leftPanel;
@property (nullable, weak, nonatomic, readonly) UIViewController <MVMCoreUIPanelProtocol> *rightPanel; @property (nullable, weak, nonatomic) UIViewController <MVMCoreUIPanelProtocol> *rightPanel;
// For keeping
@property (nullable, strong, nonatomic) UIViewController <MVMCoreUIPanelProtocol> *globalLeftPanel;
@property (nullable, strong, nonatomic) UIViewController <MVMCoreUIPanelProtocol> *globalRightPanel;
// Can be of protocol MVMCoreUIPanelButtonProtocol // Can be of protocol MVMCoreUIPanelButtonProtocol
@property (nullable, strong, nonatomic) UIBarButtonItem *leftPanelButton; @property (nullable, strong, nonatomic) UIBarButtonItem *leftPanelButton;
@ -79,6 +83,9 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) {
// contains speicaly logic to set the icon color // contains speicaly logic to set the icon color
- (void)setNavigationIconColor:(nullable UIColor *)color; - (void)setNavigationIconColor:(nullable UIColor *)color;
///create right and left panel. if left and right panel is already created, will replace them
- (void)createPanels;
/// Updates the panels that are used. /// Updates the panels that are used.
- (void)setupPanels; - (void)setupPanels;

View File

@ -44,12 +44,6 @@ typedef NS_OPTIONS(NSInteger, MFExtendedDrawer) {
@property (weak, nonatomic) UIView *leftPanelSeparator; @property (weak, nonatomic) UIView *leftPanelSeparator;
@property (weak, nonatomic) UIView *rightPanelSeparator; @property (weak, nonatomic) UIView *rightPanelSeparator;
// For keeping
@property (strong, nonatomic, readwrite) UIViewController <MVMCoreUIPanelProtocol> *globalLeftPanel;
@property (strong, nonatomic, readwrite) UIViewController <MVMCoreUIPanelProtocol> *globalRightPanel;
@property (weak, nonatomic, readwrite) UIViewController <MVMCoreUIPanelProtocol> *leftPanel;
@property (weak, nonatomic, readwrite) UIViewController <MVMCoreUIPanelProtocol> *rightPanel;
@property (weak, nonatomic, readwrite) NavigationController *navigationController; @property (weak, nonatomic, readwrite) NavigationController *navigationController;
// A view that covers the detail view when the master is out. // A view that covers the detail view when the master is out.
@ -355,6 +349,9 @@ CGFloat const PanelAnimationDuration = 0.2;
} }
- (void)showLeftPanelAnimated:(BOOL)animated explict:(BOOL)explict { - (void)showLeftPanelAnimated:(BOOL)animated explict:(BOOL)explict {
if (!self.leftPanel) {
return;
}
[MVMCoreDispatchUtility performBlockOnMainThread:^{ [MVMCoreDispatchUtility performBlockOnMainThread:^{
if (self.mainViewLeading.constant < .1) { if (self.mainViewLeading.constant < .1) {
BOOL shouldExtendLeftPanel = [self shouldExtendLeftPanel]; BOOL shouldExtendLeftPanel = [self shouldExtendLeftPanel];
@ -548,6 +545,9 @@ CGFloat const PanelAnimationDuration = 0.2;
} }
- (void)showRightPanelAnimated:(BOOL)animated explict:(BOOL)explict { - (void)showRightPanelAnimated:(BOOL)animated explict:(BOOL)explict {
if (!self.rightPanel) {
return;
}
[MVMCoreDispatchUtility performBlockOnMainThread:^{ [MVMCoreDispatchUtility performBlockOnMainThread:^{
if (self.mainViewTrailing.constant < .1) { if (self.mainViewTrailing.constant < .1) {
BOOL shouldExtendRightPanel = [self shouldExtendRightPanel]; BOOL shouldExtendRightPanel = [self shouldExtendRightPanel];
@ -766,6 +766,13 @@ CGFloat const PanelAnimationDuration = 0.2;
} }
} }
- (void)createPanels {
// Create panels
self.globalLeftPanel = [self createLeftPanelViewController];
self.globalRightPanel = [self createRightPanelViewController];
[self setupPanels];
}
- (void)setupPanels { - (void)setupPanels {
[self forceHideBothDrawers]; [self forceHideBothDrawers];
[self setupLeftPanel]; [self setupLeftPanel];
@ -862,10 +869,7 @@ CGFloat const PanelAnimationDuration = 0.2;
[NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES; [NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES; [NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES;
// Create panels [self createPanels];
self.globalLeftPanel = [self createLeftPanelViewController];
self.globalRightPanel = [self createRightPanelViewController];
[self setupPanels];
} }
- (void)viewDidLoad { - (void)viewDidLoad {

View File

@ -10,14 +10,14 @@ import Foundation
public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol { public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol {
var line: LineModel? { get set } var line: LineModel? { get set }
var action: ActionProtocol? { get set } var action: ActionModelProtocol? { get set }
var hideArrow: Bool? { get set } var hideArrow: Bool? { get set }
var style: String? { get set } var style: String? { get set }
} }
// Not a strict requirement. // Not a strict requirement.
extension ListItemModelProtocol { extension ListItemModelProtocol {
public var action: ActionProtocol? { public var action: ActionModelProtocol? {
get { get {
return nil return nil
} }

View File

@ -15,14 +15,14 @@ import Foundation
public var peakingUI: Bool? public var peakingUI: Bool?
public var peakingArrowColor: Color? public var peakingArrowColor: Color?
enum CarouselItemCodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case backgroundColor case backgroundColor
case peakingUI case peakingUI
case peakingArrowColor case peakingArrowColor
} }
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CarouselItemCodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI) peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI)
peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor) peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor)
@ -31,7 +31,7 @@ import Foundation
public override func encode(to encoder: Encoder) throws { public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder) try super.encode(to: encoder)
var container = encoder.container(keyedBy: CarouselItemCodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(peakingUI, forKey: .peakingUI) try container.encodeIfPresent(peakingUI, forKey: .peakingUI)
try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor) try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor)

View File

@ -12,7 +12,7 @@ import MVMCore
@objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol { @objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol {
public static var identifier: String = "listItem" public static var identifier: String = "listItem"
public var backgroundColor: Color? public var backgroundColor: Color?
public var action: ActionProtocol? public var action: ActionModelProtocol?
public var hideArrow: Bool? public var hideArrow: Bool?
public var line: LineModel? public var line: LineModel?
public var style: String? = "standard" public var style: String? = "standard"

View File

@ -10,18 +10,18 @@ import UIKit
@objcMembers open class HeadlineBodySwitch: View { @objcMembers open class HeadlineBodySwitch: View {
public let headlineBody = HeadlineBody(frame: .zero) public let headlineBody = HeadlineBody(frame: .zero)
public let mvmSwitch = MVMCoreUISwitch.mvmSwitchDefault() public let toggle = Toggle()
// MARK: - MVMCoreViewProtocol // MARK: - MVMCoreViewProtocol
open override func updateView(_ size: CGFloat) { open override func updateView(_ size: CGFloat) {
super.updateView(size) super.updateView(size)
headlineBody.updateView(size) headlineBody.updateView(size)
mvmSwitch.updateView(size) toggle.updateView(size)
} }
open override func setupView() { open override func setupView() {
super.setupView() super.setupView()
guard mvmSwitch.superview == nil else { guard toggle.superview == nil else {
return return
} }
headlineBody.styleListItem() headlineBody.styleListItem()
@ -30,8 +30,8 @@ import UIKit
NSLayoutConstraint.constraintPinSubview(toSuperview: view) NSLayoutConstraint.constraintPinSubview(toSuperview: view)
view.addSubview(headlineBody) view.addSubview(headlineBody)
view.addSubview(mvmSwitch) view.addSubview(toggle)
NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: mvmSwitch) NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: toggle)
} }
@ -39,6 +39,10 @@ import UIKit
open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.setWithModel(model, delegateObject, additionalData) super.setWithModel(model, delegateObject, additionalData)
guard let headlineBodyToggleModel = model as? HeadlineBodyToggleModel else {
return
}
setWithJSON(headlineBodyToggleModel.toJSON(), delegateObject: delegateObject, additionalData: additionalData)
} }
public class override func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { public class override func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
@ -50,7 +54,7 @@ import UIKit
open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
headlineBody.setWithJSON(json?.optionalDictionaryForKey("headlineBody"), delegateObject: delegateObject, additionalData: additionalData) headlineBody.setWithJSON(json?.optionalDictionaryForKey("headlineBody"), delegateObject: delegateObject, additionalData: additionalData)
mvmSwitch.setWithJSON(json?.optionalDictionaryForKey("toggle"), delegateObject: delegateObject, additionalData: additionalData) toggle.setWithJSON(json?.optionalDictionaryForKey("toggle"), delegateObject: delegateObject, additionalData: additionalData)
} }
open class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { open class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
@ -59,14 +63,14 @@ import UIKit
open override func setAsMolecule() { open override func setAsMolecule() {
headlineBody.setAsMolecule() headlineBody.setAsMolecule()
(mvmSwitch as MVMCoreUIMoleculeViewProtocol).setAsMolecule?() (toggle as MVMCoreUIMoleculeViewProtocol).setAsMolecule?()
headlineBody.styleListItem() headlineBody.styleListItem()
} }
open override func reset() { open override func reset() {
super.reset() super.reset()
headlineBody.reset() headlineBody.reset()
(mvmSwitch as MVMCoreUIMoleculeViewProtocol).reset?() (toggle as MVMCoreUIMoleculeViewProtocol).reset?()
headlineBody.styleListItem() headlineBody.styleListItem()
} }
} }

View File

@ -0,0 +1,22 @@
//
// HeadlineBodyToggleModel.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 1/21/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
open class HeadlineBodyToggleModel: MoleculeModelProtocol {
public static var identifier: String = "headlineBodyToggle"
open var backgroundColor: Color?
open var headlineBody: HeadlineBodyModel
open var toggle: ToggleModel
public init(_ headlineBody: HeadlineBodyModel, _ toggle: ToggleModel) {
self.headlineBody = headlineBody
self.toggle = toggle
}
}

View File

@ -13,7 +13,7 @@ open class ModuleMoleculeModel: MoleculeModelProtocol {
public static var identifier: String = "moduleMolecule" public static var identifier: String = "moduleMolecule"
public var moduleName: String public var moduleName: String
enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moduleName case moduleName
} }

View File

@ -15,9 +15,8 @@ import Foundation
public var style: String? public var style: String?
public var backgroundColor: Color? public var backgroundColor: Color?
public init(headline: LabelModel, body: LabelModel) { public init(headline: LabelModel) {
self.headline = headline self.headline = headline
self.body = body
} }
} }

View File

@ -8,7 +8,7 @@
import UIKit import UIKit
open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol { open class Carousel: View {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
@ -47,6 +47,9 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol {
var loop = false var loop = false
private var dragging = false private var dragging = false
// For adding pager
private var bottomPin: NSLayoutConstraint?
// MARK: - MVMCoreViewProtocol // MARK: - MVMCoreViewProtocol
open override func setupView() { open override func setupView() {
super.setupView() super.setupView()
@ -60,7 +63,7 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol {
collectionView.backgroundColor = .clear collectionView.backgroundColor = .clear
collectionView.isAccessibilityElement = false collectionView.isAccessibilityElement = false
addSubview(collectionView) addSubview(collectionView)
pinView(toSuperView: collectionView) bottomPin = NSLayoutConstraint.constraintPinSubview(toSuperview: collectionView)?[ConstraintBot] as? NSLayoutConstraint
collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300) collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: 300)
collectionViewHeight?.isActive = false collectionViewHeight?.isActive = false
@ -81,41 +84,29 @@ open class Carousel: ViewConstrainingView, ModelMoleculeViewProtocol {
// MARK: - MVMCoreUIMoleculeViewProtocol // MARK: - MVMCoreUIMoleculeViewProtocol
//TODO: Model, Change to model //TODO: Model, Change to model
public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
guard let caroselModel = model as? CarouselModel else { super.setWithModel(model, delegateObject, additionalData)
return guard let carouselModel = model as? CarouselModel else { return }
}
#warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.")
//TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.
setUpDefaultWithModel(model, delegateObject, additionalData)
collectionView.backgroundColor = backgroundColor collectionView.backgroundColor = backgroundColor
collectionView.layer.borderColor = backgroundColor?.cgColor collectionView.layer.borderColor = backgroundColor?.cgColor
collectionView.layer.borderWidth = (caroselModel.border ?? false) ? 1 : 0 collectionView.layer.borderWidth = (carouselModel.border ?? false) ? 1 : 0
backgroundColor = .white backgroundColor = .white
registerCells(with: caroselModel, delegateObject: delegateObject) registerCells(with: carouselModel, delegateObject: delegateObject)
setupLayout(with: caroselModel) setupLayout(with: carouselModel)
prepareMolecules(with: caroselModel) prepareMolecules(with: carouselModel)
itemWidthPercent = (caroselModel.itemWidthPercent ?? 100) / 100 itemWidthPercent = (carouselModel.itemWidthPercent ?? 100) / 100
setAlignment(with: caroselModel.itemAlignment) setAlignment(with: carouselModel.itemAlignment)
if let height = caroselModel.height { if let height = carouselModel.height {
collectionViewHeight?.constant = CGFloat(height) collectionViewHeight?.constant = CGFloat(height)
collectionViewHeight?.isActive = true collectionViewHeight?.isActive = true
} }
setupPagingMolecule(caroselModel.pagingMolecule, delegateObject: delegateObject) setupPagingMolecule(carouselModel.pagingMolecule, delegateObject: delegateObject)
collectionView.reloadData() collectionView.reloadData()
} }
open override func shouldSetHorizontalMargins(_ shouldSet: Bool) {
super.shouldSetHorizontalMargins(shouldSet)
updateViewHorizontalDefaults = false
}
// MARK: - JSON Setters // MARK: - JSON Setters
/// Updates the layout being used /// Updates the layout being used

View File

@ -25,7 +25,7 @@ import UIKit
self.molecules = molecules self.molecules = molecules
} }
enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case backgroundColor case backgroundColor
case molecules case molecules

View File

@ -70,5 +70,6 @@ import Foundation
ModelRegistry.register(DoughnutChartModel.self) ModelRegistry.register(DoughnutChartModel.self)
ModelRegistry.register(NumberedListModel.self) ModelRegistry.register(NumberedListModel.self)
ModelRegistry.register(UnOrderedListModel.self) ModelRegistry.register(UnOrderedListModel.self)
ModelRegistry.register(HeadlineBodyToggleModel.self)
} }
} }