From a5186973ae93d0cb2c174cb9986cfa7ad317a865 Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Mon, 11 Nov 2019 21:27:08 +0530 Subject: [PATCH 1/4] Adding support for secondaryButton, if server dynamically sends only secondary button in TwoButtonView molecule. --- .../TwoButtonView.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 28ad6dc4..592abb36 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -125,6 +125,18 @@ import UIKit } } + open func setupWithSecondaryButton() { + guard self.secondaryButton == nil else { + return + } + createSecondaryButton() + if let secondaryButton = secondaryButton { + addSubview(secondaryButton) + pinView(toSuperView: secondaryButton) + alignCenterHorizontal() + } + } + // Sets up the number of buttons based on the maps. Doesn't set the buttons with the maps because legacy code handles differently from modern code... func setupUI(withPrimaryButtonMap primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?, legacy: Bool) { if primaryButtonMap != nil, secondaryButtonMap != nil { @@ -140,6 +152,10 @@ import UIKit removeButtons() setupWithPrimaryButton() } + } else if secondaryButtonMap != nil { + heightConstraint?.isActive = false + removeButtons() + setupWithSecondaryButton() } else { removeButtons() if heightConstraint == nil { From f6c2935115eebfd75e2c23813296844a14034e7e Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Mon, 11 Nov 2019 22:41:24 +0530 Subject: [PATCH 2/4] Implemented Scott feedback. --- .../TwoButtonView.swift | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index 592abb36..bc45f67d 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -114,7 +114,8 @@ import UIKit } open func setupWithPrimaryButton() { - guard self.primaryButton == nil else { + // should not allow primaryButton addition, if secondaryButton exists + guard (self.primaryButton == nil && self.secondaryButton == nil) else { return } createPrimaryButton() @@ -126,7 +127,8 @@ import UIKit } open func setupWithSecondaryButton() { - guard self.secondaryButton == nil else { + // should not allow secondaryButton addition, if primaryButton exists + guard (self.secondaryButton == nil && self.primaryButton == nil) else { return } createSecondaryButton() @@ -137,16 +139,14 @@ import UIKit } } - // Sets up the number of buttons based on the maps. Doesn't set the buttons with the maps because legacy code handles differently from modern code... - func setupUI(withPrimaryButtonMap primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?, legacy: Bool) { + func setupUI(withPrimaryButtonMap primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?) { if primaryButtonMap != nil, secondaryButtonMap != nil { heightConstraint?.isActive = false if primaryButton == nil || secondaryButton == nil { removeButtons() setupWithTwoButtons() } - } else if primaryButtonMap != nil || (secondaryButtonMap != nil && legacy) { - // Only legacy sets up the primary button with a secondary map + } else if primaryButtonMap != nil { heightConstraint?.isActive = false if primaryButton == nil || secondaryButton != nil { removeButtons() @@ -166,7 +166,7 @@ import UIKit } open func set(primaryButtonJSON: [AnyHashable: Any]?, secondaryButtonJSON: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { - setupUI(withPrimaryButtonMap: primaryButtonJSON, secondaryButtonMap: secondaryButtonJSON, legacy: false) + setupUI(withPrimaryButtonMap: primaryButtonJSON, secondaryButtonMap: secondaryButtonJSON) setDefaultCustom() primaryButton?.setWithJSON(primaryButtonJSON, delegateObject: delegateObject, additionalData: additionalData) secondaryButton?.setWithJSON(secondaryButtonJSON, delegateObject: delegateObject, additionalData: additionalData) @@ -194,7 +194,7 @@ import UIKit } open func setup(primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { - setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap, legacy: true) + setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap) if primaryButtonMap != nil, secondaryButtonMap != nil { primaryButton?.setWithActionMap(primaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) secondaryButton?.setWithActionMap(secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) @@ -202,8 +202,8 @@ import UIKit primaryButton?.setWithActionMap(primaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) primaryButton?.bordered = false } else if secondaryButtonMap != nil { - primaryButton?.setWithActionMap(secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) - primaryButton?.bordered = true + secondaryButton?.setWithActionMap(secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) + secondaryButton?.bordered = true } } @@ -213,7 +213,7 @@ import UIKit setup(primaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) } - public func hidePrimaryLeftButton() { + public func hideLeftButton() { guard let secondaryButton = secondaryButton, !secondaryButton.isHidden else { return } @@ -225,7 +225,7 @@ import UIKit } } - public func hidePrimaryRightButton() { + public func hideRightButton() { guard let primaryButton = primaryButton, !primaryButton.isHidden else { return } @@ -237,7 +237,7 @@ import UIKit } } - public func showBothPrimaryButtons() { + public func showBothButtons() { primaryButton?.isHidden = false secondaryButton?.isHidden = false if let primaryButton = primaryButton, let secondaryButton = secondaryButton { @@ -247,7 +247,7 @@ import UIKit } } - public func hideBothPrimaryButtons() { + public func hideBothButtons() { primaryButton?.isHidden = true secondaryButton?.isHidden = true } @@ -257,7 +257,7 @@ import UIKit 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, legacy: true) + 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) @@ -265,8 +265,8 @@ extension TwoButtonView { primaryButton?.setWithActionMap(primaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) primaryButton?.bordered = false } else if secondaryButtonMap != nil { - primaryButton?.setWithActionMap(secondaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) - primaryButton?.bordered = true + secondaryButton?.setWithActionMap(secondaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) + secondaryButton?.bordered = true } } From 11e549bc501c2245ff8a701dcb10ad9f87cbea3e Mon Sep 17 00:00:00 2001 From: "Khan, Arshad" Date: Mon, 11 Nov 2019 22:47:49 +0530 Subject: [PATCH 3/4] Feedback implementation impact changes. --- .../TopLabelsAndBottomButtonsTableViewController.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsTableViewController.m b/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsTableViewController.m index 5d6a6778..8b0a23bf 100644 --- a/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsTableViewController.m +++ b/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsTableViewController.m @@ -427,13 +427,13 @@ if ([self.bottomView isKindOfClass:[TwoButtonView class]]) { TwoButtonView *buttonView = (TwoButtonView *)self.bottomView; if (right && !left) { - [buttonView hidePrimaryRightButton]; + [buttonView hideRightButton]; } else if (!right && left) { - [buttonView hidePrimaryLeftButton]; + [buttonView hideLeftButton]; } else if (right && left) { - [buttonView hideBothPrimaryButtons]; + [buttonView hideBothButtons]; } else if (!right && !left) { - [buttonView showBothPrimaryButtons]; + [buttonView showBothButtons]; } } } From f9cecb9a5d2370c69c2f97ed2c85ed2b2acf3aa1 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 11 Nov 2019 15:24:10 -0500 Subject: [PATCH 4/4] small code updates --- .../HorizontalCombinationViews/TwoButtonView.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift index bc45f67d..2c5f0fe5 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonView.swift @@ -98,7 +98,7 @@ import UIKit } func setupWithTwoButtons() { - guard self.viewForButtons == nil else { + guard viewForButtons == nil else { return } let viewForButtons = MVMCoreUICommonViewsUtility.commonView() @@ -114,8 +114,7 @@ import UIKit } open func setupWithPrimaryButton() { - // should not allow primaryButton addition, if secondaryButton exists - guard (self.primaryButton == nil && self.secondaryButton == nil) else { + guard primaryButton == nil && secondaryButton == nil else { return } createPrimaryButton() @@ -127,8 +126,7 @@ import UIKit } open func setupWithSecondaryButton() { - // should not allow secondaryButton addition, if primaryButton exists - guard (self.secondaryButton == nil && self.primaryButton == nil) else { + guard secondaryButton == nil && primaryButton == nil else { return } createSecondaryButton() @@ -154,8 +152,10 @@ import UIKit } } else if secondaryButtonMap != nil { heightConstraint?.isActive = false - removeButtons() - setupWithSecondaryButton() + if secondaryButton == nil || primaryButton != nil { + removeButtons() + setupWithSecondaryButton() + } } else { removeButtons() if heightConstraint == nil {