From a2ab8c6571a09771cd7da684b2c307d3bf2be8b4 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Mar 2019 09:37:54 -0400 Subject: [PATCH 1/7] swifty buttons --- MVMCoreUI.xcodeproj/project.pbxproj | 10 +- MVMCoreUI/Atoms/Buttons/PrimaryButton.h | 2 +- MVMCoreUI/Atoms/Buttons/PrimaryButton.m | 2 +- ...abelsAndBottomButtonsTableViewController.m | 8 +- .../TopLabelsAndBottomButtonsViewController.m | 14 +- MVMCoreUI/MVMCoreUI.h | 1 - MVMCoreUI/Molecules/ButtonView.swift | 135 ++++++++++++ MVMCoreUI/Molecules/StandardFooterView.swift | 8 +- MVMCoreUI/Molecules/TwoButtonView.swift | 199 ++++++++++++++++++ .../MVMCoreUIMoleculeMappingObject.m | 4 +- 10 files changed, 362 insertions(+), 21 deletions(-) create mode 100644 MVMCoreUI/Molecules/ButtonView.swift create mode 100644 MVMCoreUI/Molecules/TwoButtonView.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index a222046d..b406d4f2 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; }; D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */; settings = {ATTRIBUTES = (Public, ); }; }; D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationController.m */; }; + D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */; }; D22D1F1A220341F60077CEC0 /* MVMCoreUICheckBox.h in Headers */ = {isa = PBXBuildFile; fileRef = D22D1F18220341F50077CEC0 /* MVMCoreUICheckBox.h */; settings = {ATTRIBUTES = (Public, ); }; }; D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */ = {isa = PBXBuildFile; fileRef = D22D1F19220341F50077CEC0 /* MVMCoreUICheckBox.m */; }; D22D1F1E220343560077CEC0 /* MVMCoreUICheckMarkView.h in Headers */ = {isa = PBXBuildFile; fileRef = D22D1F1C220343560077CEC0 /* MVMCoreUICheckMarkView.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -22,6 +23,7 @@ D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D274CA322236A78900B01B62 /* StandardFooterView.swift */; }; D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */; }; D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */; }; + D282AACB2243C61700C46919 /* ButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AACA2243C61700C46919 /* ButtonView.swift */; }; D28B4F8A21FF967C00712C7A /* MVMCoreUIObject.h in Headers */ = {isa = PBXBuildFile; fileRef = D28B4F8821FF967C00712C7A /* MVMCoreUIObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; D28B4F8B21FF967C00712C7A /* MVMCoreUIObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D28B4F8921FF967C00712C7A /* MVMCoreUIObject.m */; }; D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */; }; @@ -30,7 +32,6 @@ D29770F321F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770EF21F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770F421F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770F021F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770F521F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770F121F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m */; }; - D29770F821F7C73800B2F0D0 /* PrimaryButtonView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770F621F7C73800B2F0D0 /* PrimaryButtonView.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770F921F7C73800B2F0D0 /* PrimaryButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770F721F7C73800B2F0D0 /* PrimaryButtonView.m */; }; D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770FA21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m */; }; D29770FD21F7C77400B2F0D0 /* MVMCoreUITextFieldView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770FB21F7C77400B2F0D0 /* MVMCoreUITextFieldView.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -165,6 +166,7 @@ 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = ""; }; D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = ""; }; D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUINavigationController.m; sourceTree = ""; }; + D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonView.swift; sourceTree = ""; }; D22D1F18220341F50077CEC0 /* MVMCoreUICheckBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUICheckBox.h; sourceTree = ""; }; D22D1F19220341F50077CEC0 /* MVMCoreUICheckBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUICheckBox.m; sourceTree = ""; }; D22D1F1C220343560077CEC0 /* MVMCoreUICheckMarkView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUICheckMarkView.h; sourceTree = ""; }; @@ -176,6 +178,7 @@ D274CA322236A78900B01B62 /* StandardFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardFooterView.swift; sourceTree = ""; }; D282AAB3223FDDAE00C46919 /* MFLoadImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFLoadImageView.swift; sourceTree = ""; }; D282AAB9224131D100C46919 /* MFTransparentGIFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFTransparentGIFView.swift; sourceTree = ""; }; + D282AACA2243C61700C46919 /* ButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonView.swift; sourceTree = ""; }; D28B4F8821FF967C00712C7A /* MVMCoreUIObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIObject.h; sourceTree = ""; }; D28B4F8921FF967C00712C7A /* MVMCoreUIObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIObject.m; sourceTree = ""; }; D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopLabelsView.m; sourceTree = ""; }; @@ -417,6 +420,8 @@ 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */, D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */, D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, + D282AACA2243C61700C46919 /* ButtonView.swift */, + D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, D29770F621F7C73800B2F0D0 /* PrimaryButtonView.h */, D29770F721F7C73800B2F0D0 /* PrimaryButtonView.m */, D2A514662213885800345BFB /* StandardHeaderView.swift */, @@ -746,7 +751,6 @@ D2A5145D2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h in Headers */, D28B4F8A21FF967C00712C7A /* MVMCoreUIObject.h in Headers */, D29DF2CA21E7BFC8003B2FB9 /* MFSizeThreshold.h in Headers */, - D29770F821F7C73800B2F0D0 /* PrimaryButtonView.h in Headers */, D29DF28021E7AA51003B2FB9 /* MVMCoreUIDetailViewProtocol.h in Headers */, D29DF2BD21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.h in Headers */, D29DF2EE21ECEADF003B2FB9 /* MFFonts.h in Headers */, @@ -877,6 +881,7 @@ D28B4F8B21FF967C00712C7A /* MVMCoreUIObject.m in Sources */, D29DF26D21E6AA0B003B2FB9 /* FLAnimatedImageView.m in Sources */, D29DF2EF21ECEAE1003B2FB9 /* MFFonts.m in Sources */, + D282AACB2243C61700C46919 /* ButtonView.swift in Sources */, D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */, D29DF18121E69E50003B2FB9 /* MFView.m in Sources */, D29DF18321E69E54003B2FB9 /* SeparatorView.m in Sources */, @@ -901,6 +906,7 @@ D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */, D29DF29821E7ADB8003B2FB9 /* MFScrollingViewController.m in Sources */, D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */, + D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */, D29DF2AA21E7B2F9003B2FB9 /* MVMCoreUIConstants.m in Sources */, D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */, D29DF17821E69E1F003B2FB9 /* MFCaretButton.m in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.h b/MVMCoreUI/Atoms/Buttons/PrimaryButton.h index 182a527b..fb93c33a 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.h +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.h @@ -51,7 +51,7 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0; + (nullable instancetype)primarySmallButton:(BOOL)enabled; + (nullable instancetype)primaryTinyButton:(BOOL)enabled; -+ (nullable instancetype)primaryButton; ++ (nonnull instancetype)primaryButton NS_SWIFT_NAME(button()); + (nullable instancetype)primarySmallButton; + (nullable instancetype)primaryWhiteButton:(BOOL)small; diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m index 960e29e7..a13a693c 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m @@ -547,7 +547,7 @@ return button; } -+ (nullable instancetype)primaryButton { ++ (nonnull instancetype)primaryButton { PrimaryButton *button = [self getButton]; button.primaryButtonType = PrimaryButtonTypeBlack; [button setAsBlack]; diff --git a/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsTableViewController.m b/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsTableViewController.m index e68fda0f..7a16405b 100644 --- a/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsTableViewController.m +++ b/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsTableViewController.m @@ -7,7 +7,6 @@ // #import "TopLabelsAndBottomButtonsTableViewController.h" -#import #import #import #import @@ -18,6 +17,7 @@ #import #import #import +#import @import MVMAnimationFramework; @@ -117,7 +117,7 @@ // Sets up the buttons/button. NSDictionary *primaryButtonDictionary = [self primaryButtonMap]; NSDictionary *secondaryButtonDictionary = [self secondaryButtonMap]; - PrimaryButtonView *buttonView = [[PrimaryButtonView alloc] initWithPrimaryButtonMap:primaryButtonDictionary secondaryButtonMap:secondaryButtonDictionary actionDelegate:self additionalData:nil buttonDelegate:self]; + TwoButtonView *buttonView = [[TwoButtonView alloc] initWithPrimaryButtonMap:primaryButtonDictionary secondaryButtonMap:secondaryButtonDictionary actionDelegate:self additionalData:nil buttonDelegate:self]; self.secondaryButton = buttonView.secondaryButton; self.primaryButton = buttonView.primaryButton; @@ -430,8 +430,8 @@ - (void)setPrimaryLeftButtonHidden:(BOOL)left rightButtonHidden:(BOOL)right { - if ([self.bottomView isKindOfClass:[PrimaryButtonView class]]) { - PrimaryButtonView *buttonView = (PrimaryButtonView *)self.bottomView; + if ([self.bottomView isKindOfClass:[TwoButtonView class]]) { + TwoButtonView *buttonView = (TwoButtonView *)self.bottomView; if (right && !left) { [buttonView hidePrimaryRightButton]; } else if (!right && left) { diff --git a/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsViewController.m b/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsViewController.m index 4d2bc3c6..be14e149 100644 --- a/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsViewController.m +++ b/MVMCoreUI/LegacyControllers/TopLabelsAndBottomButtonsViewController.m @@ -7,7 +7,6 @@ // #import "TopLabelsAndBottomButtonsViewController.h" -#import #import #import #import @@ -18,6 +17,7 @@ #import #import #import +#import @import MVMAnimationFramework; @@ -80,18 +80,18 @@ } if (!self.customBottemView) { - PrimaryButtonView *buttonView = (PrimaryButtonView *)self.bottomView; + TwoButtonView *buttonView = (TwoButtonView *)self.bottomView; if (self.secondaryButton || self.primaryButton) { UIEdgeInsets paddingForBottomButtons = [self paddingForBottomButtons]; - buttonView.leftPin.constant = paddingForBottomButtons.left; - buttonView.rightPin.constant = paddingForBottomButtons.right; + [buttonView setLeftPinConstant:paddingForBottomButtons.left]; + [buttonView setRightPinConstant:paddingForBottomButtons.right]; buttonView.topPin.constant = paddingForBottomButtons.top; buttonView.bottomPin.constant = paddingForBottomButtons.bottom; } else { buttonView.topPin.constant = 0; buttonView.bottomPin.constant = 0; - buttonView.leftPin.constant = 0; - buttonView.rightPin.constant = 0; + [buttonView setLeftPinConstant:0]; + [buttonView setRightPinConstant:0]; } } } @@ -127,7 +127,7 @@ // Sets up the buttons/button. NSDictionary *primaryButtonDictionary = [self primaryButtonMap]; NSDictionary *secondaryButtonDictionary = [self secondaryButtonMap]; - PrimaryButtonView *buttonView = [[PrimaryButtonView alloc] initWithPrimaryButtonMap:primaryButtonDictionary secondaryButtonMap:secondaryButtonDictionary actionDelegate:self additionalData:nil buttonDelegate:self]; + TwoButtonView *buttonView = [[TwoButtonView alloc] initWithPrimaryButtonMap:primaryButtonDictionary secondaryButtonMap:secondaryButtonDictionary actionDelegate:self additionalData:nil buttonDelegate:self]; self.secondaryButton = buttonView.secondaryButton; self.primaryButton = buttonView.primaryButton; bottomView = buttonView; diff --git a/MVMCoreUI/MVMCoreUI.h b/MVMCoreUI/MVMCoreUI.h index 3a8029c4..96f585d0 100644 --- a/MVMCoreUI/MVMCoreUI.h +++ b/MVMCoreUI/MVMCoreUI.h @@ -109,7 +109,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[]; #pragma mark - Molecules #import -#import #import #pragma mark - Templates diff --git a/MVMCoreUI/Molecules/ButtonView.swift b/MVMCoreUI/Molecules/ButtonView.swift new file mode 100644 index 00000000..04be7ba5 --- /dev/null +++ b/MVMCoreUI/Molecules/ButtonView.swift @@ -0,0 +1,135 @@ +// +// ButtonView.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 3/21/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers open class ButtonView: ViewConstrainingView { + open var primaryButton: PrimaryButton? = PrimaryButton.button() + open var alignCenterPin: NSLayoutConstraint? + open var alignCenterLeftPin: NSLayoutConstraint? + open var alignCenterRightPin: NSLayoutConstraint? + + // MARK: - Inits + public init() { + super.init(frame: .zero) + } + + public override init(frame: CGRect) { + super.init(frame: frame) + } + + required public init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + public convenience init(buttonSmall small: Bool, enabled: Bool) { + self.init() + primaryButton?.setAsSmall(small) + primaryButton?.isEnabled = enabled + } + + public init(withJSON json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, actionDelegate: NSObject?, buttonDelegate: Any?) { + super.init(frame: .zero) + setWithJSON(json, delegate: actionDelegate, additionalData: additionalData) + } + + // MARK: - MVMCoreViewProtocol + open override func updateView(_ size: CGFloat) { + super.updateView(size) + MVMCoreDispatchUtility.performBlock(onMainThread: { + self.primaryButton?.updateView(size) + }) + } + + open override func setupView() { + super.setupView() + setupButton() + alignCenter() + } + + // MARK: - MVMCoreUIMoleculeViewProtocol + open override func setAsMolecule() { + super.setAsMolecule() + primaryButton?.setAsMolecule() + } + + open override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) { + super.setWithJSON(json, delegate: delegate, additionalData: additionalData) + primaryButton?.setWithJSON(json, delegate: delegate, additionalData: additionalData) + } + + // MARK: - Constraining + func setupButton() { + if let primaryButton = primaryButton, !subviews.contains(primaryButton) { + addSubview(primaryButton) + setupConstraints(forView: primaryButton) + } + } + + func setupConstraints(forView view: UIView) { + leftPin = view.leftAnchor.constraint(equalTo: leftAnchor) + topPin = view.topAnchor.constraint(equalTo: topAnchor) + rightPin = rightAnchor.constraint(equalTo: view.rightAnchor) + bottomPin = bottomAnchor.constraint(equalTo: view.bottomAnchor) + leftPin?.isActive = true + topPin?.isActive = true + rightPin?.isActive = true + bottomPin?.isActive = true + + alignCenterPin = view.centerXAnchor.constraint(equalTo: centerXAnchor) + alignCenterLeftPin = view.leftAnchor.constraint(greaterThanOrEqualTo: leftAnchor) + alignCenterRightPin = rightAnchor.constraint(greaterThanOrEqualTo: view.rightAnchor) + } + + open func alignLeft() { + alignCenterPin?.isActive = false + alignCenterLeftPin?.isActive = false + alignCenterRightPin?.isActive = true + leftPin?.isActive = true + rightPin?.isActive = false + } + + open func alignCenter() { + alignCenterPin?.isActive = true + alignCenterLeftPin?.isActive = true + alignCenterRightPin?.isActive = true + leftPin?.isActive = false + rightPin?.isActive = false + } + + open func alignFill() { + alignCenterPin?.isActive = false + alignCenterLeftPin?.isActive = false + alignCenterRightPin?.isActive = false + leftPin?.isActive = true + rightPin?.isActive = false + } + + open func alignRight() { + alignCenterPin?.isActive = false + alignCenterLeftPin?.isActive = true + alignCenterRightPin?.isActive = false + leftPin?.isActive = false + rightPin?.isActive = true + } + + open override func setLeftPinConstant(_ constant: CGFloat) { + super.setLeftPinConstant(constant) + alignCenterLeftPin?.constant = constant + } + + open override func setRightPinConstant(_ constant: CGFloat) { + super.setRightPinConstant(constant) + alignCenterRightPin?.constant = constant + } + + open override func resetConstraints() { + super.resetConstraints() + primaryButton?.isEnabled = false + } +} diff --git a/MVMCoreUI/Molecules/StandardFooterView.swift b/MVMCoreUI/Molecules/StandardFooterView.swift index 1e1f7b76..2cf85302 100644 --- a/MVMCoreUI/Molecules/StandardFooterView.swift +++ b/MVMCoreUI/Molecules/StandardFooterView.swift @@ -9,7 +9,7 @@ import UIKit public class StandardFooterView: ViewConstrainingView { - let twoButtonView = PrimaryButtonView(frame: .zero) + let twoButtonView = TwoButtonView(frame: .zero) var textButton = MFTextButton(nil, constrainHeight: true, forWidth: MVMCoreUIUtility.getWidth()) var spaceBetweenButtons: NSLayoutConstraint? var leftConstraintTwoButton: NSLayoutConstraint? @@ -34,7 +34,9 @@ public class StandardFooterView: ViewConstrainingView { translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear clipsToBounds = true - + setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical) + setContentCompressionResistancePriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical) + addSubview(twoButtonView) addSubview(textButton) @@ -66,7 +68,7 @@ public class StandardFooterView: ViewConstrainingView { } public func setSpacing() { - if twoButtonView.subviews.count > 0 && textButton.title(for: UIControl.State.normal)?.count ?? 0 > 0 { + if !(twoButtonView.heightConstraint?.isActive ?? false) && textButton.title(for: UIControl.State.normal)?.count ?? 0 > 0 { spaceBetweenButtons?.constant = PaddingTwo show() } else if twoButtonView.subviews.count > 0 || textButton.title(for: UIControl.State.normal)?.count ?? 0 > 0 { diff --git a/MVMCoreUI/Molecules/TwoButtonView.swift b/MVMCoreUI/Molecules/TwoButtonView.swift new file mode 100644 index 00000000..4ae821d2 --- /dev/null +++ b/MVMCoreUI/Molecules/TwoButtonView.swift @@ -0,0 +1,199 @@ +// +// TwoButtonView.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 3/21/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers open class TwoButtonView: ButtonView { + open var secondaryButton: PrimaryButton? + open var viewForButtons = MVMCoreUICommonViewsUtility.commonView() + public var heightConstraint: NSLayoutConstraint? + + public override init() { + super.init(frame: .zero) + } + + required public init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + public override init(frame: CGRect) { + super.init(frame: frame) + } + + // MARK: - MVMCoreViewProtocol + open override func updateView(_ size: CGFloat) { + super.updateView(size) + MVMCoreDispatchUtility.performBlock(onMainThread: { + self.secondaryButton?.updateView(size) + }) + } + + // MARK: - MVMCoreUIMoleculeViewProtocol + open override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) { + super.setWithJSON(json, delegate: delegate, additionalData: additionalData) + if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) { + backgroundColor = UIColor.mfGet(forHex: backgroundColorString) + } + let primaryButtonMap = json?.optionalDictionaryForKey("primaryButton") + let secondaryButtonMap = json?.optionalDictionaryForKey("secondaryButton") + setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap) + primaryButton?.setAsStandardCustom() + secondaryButton?.setAsSecondaryCustom() + primaryButton?.setWithJSON(primaryButtonMap, delegate: delegate, additionalData: additionalData) + secondaryButton?.setWithJSON(secondaryButtonMap, delegate: delegate, additionalData: additionalData) + } + + // MARK: - Constraining + override func setupButton() { + guard viewForButtons.superview != self else { + return + } + addSubview(viewForButtons) + setupConstraints(forView: viewForButtons) + setupWithTwoButtons() + } + + open func setupWithTwoButtons() { + guard viewForButtons != primaryButton?.superview && viewForButtons != secondaryButton?.superview else { + return + } + if let primaryButton = primaryButton { + primaryButton.removeFromSuperview() + } else { + primaryButton = PrimaryButton.button() + } + if let secondaryButton = secondaryButton { + secondaryButton.removeFromSuperview() + } else { + secondaryButton = PrimaryButton.button() + secondaryButton?.bordered = true + } + guard let primaryButton = primaryButton, let secondaryButton = secondaryButton else { + return + } + viewForButtons.addSubview(primaryButton) + viewForButtons.addSubview(secondaryButton) + secondaryButton.widthAnchor.constraint(equalTo: primaryButton.widthAnchor, multiplier: 1).isActive = true + secondaryButton.topAnchor.constraint(equalTo: viewForButtons.topAnchor).isActive = true + primaryButton.topAnchor.constraint(equalTo: viewForButtons.topAnchor).isActive = true + viewForButtons.bottomAnchor.constraint(equalTo: secondaryButton.bottomAnchor).isActive = true + viewForButtons.bottomAnchor.constraint(equalTo: primaryButton.bottomAnchor).isActive = true + NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[leftButton]-10-[rightButton]-0-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterY, metrics: nil, views: ["leftButton": secondaryButton, "rightButton": primaryButton])) + } + + open func setupWithPrimaryButton() { + primaryButton?.removeFromSuperview() + secondaryButton?.removeFromSuperview() + secondaryButton = nil + if primaryButton == nil { + primaryButton = PrimaryButton.button() + } + setupWithOneButton(primaryButton!) + } + + open func setupWithSecondaryButton() { + primaryButton?.removeFromSuperview() + secondaryButton?.removeFromSuperview() + primaryButton = nil + if secondaryButton == nil { + secondaryButton = PrimaryButton.button() + secondaryButton?.bordered = true + } + setupWithOneButton(secondaryButton!) + } + + func setupWithOneButton(_ button: PrimaryButton) { + viewForButtons.addSubview(button) + button.topAnchor.constraint(equalTo: viewForButtons.topAnchor).isActive = true + button.leftAnchor.constraint(equalTo: viewForButtons.leftAnchor).isActive = true + viewForButtons.rightAnchor.constraint(equalTo: button.rightAnchor).isActive = true + viewForButtons.bottomAnchor.constraint(equalTo: button.bottomAnchor).isActive = true + } + + open func setupUI(withPrimaryButtonMap primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?) { + if primaryButtonMap != nil, secondaryButtonMap != nil { + heightConstraint?.isActive = false + setupWithTwoButtons() + } else if primaryButtonMap != nil || secondaryButtonMap != nil { + heightConstraint?.isActive = false + setupWithPrimaryButton() + } else { + primaryButton?.removeFromSuperview() + secondaryButton?.removeFromSuperview() + primaryButton = nil + secondaryButton = nil + if heightConstraint == nil { + self.heightConstraint = heightAnchor.constraint(equalToConstant: 0) + self.heightConstraint?.isActive = true + } + } + } + + // MARK: - Legacy + 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) + } + + 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) + } else { + primaryButton?.setWithActionMap(secondaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) + } + } + + public convenience init(buttonSmall small: Bool, enabled: Bool) { + self.init() + setupWithPrimaryButton() + primaryButton?.setAsSmall(small) + primaryButton?.isEnabled = enabled + } + + 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: buttonMap) + primaryButton?.setAsSmall(small) + secondaryButton?.setAsSmall(small) + } + + 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) + } + + public func hidePrimaryLeftButton() { + if let secondaryButton = secondaryButton, !secondaryButton.isHidden { + secondaryButton.isHidden = true + setupWithPrimaryButton() + } + } + + public func hidePrimaryRightButton() { + if let primaryButton = primaryButton, !primaryButton.isHidden { + primaryButton.isHidden = true + setupWithSecondaryButton() + } + } + + public func showBothPrimaryButtons() { + primaryButton?.isHidden = false + secondaryButton?.isHidden = false + setupWithTwoButtons() + } + + public func hideBothPrimaryButtons() { + primaryButton?.isHidden = true + secondaryButton?.isHidden = true + } +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 3c36a612..304f8faf 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -23,11 +23,11 @@ mapping = [@{ @"label": LabelView.class, @"separator": SeparatorView.class, - @"button": MFCustomButton.class, + @"button": ButtonView.class, @"textButton": MFTextButton.class, @"standardHeader": StandardHeaderView.class, @"moleculeStack": MoleculeStackView.class, - @"twoButtonView": PrimaryButtonView.class, + @"twoButtonView": TwoButtonView.class, @"standardFooter": StandardFooterView.class } mutableCopy]; }); From b7556fdce949d3eeb3d75544a08ead42dbf4ba88 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Mar 2019 09:57:47 -0400 Subject: [PATCH 2/7] merge --- MVMCoreUI.xcodeproj/project.pbxproj | 6 - MVMCoreUI/Molecules/PrimaryButtonView.h | 53 ---- MVMCoreUI/Molecules/PrimaryButtonView.m | 350 ------------------------ 3 files changed, 409 deletions(-) delete mode 100644 MVMCoreUI/Molecules/PrimaryButtonView.h delete mode 100644 MVMCoreUI/Molecules/PrimaryButtonView.m diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index b406d4f2..e16b61aa 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -32,7 +32,6 @@ D29770F321F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770EF21F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770F421F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770F021F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770F521F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770F121F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m */; }; - D29770F921F7C73800B2F0D0 /* PrimaryButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770F721F7C73800B2F0D0 /* PrimaryButtonView.m */; }; D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770FA21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m */; }; D29770FD21F7C77400B2F0D0 /* MVMCoreUITextFieldView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770FB21F7C77400B2F0D0 /* MVMCoreUITextFieldView.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF0D121E404D4003B2FB9 /* MVMCoreUI.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF0CF21E404D4003B2FB9 /* MVMCoreUI.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -187,8 +186,6 @@ D29770EF21F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopLabelsAndBottomButtonsTableViewController.h; sourceTree = ""; }; D29770F021F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopLabelsAndBottomButtonsViewController.h; sourceTree = ""; }; D29770F121F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopLabelsAndBottomButtonsViewController.m; sourceTree = ""; }; - D29770F621F7C73800B2F0D0 /* PrimaryButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrimaryButtonView.h; sourceTree = ""; }; - D29770F721F7C73800B2F0D0 /* PrimaryButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrimaryButtonView.m; sourceTree = ""; }; D29770FA21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUITextFieldView.m; sourceTree = ""; }; D29770FB21F7C77400B2F0D0 /* MVMCoreUITextFieldView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUITextFieldView.h; sourceTree = ""; }; D29DF0CC21E404D4003B2FB9 /* MVMCoreUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MVMCoreUI.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -422,8 +419,6 @@ D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D282AACA2243C61700C46919 /* ButtonView.swift */, D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */, - D29770F621F7C73800B2F0D0 /* PrimaryButtonView.h */, - D29770F721F7C73800B2F0D0 /* PrimaryButtonView.m */, D2A514662213885800345BFB /* StandardHeaderView.swift */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, D2A5145E2211DDC100345BFB /* MoleculeStackView.swift */, @@ -859,7 +854,6 @@ D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */, D29DF11721E6805F003B2FB9 /* UIColor+MFConvenience.m in Sources */, D29DF25321E6A177003B2FB9 /* MFDigitTextField.m in Sources */, - D29770F921F7C73800B2F0D0 /* PrimaryButtonView.m in Sources */, D29DF12F21E6851E003B2FB9 /* MVMCoreUITopAlertMainView.m in Sources */, D29DF17C21E69E1F003B2FB9 /* MFTextButton.m in Sources */, D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */, diff --git a/MVMCoreUI/Molecules/PrimaryButtonView.h b/MVMCoreUI/Molecules/PrimaryButtonView.h deleted file mode 100644 index dbfd0c20..00000000 --- a/MVMCoreUI/Molecules/PrimaryButtonView.h +++ /dev/null @@ -1,53 +0,0 @@ -// -// PrimaryButtonView.h -// myverizon -// -// Created by Scott Pfeil on 12/11/15. -// Copyright © 2015 Verizon Wireless. All rights reserved. -// - -#import -#import -#import - -@interface PrimaryButtonView : ViewConstrainingView - -// Set when there is one button or it is the right button when there are two. -@property (nullable, weak, nonatomic) PrimaryButton *primaryButton; - -// The left button when there are two buttons. -@property (nullable, weak, nonatomic) PrimaryButton *secondaryButton; - -// Inits with a single button. -- (nonnull instancetype)initButtonSmall:(BOOL)small enabled:(BOOL)enabled; - -// Inits with two buttons. -- (nonnull instancetype)initWithTwoButtons; - -// Legacy: Sets up with whatever is in the passed in button map. (could be 0, 1, or 2 buttons) -- (nonnull instancetype)initButtonSmall:(BOOL)small buttonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate; -- (nonnull instancetype)initWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate; -- (void)setupWithButtonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate; -- (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate; - -// Sets up with two buttons. -- (void)setupWithTwoButtons; - -// For subclassing, just returns the button. -- (nonnull id)createButton; - -// Change the alignment of the button -- (void)alignLeft; -- (void)alignCenter; -- (void)alignRight; -- (void)alignFill;//default behavior - -// Show/hide left and right primary buttons. This does not impact the vertical space of the view. -- (void)hidePrimaryLeftButton; -- (void)hidePrimaryRightButton; -- (void)showBothPrimaryButtons; -- (void)hideBothPrimaryButtons; - -- (void)removeSubviews; - -@end diff --git a/MVMCoreUI/Molecules/PrimaryButtonView.m b/MVMCoreUI/Molecules/PrimaryButtonView.m deleted file mode 100644 index a479efab..00000000 --- a/MVMCoreUI/Molecules/PrimaryButtonView.m +++ /dev/null @@ -1,350 +0,0 @@ -// -// PrimaryButtonView.m -// myverizon -// -// Created by Scott Pfeil on 12/11/15. -// Copyright © 2015 Verizon Wireless. All rights reserved. -// - -#import "PrimaryButtonView.h" -#import -#import -#import -#import "MVMCoreUICommonViewsUtility.h" -#import "MVMCoreUIConstants.h" -#import "UIColor+MFConvenience.h" - -@interface PrimaryButtonView () - -@property (weak, nonatomic) UIView *twoButtonView; -@property (weak, nonatomic) NSLayoutConstraint *alignCenterPin; -@property (weak, nonatomic) NSLayoutConstraint *alignCenterLeftPin; -@property (weak, nonatomic) NSLayoutConstraint *alignCenterRightPin; -@property (weak, nonatomic) NSLayoutConstraint *height; - -@property (nonatomic, strong) NSArray *horizontalConstraints; - -@end - -@implementation PrimaryButtonView - -- (void)updateView:(CGFloat)size { - [super updateView:size]; - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - [self.primaryButton updateView:size]; - [self.secondaryButton updateView:size]; - }]; -} - -- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { - [super setWithJSON:json delegate:delegate additionalData:additionalData]; - NSString *backgroundColorString = [json string:@"backgroundColor"]; - if (backgroundColorString) { - self.backgroundColor = [UIColor mfGetColorForHex:backgroundColorString]; - } - NSDictionary *primaryButtonMap = [json dict:@"primaryButton"]; - NSDictionary *secondaryButtonMap = [json dict:@"secondaryButton"]; - [self setupUIWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap]; - [self.primaryButton setAsStandardCustom]; - [self.secondaryButton setAsSecondaryCustom]; - [self.primaryButton setWithJSON:primaryButtonMap delegate:delegate additionalData:additionalData]; - [self.secondaryButton setWithJSON:secondaryButtonMap delegate:delegate additionalData:additionalData]; -} - -#pragma mark - Inits - -- (instancetype)init { - if (self = [super init]) { - self.backgroundColor = [UIColor clearColor]; - self.translatesAutoresizingMaskIntoConstraints = NO; - [self setupWithSingleButton]; - } - return self; -} - -- (instancetype)initWithCoder:(NSCoder *)aDecoder { - if (self = [super initWithCoder:aDecoder]) { - self.backgroundColor = [UIColor clearColor]; - self.translatesAutoresizingMaskIntoConstraints = NO; - [self setupWithSingleButton]; - } - return self; -} - -- (instancetype)initWithFrame:(CGRect)frame { - if (self = [super initWithFrame:frame]) { - self.backgroundColor = [UIColor clearColor]; - self.translatesAutoresizingMaskIntoConstraints = NO; - [self setupWithSingleButton]; - } - return self; -} - -- (nonnull instancetype)initButtonSmall:(BOOL)small enabled:(BOOL)enabled { - if (self = [self init]) { - [self.primaryButton setAsSmallButton:small]; - [self.primaryButton setEnabled:enabled]; - } - return self; -} - -- (nonnull instancetype)initWithTwoButtons { - if (self = [self init]) { - [self setupWithTwoButtons]; - } - return self; -} - -#pragma mark - Legacy Setup - -- (nonnull instancetype)initButtonSmall:(BOOL)small buttonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate { - if (self = [self init]) { - [self setupWithButtonMap:buttonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - [self.primaryButton setAsSmallButton:small]; - [self.secondaryButton setAsSmallButton:small]; - } - return self; -} - -- (nonnull instancetype)initWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate { - if (self = [self init]) { - [self setupWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - } - return self; -} - -- (void)setupWithButtonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate { - NSDictionary *secondaryButtonMap = [buttonMap dict:KeySecondaryButton]; - NSDictionary *primaryButtonMap = [buttonMap dict:KeyPrimaryButton]; - [self setupWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; -} - -- (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate { - [self setupUIWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap]; - if (self.primaryButton && self.secondaryButton) { - [self.primaryButton setWithActionMap:primaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - [self.secondaryButton setWithActionMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - } else if (self.primaryButton) { - [self.primaryButton setWithActionMap:primaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - self.primaryButton.bordered = NO; - } else { - [self.primaryButton setWithActionMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - self.primaryButton.bordered = YES; - } -} - -#pragma mark - Setup - -- (void)setupUIWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap { - if (primaryButtonMap && secondaryButtonMap) { - self.height.active = NO; - - // Setup with two buttons - if (!self.primaryButton || !self.secondaryButton) { - [self removeSubviews]; - self.twoButtonView = nil; - [self setupWithTwoButtons]; - } - } else if (primaryButtonMap || secondaryButtonMap) { - self.height.active = NO; - - // Setup with one button. - if (!self.primaryButton || self.secondaryButton) { - [self removeSubviews]; - self.primaryButton = nil; - self.secondaryButton = nil; - [self setupWithSingleButton]; - } - } else { - [self removeSubviews]; - if (!self.height) { - NSLayoutConstraint *height = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]; - height.active = YES; - self.height = height; - } - } -} - -- (id)createButton { - return [PrimaryButton primaryButton:NO]; -} - -- (void)setupWithTwoButtons { - if (self.primaryButton) { - [self.primaryButton removeFromSuperview]; - self.primaryButton = nil; - } - - if (!self.twoButtonView) { - self.backgroundColor = [UIColor clearColor]; - self.translatesAutoresizingMaskIntoConstraints = NO; - - UIView *buttonView = [MVMCoreUICommonViewsUtility commonView]; - - PrimaryButton *leftButton = [PrimaryButton primaryButton]; - leftButton.bordered = YES; - leftButton.translatesAutoresizingMaskIntoConstraints = NO; - [buttonView addSubview:leftButton]; - self.secondaryButton = leftButton; - - PrimaryButton *rightButton = [PrimaryButton primaryButton]; - rightButton.translatesAutoresizingMaskIntoConstraints = NO; - [buttonView addSubview:rightButton]; - self.primaryButton = rightButton; - - [rightButton.widthAnchor constraintEqualToAnchor:leftButton.widthAnchor multiplier:1].active = YES; - - [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[leftButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(leftButton)]]; - [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[rightButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(rightButton)]]; - self.horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[leftButton]-10-[rightButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(leftButton,rightButton)]; - [NSLayoutConstraint activateConstraints:self.horizontalConstraints]; - [self addSubview:buttonView]; - - [self setupAlignmentsWithView:buttonView]; - - self.twoButtonView = buttonView; - - [self alignCenter]; - } -} - -- (void)setupWithSingleButton { - - if (!self.primaryButton) { - self.backgroundColor = [UIColor clearColor]; - self.translatesAutoresizingMaskIntoConstraints = NO; - - PrimaryButton *button = [self createButton]; - button.translatesAutoresizingMaskIntoConstraints = NO; - [self addSubview:button]; - self.primaryButton = button; - - [self setupAlignmentsWithView:button]; - - [self alignCenter]; - } -} - -- (void)setupAlignmentsWithView:(UIView *)view { - // Align left and right constants. - NSLayoutConstraint *leftPin = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]; - self.leftPin = leftPin; - leftPin.active = YES; - - NSLayoutConstraint *topPin = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]; - self.topPin = topPin; - topPin.active = YES; - - NSLayoutConstraint *bottomPin = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]; - self.bottomPin = bottomPin; - bottomPin.active = YES; - - NSLayoutConstraint *rightPin = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]; - self.rightPin = rightPin; - rightPin.active = YES; - - // Center alignments - NSLayoutConstraint *alignCenter = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]; - self.alignCenterPin = alignCenter; - alignCenter.active = YES; - - NSLayoutConstraint *centerLeftPin = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]; - self.alignCenterLeftPin = centerLeftPin; - centerLeftPin.active = YES; - - NSLayoutConstraint *centerRightPin = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]; - self.alignCenterRightPin = centerRightPin; - centerRightPin.active = YES; -} - -#pragma mark - Configuring - -- (void)alignLeft { - self.alignCenterPin.active = NO; - self.alignCenterLeftPin.active = NO; - self.alignCenterRightPin.active = YES; - self.leftPin.active = YES; - self.rightPin.active = NO; -} - -- (void)alignCenter { - self.alignCenterPin.active = YES; - self.alignCenterLeftPin.active = YES; - self.alignCenterRightPin.active = YES; - self.leftPin.active = NO; - self.rightPin.active = NO; -} - -- (void)alignFill { - self.alignCenterPin.active = NO; - self.alignCenterLeftPin.active = NO; - self.alignCenterRightPin.active = NO; - self.leftPin.active = YES; - self.rightPin.active = YES; -} - -- (void)alignRight { - self.alignCenterPin.active = NO; - self.alignCenterLeftPin.active = YES; - self.alignCenterRightPin.active = NO; - self.leftPin.active = NO; - self.rightPin.active = YES; -} - -- (void)setLeftPinConstant:(CGFloat)constant { - [super setLeftPinConstant:constant]; - self.alignCenterLeftPin.constant = constant; -} - -- (void)setRightPinConstant:(CGFloat)constant { - [super setRightPinConstant:constant]; - self.alignCenterRightPin.constant = constant; -} - -- (void)resetConstraints { - [super resetConstraints]; - self.primaryButton.enabled = NO; -} - -- (void)hidePrimaryLeftButton { - if (!self.secondaryButton.hidden) { - self.secondaryButton.hidden = YES; - PrimaryButton *rightButton = self.primaryButton; - [NSLayoutConstraint deactivateConstraints:self.horizontalConstraints]; - self.horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[rightButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(rightButton)]; - [NSLayoutConstraint activateConstraints:self.horizontalConstraints]; - } -} - -- (void)hidePrimaryRightButton { - if (!self.primaryButton.hidden) { - self.primaryButton.hidden = YES; - PrimaryButton *leftButton = self.secondaryButton; - [NSLayoutConstraint deactivateConstraints:self.horizontalConstraints]; - self.horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[leftButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(leftButton)]; - [NSLayoutConstraint activateConstraints:self.horizontalConstraints]; - } -} - -- (void)showBothPrimaryButtons { - self.primaryButton.hidden = NO; - self.secondaryButton.hidden = NO; - PrimaryButton *rightButton = self.primaryButton; - PrimaryButton *leftButton = self.secondaryButton; - [NSLayoutConstraint deactivateConstraints:self.horizontalConstraints]; - self.horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[leftButton]-10-[rightButton]-0-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(leftButton,rightButton)]; - [NSLayoutConstraint activateConstraints:self.horizontalConstraints]; -} - -- (void)hideBothPrimaryButtons { - self.primaryButton.hidden = YES; - self.secondaryButton.hidden = YES; -} - -- (void)removeSubviews { - for (UIView *view in self.subviews) { - [view removeFromSuperview]; - } -} - -@end From b25b869c4d10257df5e405038bc4f311ff902b32 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Mar 2019 12:59:07 -0400 Subject: [PATCH 3/7] fix to size check --- MVMCoreUI/Molecules/StandardFooterView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Molecules/StandardFooterView.swift b/MVMCoreUI/Molecules/StandardFooterView.swift index 2cf85302..99880b9b 100644 --- a/MVMCoreUI/Molecules/StandardFooterView.swift +++ b/MVMCoreUI/Molecules/StandardFooterView.swift @@ -71,7 +71,7 @@ public class StandardFooterView: ViewConstrainingView { if !(twoButtonView.heightConstraint?.isActive ?? false) && textButton.title(for: UIControl.State.normal)?.count ?? 0 > 0 { spaceBetweenButtons?.constant = PaddingTwo show() - } else if twoButtonView.subviews.count > 0 || textButton.title(for: UIControl.State.normal)?.count ?? 0 > 0 { + } else if !(twoButtonView.heightConstraint?.isActive ?? false) || textButton.title(for: UIControl.State.normal)?.count ?? 0 > 0 { spaceBetweenButtons?.constant = 0 show() } else { From f63b157c1650d86dc36ea41c5060611adb93cb15 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Mar 2019 16:51:51 -0400 Subject: [PATCH 4/7] Fixes to make two button more compatible with legacy --- MVMCoreUI/Molecules/TwoButtonView.swift | 146 ++++++++++++++---------- 1 file changed, 85 insertions(+), 61 deletions(-) diff --git a/MVMCoreUI/Molecules/TwoButtonView.swift b/MVMCoreUI/Molecules/TwoButtonView.swift index 4ae821d2..9e6cf4ee 100644 --- a/MVMCoreUI/Molecules/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/TwoButtonView.swift @@ -10,7 +10,7 @@ import UIKit @objcMembers open class TwoButtonView: ButtonView { open var secondaryButton: PrimaryButton? - open var viewForButtons = MVMCoreUICommonViewsUtility.commonView() + open var viewForButtons: UIView? public var heightConstraint: NSLayoutConstraint? public override init() { @@ -41,7 +41,7 @@ import UIKit } let primaryButtonMap = json?.optionalDictionaryForKey("primaryButton") let secondaryButtonMap = json?.optionalDictionaryForKey("secondaryButton") - setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap) + setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap, legacy: false) primaryButton?.setAsStandardCustom() secondaryButton?.setAsSecondaryCustom() primaryButton?.setWithJSON(primaryButtonMap, delegate: delegate, additionalData: additionalData) @@ -50,30 +50,33 @@ import UIKit // MARK: - Constraining override func setupButton() { - guard viewForButtons.superview != self else { - return - } - addSubview(viewForButtons) - setupConstraints(forView: viewForButtons) setupWithTwoButtons() } - open func setupWithTwoButtons() { - guard viewForButtons != primaryButton?.superview && viewForButtons != secondaryButton?.superview else { - return - } - if let primaryButton = primaryButton { - primaryButton.removeFromSuperview() - } else { + func createPrimaryButton() { + if primaryButton == nil { primaryButton = PrimaryButton.button() } - if let secondaryButton = secondaryButton { - secondaryButton.removeFromSuperview() - } else { + } + + func createSecondaryButton() { + if secondaryButton == nil { secondaryButton = PrimaryButton.button() secondaryButton?.bordered = true } - guard let primaryButton = primaryButton, let secondaryButton = secondaryButton else { + } + + 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) @@ -86,50 +89,54 @@ import UIKit NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[leftButton]-10-[rightButton]-0-|", options: NSLayoutConstraint.FormatOptions.alignAllCenterY, metrics: nil, views: ["leftButton": secondaryButton, "rightButton": primaryButton])) } + func setupWithTwoButtons() { + guard self.viewForButtons == nil else { + return + } + let viewForButtons = MVMCoreUICommonViewsUtility.commonView() + addSubview(viewForButtons) + self.viewForButtons = viewForButtons + + setupConstraints(forView: viewForButtons) + alignCenter() + + createPrimaryButton() + createSecondaryButton() + setupConstraintsForViewWithButtons() + } + open func setupWithPrimaryButton() { - primaryButton?.removeFromSuperview() - secondaryButton?.removeFromSuperview() - secondaryButton = nil - if primaryButton == nil { - primaryButton = PrimaryButton.button() + guard self.primaryButton == nil else { + return } - setupWithOneButton(primaryButton!) - } - - open func setupWithSecondaryButton() { - primaryButton?.removeFromSuperview() - secondaryButton?.removeFromSuperview() - primaryButton = nil - if secondaryButton == nil { - secondaryButton = PrimaryButton.button() - secondaryButton?.bordered = true + createPrimaryButton() + if let primaryButton = primaryButton { + addSubview(primaryButton) + setupConstraints(forView: primaryButton) + alignCenter() } - setupWithOneButton(secondaryButton!) } - func setupWithOneButton(_ button: PrimaryButton) { - viewForButtons.addSubview(button) - button.topAnchor.constraint(equalTo: viewForButtons.topAnchor).isActive = true - button.leftAnchor.constraint(equalTo: viewForButtons.leftAnchor).isActive = true - viewForButtons.rightAnchor.constraint(equalTo: button.rightAnchor).isActive = true - viewForButtons.bottomAnchor.constraint(equalTo: button.bottomAnchor).isActive = true - } - - open func setupUI(withPrimaryButtonMap primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?) { + // 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 { heightConstraint?.isActive = false - setupWithTwoButtons() - } else if primaryButtonMap != nil || secondaryButtonMap != nil { + 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 heightConstraint?.isActive = false - setupWithPrimaryButton() + if primaryButton == nil || secondaryButton != nil { + removeButtons() + setupWithPrimaryButton() + } } else { - primaryButton?.removeFromSuperview() - secondaryButton?.removeFromSuperview() - primaryButton = nil - secondaryButton = nil + removeButtons() if heightConstraint == nil { - self.heightConstraint = heightAnchor.constraint(equalToConstant: 0) - self.heightConstraint?.isActive = true + heightConstraint = heightAnchor.constraint(equalToConstant: 0) + heightConstraint?.isActive = true } } } @@ -142,19 +149,22 @@ import UIKit } open func setup(primaryButtonMap: [AnyHashable: Any]?, secondaryButtonMap: [AnyHashable: Any]?, actionDelegate: NSObjectProtocol?, additionalData: [AnyHashable: Any]?, buttonDelegate: Any?) { - setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap) + setupUI(withPrimaryButtonMap: primaryButtonMap, secondaryButtonMap: secondaryButtonMap, legacy: true) 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) - } else { + primaryButton?.bordered = false + } else if secondaryButtonMap != nil { primaryButton?.setWithActionMap(secondaryButtonMap, actionDelegate: actionDelegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol, additionalData: additionalData, buttonDelegate: buttonDelegate as? ButtonDelegateProtocol) + primaryButton?.bordered = true } } public convenience init(buttonSmall small: Bool, enabled: Bool) { self.init() + removeButtons() setupWithPrimaryButton() primaryButton?.setAsSmall(small) primaryButton?.isEnabled = enabled @@ -173,23 +183,37 @@ import UIKit } public func hidePrimaryLeftButton() { - if let secondaryButton = secondaryButton, !secondaryButton.isHidden { - secondaryButton.isHidden = true - setupWithPrimaryButton() + 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 hidePrimaryRightButton() { - if let primaryButton = primaryButton, !primaryButton.isHidden { - primaryButton.isHidden = true - setupWithSecondaryButton() + 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 showBothPrimaryButtons() { primaryButton?.isHidden = false secondaryButton?.isHidden = false - setupWithTwoButtons() + if let primaryButton = primaryButton, let secondaryButton = secondaryButton { + primaryButton.removeFromSuperview() + secondaryButton.removeFromSuperview() + setupConstraintsForViewWithButtons() + } } public func hideBothPrimaryButtons() { From aab0fbc083d9d2f9000758502314933a9f680668 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Mar 2019 17:07:02 -0400 Subject: [PATCH 5/7] non null --- MVMCoreUI/Atoms/Buttons/PrimaryButton.h | 22 +++++++++++----------- MVMCoreUI/Atoms/Buttons/PrimaryButton.m | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.h b/MVMCoreUI/Atoms/Buttons/PrimaryButton.h index fb93c33a..a1c7d393 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.h +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.h @@ -47,20 +47,20 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0; @property (nonatomic) BOOL skipHighlighted; // The main creation functions, changed to black button for 2.0 for default -+ (nullable instancetype)primaryButton:(BOOL)enabled; -+ (nullable instancetype)primarySmallButton:(BOOL)enabled; -+ (nullable instancetype)primaryTinyButton:(BOOL)enabled; ++ (nonnull instancetype)primaryButton:(BOOL)enabled; ++ (nonnull instancetype)primarySmallButton:(BOOL)enabled; ++ (nonnull instancetype)primaryTinyButton:(BOOL)enabled; + (nonnull instancetype)primaryButton NS_SWIFT_NAME(button()); -+ (nullable instancetype)primarySmallButton; -+ (nullable instancetype)primaryWhiteButton:(BOOL)small; ++ (nonnull instancetype)primarySmallButton; ++ (nonnull instancetype)primaryWhiteButton:(BOOL)small; // legacy color functions. -+ (nullable instancetype)primaryRedButton; -+ (nullable instancetype)primaryGrayButtonSmall:(BOOL)small; -+ (nullable instancetype)primaryRedSmallButton; -+ (nullable instancetype)primaryGraySmallRedButton; -+ (nullable instancetype)primaryWhiteSmallRedButton; ++ (nonnull instancetype)primaryRedButton; ++ (nonnull instancetype)primaryGrayButtonSmall:(BOOL)small; ++ (nonnull instancetype)primaryRedSmallButton; ++ (nonnull instancetype)primaryGraySmallRedButton; ++ (nonnull instancetype)primaryWhiteSmallRedButton; @@ -68,7 +68,7 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0; #pragma mark - For Subclassing // Creates and pins the height of the button, nothing more. -+ (nullable instancetype)getButton; ++ (nonnull instancetype)getButton; // Pins the height initially. - (void)pinHeight; diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m index a13a693c..b87af3ac 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m @@ -555,7 +555,7 @@ return button; } -+ (nullable instancetype)primarySmallButton { ++ (nonnull instancetype)primarySmallButton { PrimaryButton *button = [self getButton]; button.primaryButtonType = PrimaryButtonTypeBlack; [button setAsBlack]; @@ -563,7 +563,7 @@ return button; } -+ (nullable instancetype)primaryTinyButton:(BOOL)enabled { ++ (nonnull instancetype)primaryTinyButton:(BOOL)enabled { PrimaryButton *button = [self getButton]; button.primaryButtonType = PrimaryButtonTypeBlack; [button setAsBlack]; @@ -612,7 +612,7 @@ return button; } -+ (nullable instancetype)primaryWhiteButton:(BOOL)small { ++ (nonnull instancetype)primaryWhiteButton:(BOOL)small { PrimaryButton *button = [self getButton]; button.primaryButtonType = PrimaryButtonTypeWhite; [button setAsAllWhite]; From 623b1590ee453e2acfbfd30859835caca36e7b57 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Mar 2019 17:11:31 -0400 Subject: [PATCH 6/7] delete unused --- MVMCoreUI/Molecules/ButtonView.swift | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/MVMCoreUI/Molecules/ButtonView.swift b/MVMCoreUI/Molecules/ButtonView.swift index 04be7ba5..f48044dd 100644 --- a/MVMCoreUI/Molecules/ButtonView.swift +++ b/MVMCoreUI/Molecules/ButtonView.swift @@ -101,15 +101,7 @@ import UIKit leftPin?.isActive = false rightPin?.isActive = false } - - open func alignFill() { - alignCenterPin?.isActive = false - alignCenterLeftPin?.isActive = false - alignCenterRightPin?.isActive = false - leftPin?.isActive = true - rightPin?.isActive = false - } - + open func alignRight() { alignCenterPin?.isActive = false alignCenterLeftPin?.isActive = true From bc5e4b311bdaf352f8a7ba664980544511a4ab7a Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Mar 2019 17:32:24 -0400 Subject: [PATCH 7/7] un nonnulla --- MVMCoreUI/Atoms/Buttons/PrimaryButton.h | 22 +++++++++++----------- MVMCoreUI/Atoms/Buttons/PrimaryButton.m | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.h b/MVMCoreUI/Atoms/Buttons/PrimaryButton.h index a1c7d393..fb93c33a 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.h +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.h @@ -47,20 +47,20 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0; @property (nonatomic) BOOL skipHighlighted; // The main creation functions, changed to black button for 2.0 for default -+ (nonnull instancetype)primaryButton:(BOOL)enabled; -+ (nonnull instancetype)primarySmallButton:(BOOL)enabled; -+ (nonnull instancetype)primaryTinyButton:(BOOL)enabled; ++ (nullable instancetype)primaryButton:(BOOL)enabled; ++ (nullable instancetype)primarySmallButton:(BOOL)enabled; ++ (nullable instancetype)primaryTinyButton:(BOOL)enabled; + (nonnull instancetype)primaryButton NS_SWIFT_NAME(button()); -+ (nonnull instancetype)primarySmallButton; -+ (nonnull instancetype)primaryWhiteButton:(BOOL)small; ++ (nullable instancetype)primarySmallButton; ++ (nullable instancetype)primaryWhiteButton:(BOOL)small; // legacy color functions. -+ (nonnull instancetype)primaryRedButton; -+ (nonnull instancetype)primaryGrayButtonSmall:(BOOL)small; -+ (nonnull instancetype)primaryRedSmallButton; -+ (nonnull instancetype)primaryGraySmallRedButton; -+ (nonnull instancetype)primaryWhiteSmallRedButton; ++ (nullable instancetype)primaryRedButton; ++ (nullable instancetype)primaryGrayButtonSmall:(BOOL)small; ++ (nullable instancetype)primaryRedSmallButton; ++ (nullable instancetype)primaryGraySmallRedButton; ++ (nullable instancetype)primaryWhiteSmallRedButton; @@ -68,7 +68,7 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0; #pragma mark - For Subclassing // Creates and pins the height of the button, nothing more. -+ (nonnull instancetype)getButton; ++ (nullable instancetype)getButton; // Pins the height initially. - (void)pinHeight; diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m index b87af3ac..a13a693c 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m @@ -555,7 +555,7 @@ return button; } -+ (nonnull instancetype)primarySmallButton { ++ (nullable instancetype)primarySmallButton { PrimaryButton *button = [self getButton]; button.primaryButtonType = PrimaryButtonTypeBlack; [button setAsBlack]; @@ -563,7 +563,7 @@ return button; } -+ (nonnull instancetype)primaryTinyButton:(BOOL)enabled { ++ (nullable instancetype)primaryTinyButton:(BOOL)enabled { PrimaryButton *button = [self getButton]; button.primaryButtonType = PrimaryButtonTypeBlack; [button setAsBlack]; @@ -612,7 +612,7 @@ return button; } -+ (nonnull instancetype)primaryWhiteButton:(BOOL)small { ++ (nullable instancetype)primaryWhiteButton:(BOOL)small { PrimaryButton *button = [self getButton]; button.primaryButtonType = PrimaryButtonTypeWhite; [button setAsAllWhite];