From 487d41b3d99a28649f5b17fa0d9cfbd68f917afb Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 31 Jan 2020 16:01:06 -0500 Subject: [PATCH 1/9] two button view update --- .../TwoButtonView.swift | 333 ++++-------------- 1 file changed, 62 insertions(+), 271 deletions(-) diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 5c80bd1a..9a4f31f9 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -8,11 +8,10 @@ import UIKit -@objcMembers open class TwoButtonView: ViewConstrainingView { - open var primaryButton: PrimaryButton? = PrimaryButton.button() - open var secondaryButton: PrimaryButton? = PrimaryButton.button() - open var viewForButtons: UIView? - public var heightConstraint: NSLayoutConstraint? +@objcMembers open class TwoButtonView: View, MVMCoreUIViewConstrainingProtocol { + open var primaryButton: PillButton = PillButton() + open var secondaryButton: PillButton = PillButton() + private var stack = UIStackView() public init() { super.init(frame: .zero) @@ -26,289 +25,81 @@ import UIKit super.init(frame: frame) } - public func setDefaultCustom() { - primaryButton?.setAsStandardCustom() - secondaryButton?.setAsSecondaryCustom() + public func setDefault() { + primaryButton.stylePrimary() + secondaryButton.styleSecondary() } // MARK: - MVMCoreViewProtocol open override func updateView(_ size: CGFloat) { super.updateView(size) - MVMCoreDispatchUtility.performBlock(onMainThread: { - self.primaryButton?.updateView(size) - self.secondaryButton?.updateView(size) - }) + self.primaryButton.updateView(size) + self.secondaryButton.updateView(size) } open override func setupView() { super.setupView() - setupWithTwoButtons() - secondaryButton?.bordered = true + + stack.translatesAutoresizingMaskIntoConstraints = false + addSubview(stack) + stack.addArrangedSubview(primaryButton) + stack.addArrangedSubview(secondaryButton) + NSLayoutConstraint.constraintPinSubview(toSuperview: stack) + stack.axis = .horizontal + stack.spacing = 10 + } + + // MARK: - Stack Manipulation + public func showPrimaryButton() { + if primaryButton.superview == nil { + stack.addArrangedSubview(primaryButton) + } + } + + public func showSecondaryButton() { + if secondaryButton.superview == nil { + stack.addArrangedSubview(secondaryButton) + } + } + + public func hidePrimaryButton() { + if primaryButton.superview != nil { + stack.removeArrangedSubview(primaryButton) + } + } + + public func hideSecondaryButton() { + if secondaryButton.superview != nil { + stack.removeArrangedSubview(secondaryButton) + } } // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - let primaryButtonMap = json?.optionalDictionaryForKey("primaryButton") - let secondaryButtonMap = json?.optionalDictionaryForKey("secondaryButton") - set(primaryButtonJSON: primaryButtonMap, secondaryButtonJSON: secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - } - open override func reset() { super.reset() - primaryButton?.setAsStandardCustom() - secondaryButton?.setAsSecondaryCustom() + setDefault() } - - // MARK: - Constraining - func createPrimaryButton() { - if primaryButton == nil { - primaryButton = PrimaryButton.button() - } - } - - func createSecondaryButton() { - if secondaryButton == nil { - secondaryButton = PrimaryButton.button() - secondaryButton?.bordered = true - } - } - - func removeButtons() { - viewForButtons?.removeFromSuperview() - primaryButton?.removeFromSuperview() - secondaryButton?.removeFromSuperview() - viewForButtons = nil - secondaryButton = nil - primaryButton = nil - } - - open func setupConstraintsForViewWithButtons() { - guard let viewForButtons = viewForButtons, - let primaryButton = primaryButton, - let secondaryButton = secondaryButton - else { return } - - viewForButtons.addSubview(primaryButton) - viewForButtons.addSubview(secondaryButton) - secondaryButton.widthAnchor.constraint(equalTo: primaryButton.widthAnchor, multiplier: 1).isActive = true - NSLayoutConstraint.constraintPinSubview(secondaryButton, pinTop: true, pinBottom: true, pinLeft: true, pinRight: false) - NSLayoutConstraint.constraintPinSubview(primaryButton, pinTop: true, pinBottom: true, pinLeft: false, pinRight: true) - let constraint = primaryButton.leadingAnchor.constraint(equalTo: secondaryButton.trailingAnchor, constant: 10) - constraint.priority = UILayoutPriority(900) - constraint.isActive = true - } - - func setupWithTwoButtons() { - guard viewForButtons == nil else { - return - } - let viewForButtons = MVMCoreUICommonViewsUtility.commonView() - addSubview(viewForButtons) - self.viewForButtons = viewForButtons - - pinView(toSuperView: viewForButtons) - alignCenterHorizontal() - createPrimaryButton() - createSecondaryButton() - setupConstraintsForViewWithButtons() - } - - open func setupWithPrimaryButton() { - guard primaryButton == nil && secondaryButton == nil else { - return - } - createPrimaryButton() - if let primaryButton = primaryButton { - addSubview(primaryButton) - pinView(toSuperView: primaryButton) - alignCenterHorizontal() - } - } - - open func setupWithSecondaryButton() { - guard secondaryButton == nil && primaryButton == nil else { - return - } - createSecondaryButton() - if let secondaryButton = secondaryButton { - addSubview(secondaryButton) - pinView(toSuperView: secondaryButton) - alignCenterHorizontal() - } - } - - /// Legacy - func setupUI(withPrimaryButtonMap primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?) { - setupUI(primaryButtonShowing: primaryButtonMap != nil, secondaryButtonShowing: secondaryButtonMap != nil) - } - - func setupUI(primaryButtonShowing: Bool, secondaryButtonShowing: Bool) { - if primaryButtonShowing, secondaryButtonShowing { - heightConstraint?.isActive = false - if primaryButton == nil || secondaryButton == nil { - removeButtons() - setupWithTwoButtons() - } - } else if primaryButtonShowing { - heightConstraint?.isActive = false - if primaryButton == nil || secondaryButton != nil { - removeButtons() - setupWithPrimaryButton() - } - } else if secondaryButtonShowing { - heightConstraint?.isActive = false - if secondaryButton == nil || primaryButton != nil { - removeButtons() - setupWithSecondaryButton() - } - } else { - removeButtons() - if heightConstraint == nil { - heightConstraint = heightAnchor.constraint(equalToConstant: 0) - heightConstraint?.isActive = true - } - } - } - - open func set(primaryButtonJSON: [AnyHashable: Any]?, secondaryButtonJSON: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - setupUI(withPrimaryButtonMap: primaryButtonJSON, secondaryButtonMap: secondaryButtonJSON) - setDefaultCustom() - primaryButton?.setWithJSON(primaryButtonJSON, delegateObject: delegateObject, additionalData: additionalData) - secondaryButton?.setWithJSON(secondaryButtonJSON, delegateObject: delegateObject, additionalData: additionalData) - } - - // MARK: - Legacy - public convenience init(primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { - self.init() - setup(primaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) - } - - public convenience init(buttonSmall small: Bool, buttonMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: AnyHashable]?) { - self.init() - setup(withButtonMap: buttonMap, delegateObject: delegateObject, additionalData: additionalData) - primaryButton?.setAsSmall(small) - secondaryButton?.setAsSmall(small) - } - - public convenience init(buttonSmall small: Bool, enabled: Bool) { - self.init() - removeButtons() - setupWithPrimaryButton() - primaryButton?.setAsSmall(small) - primaryButton?.isEnabled = enabled - } - - open func setup(primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { - setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap) - if primaryButtonMap != nil, secondaryButtonMap != nil { - primaryButton?.setWithActionMap(primaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) - secondaryButton?.setWithActionMap(secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) - } else if primaryButtonMap != nil { - primaryButton?.setWithActionMap(primaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) - primaryButton?.bordered = false - } else if secondaryButtonMap != nil { - secondaryButton?.setWithActionMap(secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) - secondaryButton?.bordered = true - } - } - - open func setup(withButtonMap buttonMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { - let secondaryButtonMap = buttonMap?.optionalDictionaryForKey(KeySecondaryButton) - let primaryButtonMap = buttonMap?.optionalDictionaryForKey(KeyPrimaryButton) - setup(primaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) - } - - public func hideLeftButton() { - guard let secondaryButton = secondaryButton, !secondaryButton.isHidden else { - return - } - secondaryButton.isHidden = true - if let primaryButton = primaryButton { - primaryButton.removeFromSuperview() - viewForButtons?.addSubview(primaryButton) - NSLayoutConstraint.constraintPinSubview(toSuperview: primaryButton) - } - } - - public func hideRightButton() { - guard let primaryButton = primaryButton, !primaryButton.isHidden else { - return - } - primaryButton.isHidden = true - if let secondaryButton = secondaryButton { - secondaryButton.removeFromSuperview() - viewForButtons?.addSubview(secondaryButton) - NSLayoutConstraint.constraintPinSubview(toSuperview: secondaryButton) - } - } - - public func showBothButtons() { - primaryButton?.isHidden = false - secondaryButton?.isHidden = false - if let primaryButton = primaryButton, let secondaryButton = secondaryButton { - primaryButton.removeFromSuperview() - secondaryButton.removeFromSuperview() - setupConstraintsForViewWithButtons() - } - } - - public func hideBothButtons() { - primaryButton?.isHidden = true - secondaryButton?.isHidden = true - } - - override open func horizontalAlignment() -> UIStackView.Alignment { + + // MARK: - MVMCoreUIViewConstrainingProtocol + open func horizontalAlignment() -> UIStackView.Alignment { return .center } -} - -// MARK: - Deprecate -extension TwoButtonView { - @available(*, deprecated) - open func setup(primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?, actionDelegate: NSObjectProtocol?, additionalData: [AnyHashable: Any]?, buttonDelegate: Any?) { - setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap) - if primaryButtonMap != nil, secondaryButtonMap != nil { - primaryButton?.setWithActionMap(primaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) - secondaryButton?.setWithActionMap(secondaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) - } else if primaryButtonMap != nil { - primaryButton?.setWithActionMap(primaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) - primaryButton?.bordered = false - } else if secondaryButtonMap != nil { - secondaryButton?.setWithActionMap(secondaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) - secondaryButton?.bordered = true + + // MARK: - ModelMoleculeViewProtocol + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + guard let model = model as? TwoButtonViewModel else { return } + if let primaryModel = model.primaryButton { + showPrimaryButton() + primaryButton.setWithModel(primaryModel, delegateObject, additionalData) + } else { + hidePrimaryButton() + } + if let secondaryModel = model.secondaryButton { + showSecondaryButton() + secondaryButton.setWithModel(secondaryModel, delegateObject, additionalData) + } else { + hideSecondaryButton() } } - - @available(*, deprecated) - open func setup(withButtonMap buttonMap: [AnyHashable: Any]?, actionDelegate: NSObjectProtocol?, additionalData: [AnyHashable: Any]?, buttonDelegate: Any?) { - let secondaryButtonMap = buttonMap?.optionalDictionaryForKey(KeySecondaryButton) - let primaryButtonMap = buttonMap?.optionalDictionaryForKey(KeyPrimaryButton) - setup(primaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap, actionDelegate: actionDelegate, additionalData: additionalData, buttonDelegate: buttonDelegate) - } - - @available(*, deprecated) - public convenience init(buttonSmall small: Bool, buttonMap: [AnyHashable: Any]?, actionDelegate: NSObjectProtocol?, additionalData: [AnyHashable: AnyHashable]?, buttonDelegate: Any?) { - self.init() - setup(withButtonMap: buttonMap, actionDelegate: actionDelegate, additionalData: additionalData, buttonDelegate: buttonDelegate) - primaryButton?.setAsSmall(small) - secondaryButton?.setAsSmall(small) - } - - @available(*, deprecated) - public convenience init(primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?, actionDelegate: NSObjectProtocol?, additionalData: [AnyHashable: Any]?, buttonDelegate: Any?) { - self.init() - setup(primaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap, actionDelegate: actionDelegate, additionalData: additionalData, buttonDelegate: buttonDelegate) - } -} - -extension TwoButtonView: ModelMoleculeViewProtocol { - public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - guard let model = model as? TwoButtonViewModel else { return } - setupUI(primaryButtonShowing: model.primaryButton != nil, secondaryButtonShowing: model.secondaryButton != nil) - setDefaultCustom() - primaryButton?.setWithModel(model.primaryButton, delegateObject, additionalData) - secondaryButton?.setWithModel(model.secondaryButton, delegateObject, additionalData) - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - } } From 37228669e08678469549523d5bf2647a4f7f3ff7 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 31 Jan 2020 16:27:20 -0500 Subject: [PATCH 2/9] Two button remove legacy --- MVMCoreUI/Atoms/Buttons/ButtonModel.swift | 6 ++++ .../TwoButtonView.swift | 17 ++++++++++- .../TwoButtonViewModel.swift | 28 ++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift index 9eb284d7..cfe8bb2f 100644 --- a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift @@ -41,6 +41,12 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol { self.action = action } + init(secondaryButtonWith title: String, action: ActionModelProtocol) { + self.title = title + self.action = action + style = .secondary + } + private enum CodingKeys: String, CodingKey { case moleculeName case backgroundColor diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 9a4f31f9..a12bf03f 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -12,7 +12,8 @@ import UIKit open var primaryButton: PillButton = PillButton() open var secondaryButton: PillButton = PillButton() private var stack = UIStackView() - + private var equalWidthConstraint: NSLayoutConstraint? + public init() { super.init(frame: .zero) } @@ -47,31 +48,45 @@ import UIKit NSLayoutConstraint.constraintPinSubview(toSuperview: stack) stack.axis = .horizontal stack.spacing = 10 + equalWidthConstraint = secondaryButton.widthAnchor.constraint(equalTo: primaryButton.widthAnchor, multiplier: 1) + equalWidthConstraint?.isActive = true } // MARK: - Stack Manipulation public func showPrimaryButton() { if primaryButton.superview == nil { stack.addArrangedSubview(primaryButton) + primaryButton.isHidden = false + } + if secondaryButton.superview != nil { + equalWidthConstraint?.isActive = true } } public func showSecondaryButton() { if secondaryButton.superview == nil { stack.addArrangedSubview(secondaryButton) + secondaryButton.isHidden = false + } + if primaryButton.superview != nil { + equalWidthConstraint?.isActive = true } } public func hidePrimaryButton() { if primaryButton.superview != nil { stack.removeArrangedSubview(primaryButton) + primaryButton.isHidden = true } + equalWidthConstraint?.isActive = false } public func hideSecondaryButton() { if secondaryButton.superview != nil { stack.removeArrangedSubview(secondaryButton) + secondaryButton.isHidden = true } + equalWidthConstraint?.isActive = false } // MARK: - MVMCoreUIMoleculeViewProtocol diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift index a7abde9f..5938692b 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift @@ -8,9 +8,35 @@ import UIKit -public struct TwoButtonViewModel: MoleculeModelProtocol { +public class TwoButtonViewModel: MoleculeModelProtocol { public static var identifier: String = "twoButtonView" public var backgroundColor: Color? public var primaryButton: ButtonModel? public var secondaryButton: ButtonModel? + + private enum CodingKeys: String, CodingKey { + case moleculeName + case backgroundColor + case primaryButton + case secondaryButton + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + primaryButton = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .primaryButton) + secondaryButton = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .secondaryButton) + // Default value + if secondaryButton?.style == nil { + secondaryButton?.style = .secondary + } + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(primaryButton, forKey: .primaryButton) + try container.encodeIfPresent(secondaryButton, forKey: .secondaryButton) + } } From e2f1da7c276519ade5e87568f3da296c5a38dd36 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 31 Jan 2020 16:29:46 -0500 Subject: [PATCH 3/9] estimated height --- .../Molecules/HorizontalCombinationViews/TwoButtonView.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index a12bf03f..31fd6f37 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -101,6 +101,11 @@ import UIKit } // MARK: - ModelMoleculeViewProtocol + public override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + guard let model = molecule as? TwoButtonViewModel else { return 0 } + return PillButton.estimatedHeight(forRow: model.primaryButton ?? model.secondaryButton, delegateObject: delegateObject) + } + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) guard let model = model as? TwoButtonViewModel else { return } From 205e9707e6a92ec9c04bf2094d59cc73fee795f3 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 31 Jan 2020 16:37:24 -0500 Subject: [PATCH 4/9] move legacy --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++-- .../Views}/PrimaryButtonView.h | 0 .../Views}/PrimaryButtonView.m | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename MVMCoreUI/{Molecules/HorizontalCombinationViews => Legacy/Views}/PrimaryButtonView.h (100%) rename MVMCoreUI/{Molecules/HorizontalCombinationViews => Legacy/Views}/PrimaryButtonView.m (100%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index a35514cb..1a84907a 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -827,6 +827,8 @@ D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, + 94F217B423E0BF6100A47C06 /* PrimaryButtonView.h */, + 94F217B523E0BF6100A47C06 /* PrimaryButtonView.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, ); path = Views; @@ -871,8 +873,6 @@ D28A838E23CCDEDE00DFE4FC /* TwoButtonViewModel.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D28A837E23CCA96400DFE4FC /* TabsModel.swift */, - 94F217B423E0BF6100A47C06 /* PrimaryButtonView.h */, - 94F217B523E0BF6100A47C06 /* PrimaryButtonView.m */, ); path = HorizontalCombinationViews; sourceTree = ""; diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/PrimaryButtonView.h b/MVMCoreUI/Legacy/Views/PrimaryButtonView.h similarity index 100% rename from MVMCoreUI/Molecules/HorizontalCombinationViews/PrimaryButtonView.h rename to MVMCoreUI/Legacy/Views/PrimaryButtonView.h diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/PrimaryButtonView.m b/MVMCoreUI/Legacy/Views/PrimaryButtonView.m similarity index 100% rename from MVMCoreUI/Molecules/HorizontalCombinationViews/PrimaryButtonView.m rename to MVMCoreUI/Legacy/Views/PrimaryButtonView.m From 595dc99936ad24e1579b3c9d784d49756f21abfc Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 6 Feb 2020 09:50:03 -0500 Subject: [PATCH 5/9] button minimum caretLink --- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 38 +++++------------------ MVMCoreUI/Atoms/Buttons/PillButton.swift | 6 ++-- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 3fcf453a..97f8d55e 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -8,7 +8,7 @@ // -open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol, ModelMoleculeViewProtocol { +open class CaretButton: Button, MVMCoreUIViewConstrainingProtocol { //------------------------------------------------------ // MARK: - Constants @@ -49,7 +49,9 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI didSet { changeCaretColor() } } - public func updateView(_ size: CGFloat) { } + public override func updateView(_ size: CGFloat) { + titleLabel?.font = MFStyler.fontB1() + } //------------------------------------------------------ // MARK: - Methods @@ -115,33 +117,7 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI setTitleColor(disabledColor, for: .disabled) } - @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - setWithActionMap(json, delegateObject: delegateObject, additionalData: additionalData) - - guard let dictionary = json else { return } - - if let title = dictionary.optionalStringForKey(KeyTitle) { - setTitle(title, for: .normal) - } - - if let disableButtonAsAny = dictionary[KeyDisableButton], let isDisabled = disableButtonAsAny as? Bool { - isEnabled = !isDisabled - } - - if let backgroundColorHex = dictionary[KeyBackgroundColor] as? String { - backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) - } - - if let enabledColorHex = dictionary["enabledColor"] as? String { - enabledColor = UIColor.mfGet(forHex: enabledColorHex) - } - - if let disabledColorHex = dictionary["disabledColor"] as? String { - disabledColor = UIColor.mfGet(forHex: disabledColorHex) - } - } - - public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let caretLinkModel = model as? CaretLinkModel else { return } if let color = caretLinkModel.backgroundColor { backgroundColor = color.uiColor @@ -163,7 +139,7 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI return .leading } - public class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - return 10 + open override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return CARET_VIEW_HEIGHT } } diff --git a/MVMCoreUI/Atoms/Buttons/PillButton.swift b/MVMCoreUI/Atoms/Buttons/PillButton.swift index 0d0a3090..d3d09cee 100644 --- a/MVMCoreUI/Atoms/Buttons/PillButton.swift +++ b/MVMCoreUI/Atoms/Buttons/PillButton.swift @@ -97,9 +97,9 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol, FormValidation public static func getHeight(for buttonSize: ButtonSize?, size: CGFloat) -> CGFloat { switch buttonSize { case .tiny: - return MFSizeObject(standardSize: ButtonHeight.tiny.rawValue, standardiPadPortraitSize: 34, iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? 20 + return MFSizeObject(standardSize: ButtonHeight.tiny.rawValue, standardiPadPortraitSize: 34, iPadProLandscapeSize: 38)?.getValueBased(onSize: size) ?? ButtonHeight.tiny.rawValue default: - return MFSizeObject(standardSize: ButtonHeight.standard.rawValue, standardiPadPortraitSize: 46, iPadProLandscapeSize: 50)?.getValueBased(onSize: size) ?? 42 + return MFSizeObject(standardSize: ButtonHeight.standard.rawValue, standardiPadPortraitSize: 46, iPadProLandscapeSize: 50)?.getValueBased(onSize: size) ?? ButtonHeight.standard.rawValue } } @@ -108,7 +108,7 @@ open class PillButton: Button, MVMCoreUIViewConstrainingProtocol, FormValidation case .tiny: return MFSizeObject(standardSize: 49.0, standardiPadPortraitSize: 90.0, iPadProLandscapeSize: 135.0)?.getValueBased(onSize: size) ?? 49.0 default: - return MFSizeObject(standardSize: 102.0, standardiPadPortraitSize: 136.0, iPadProLandscapeSize: 153.0)?.getValueBased(onSize: size) ?? 102.0 + return 151.0 } } From 0d4008dec7210b32582b2360ebc36e6ea273f730 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 6 Feb 2020 09:55:18 -0500 Subject: [PATCH 6/9] CaretLink --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++++---- .../Atoms/Buttons/{CaretButton.swift => CaretLink.swift} | 6 +++--- .../HeadLineBodyCaretLinkImage.swift | 9 +-------- MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-) rename MVMCoreUI/Atoms/Buttons/{CaretButton.swift => CaretLink.swift} (97%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 752a5445..f97e81aa 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -327,7 +327,7 @@ DB06250B2293456500B72DD3 /* LeftRightLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */; }; DBC4391822442197001AB423 /* CaretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391622442196001AB423 /* CaretView.swift */; }; DBC4391922442197001AB423 /* DashLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391722442197001AB423 /* DashLine.swift */; }; - DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391A224421A0001AB423 /* CaretButton.swift */; }; + DBC4391B224421A0001AB423 /* CaretLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391A224421A0001AB423 /* CaretLink.swift */; }; DBC4392122491730001AB423 /* LabelWithInternalButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */; }; DBEFFA04225A829700230692 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB891E822253FA8500022516 /* Label.swift */; }; /* End PBXBuildFile section */ @@ -658,7 +658,7 @@ DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; DBC4391622442196001AB423 /* CaretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretView.swift; sourceTree = ""; }; DBC4391722442197001AB423 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = ""; }; - DBC4391A224421A0001AB423 /* CaretButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretButton.swift; sourceTree = ""; }; + DBC4391A224421A0001AB423 /* CaretLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretLink.swift; sourceTree = ""; }; DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelWithInternalButton.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -1168,7 +1168,7 @@ isa = PBXGroup; children = ( 01F2A03123A4498200D954D8 /* CaretLinkModel.swift */, - DBC4391A224421A0001AB423 /* CaretButton.swift */, + DBC4391A224421A0001AB423 /* CaretLink.swift */, D28A838A23CCDA6B00DFE4FC /* ButtonModel.swift */, D2E2A99E23E07F8A000B42E6 /* PillButton.swift */, D28A838823CCCFCB00DFE4FC /* LinkModel.swift */, @@ -1750,7 +1750,7 @@ 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, C003506123AA94CD00B6AC29 /* Button.swift in Sources */, - DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, + DBC4391B224421A0001AB423 /* CaretLink.swift in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, 0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */, 0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretLink.swift similarity index 97% rename from MVMCoreUI/Atoms/Buttons/CaretButton.swift rename to MVMCoreUI/Atoms/Buttons/CaretLink.swift index 405e110f..ca665928 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretLink.swift @@ -1,5 +1,5 @@ // -// CaretButton.swift +// CaretLink.swift // MVMCoreUI // // Created by Kolli, Praneeth on 1/5/18. @@ -8,7 +8,7 @@ // -open class CaretButton: Button, MVMCoreUIViewConstrainingProtocol { +open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { //------------------------------------------------------ // MARK: - Constants @@ -148,6 +148,6 @@ open class CaretButton: Button, MVMCoreUIViewConstrainingProtocol { } open override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return CARET_VIEW_HEIGHT + return 10.5 } } diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadLineBodyCaretLinkImage.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadLineBodyCaretLinkImage.swift index d5abe33f..2b3567d7 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadLineBodyCaretLinkImage.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadLineBodyCaretLinkImage.swift @@ -9,7 +9,7 @@ import Foundation @objcMembers public class HeadLineBodyCaretLinkImage: Container { let headlineBody = HeadlineBody(frame: .zero) - let caretButton = CaretButton(frame: .zero) + let caretButton = CaretLink(frame: .zero) let backgroundImageView = MFLoadImageView(pinnedEdges: .all) let maxWidth: CGFloat = 350.0 static let heightConstant: CGFloat = 320.0 @@ -66,13 +66,6 @@ import Foundation } // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - backgroundImageView.setWithJSON(json?.optionalDictionaryForKey("image"), delegateObject: delegateObject, additionalData: additionalData) - headlineBody.setWithJSON(json?.optionalDictionaryForKey("headlineBody"), delegateObject: delegateObject, additionalData: additionalData) - caretButton.setWithJSON(json?.optionalDictionaryForKey("caretLink"), delegateObject: delegateObject, additionalData: additionalData) - } - open override func reset() { super.reset() headlineBody.reset() diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index d3523ccf..8c1a36e3 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -30,7 +30,7 @@ import Foundation MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: PillButton.self, viewModelClass: ButtonModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: TwoButtonView.self, viewModelClass: TwoButtonViewModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Link.self, viewModelClass: LinkModel.self) - MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CaretButton.self, viewModelClass: CaretLinkModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CaretLink.self, viewModelClass: CaretLinkModel.self) // Entry Field MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: TextEntryField.self, viewModelClass: TextEntryFieldModel.self) From f24485c699ff6cc3c264ce6532a3eb78ab5b9d08 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 6 Feb 2020 11:59:45 -0500 Subject: [PATCH 7/9] fix button order --- .../TwoButtonView.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 31fd6f37..56004de8 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -43,8 +43,8 @@ import UIKit stack.translatesAutoresizingMaskIntoConstraints = false addSubview(stack) - stack.addArrangedSubview(primaryButton) stack.addArrangedSubview(secondaryButton) + stack.addArrangedSubview(primaryButton) NSLayoutConstraint.constraintPinSubview(toSuperview: stack) stack.axis = .horizontal stack.spacing = 10 @@ -107,19 +107,19 @@ import UIKit } public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + super.setWithModel(model, delegateObject, additionalData) guard let model = model as? TwoButtonViewModel else { return } - if let primaryModel = model.primaryButton { - showPrimaryButton() - primaryButton.setWithModel(primaryModel, delegateObject, additionalData) - } else { - hidePrimaryButton() - } if let secondaryModel = model.secondaryButton { showSecondaryButton() secondaryButton.setWithModel(secondaryModel, delegateObject, additionalData) } else { hideSecondaryButton() } + if let primaryModel = model.primaryButton { + showPrimaryButton() + primaryButton.setWithModel(primaryModel, delegateObject, additionalData) + } else { + hidePrimaryButton() + } } } From 00b179d8c27f2d9f21e2545f1a8be698de68c5b0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 6 Feb 2020 12:09:35 -0500 Subject: [PATCH 8/9] fix to reuse issue two button view --- .../HorizontalCombinationViews/TwoButtonView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 56004de8..be6228f8 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -54,7 +54,7 @@ import UIKit // MARK: - Stack Manipulation public func showPrimaryButton() { - if primaryButton.superview == nil { + if !stack.arrangedSubviews.contains(primaryButton) { stack.addArrangedSubview(primaryButton) primaryButton.isHidden = false } @@ -64,8 +64,8 @@ import UIKit } public func showSecondaryButton() { - if secondaryButton.superview == nil { - stack.addArrangedSubview(secondaryButton) + if !stack.arrangedSubviews.contains(secondaryButton) { + stack.insertArrangedSubview(secondaryButton, at: 0) secondaryButton.isHidden = false } if primaryButton.superview != nil { From 0dad2aedb1b7610faa9b3cacb256071309296ff4 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 6 Feb 2020 13:00:55 -0500 Subject: [PATCH 9/9] type fix --- MVMCoreUI/Templates/ThreeLayerPageTemplateModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Templates/ThreeLayerPageTemplateModel.swift b/MVMCoreUI/Templates/ThreeLayerPageTemplateModel.swift index fa7548f3..689a7c62 100644 --- a/MVMCoreUI/Templates/ThreeLayerPageTemplateModel.swift +++ b/MVMCoreUI/Templates/ThreeLayerPageTemplateModel.swift @@ -41,7 +41,7 @@ import Foundation screenHeading = try typeContainer.decodeIfPresent(String.self, forKey: .screenHeading) isAtomicTabs = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAtomicTabs) header = try typeContainer.decodeMoleculeIfPresent(codingKey: .header) - header = try typeContainer.decodeMoleculeIfPresent(codingKey: .middle) + middle = try typeContainer.decodeMoleculeIfPresent(codingKey: .middle) footer = try typeContainer.decodeMoleculeIfPresent(codingKey: .footer) }