From 39c96849c813d7f145298dd7efe339cc67620d30 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Wed, 18 Dec 2019 17:58:53 -0500 Subject: [PATCH 01/13] Translates MFCustomButton to Button --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++ MVMCoreUI/Atoms/Buttons/Button.swift | 57 +++++++++++++++++++++++ MVMCoreUI/Atoms/Buttons/CaretButton.swift | 10 ++-- 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 MVMCoreUI/Atoms/Buttons/Button.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 900edec2..cbb61895 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */; }; 9455B19C234F8A0400A574DB /* MVMAnimationFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */; }; 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; }; + C003506123AA94CD00B6AC29 /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = C003506023AA94CD00B6AC29 /* Button.swift */; }; D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */; }; D213347723843825008E41B3 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = D213347623843825008E41B3 /* Line.swift */; }; D224798A2314445E003FCCF9 /* LabelSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22479892314445E003FCCF9 /* LabelSwitch.swift */; }; @@ -230,6 +231,7 @@ 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphViewAnimationHandler.swift; sourceTree = ""; }; 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MVMAnimationFramework.framework; path = ../SharedFrameworks/MVMAnimationFramework.framework; sourceTree = ""; }; 948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = ""; }; + C003506023AA94CD00B6AC29 /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = ""; }; D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonView.swift; sourceTree = ""; }; D213347623843825008E41B3 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = ""; }; D22479892314445E003FCCF9 /* LabelSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelSwitch.swift; sourceTree = ""; }; @@ -733,6 +735,7 @@ DBC4391A224421A0001AB423 /* CaretButton.swift */, D29DF25821E6A22D003B2FB9 /* MFButtonProtocol.h */, D29DF16B21E69E1F003B2FB9 /* ButtonDelegateProtocol.h */, + C003506023AA94CD00B6AC29 /* Button.swift */, D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */, D29DF17021E69E1F003B2FB9 /* MFCustomButton.m */, D29DF16C21E69E1F003B2FB9 /* PrimaryButton.h */, @@ -1158,6 +1161,7 @@ D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */, D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, + C003506123AA94CD00B6AC29 /* Button.swift in Sources */, D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift new file mode 100644 index 00000000..d87ee030 --- /dev/null +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -0,0 +1,57 @@ +// +// Button.swift +// MVMCoreUI +// +// Created by Robinson, Blake on 12/18/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +@objcMembers open class Button: UIButton, MFButtonProtocol { + + public var actionMap: [AnyHashable: Any]? + public weak var buttonDelegate: ButtonDelegateProtocol? + public var heightConstraint: NSLayoutConstraint? + + //Does buttonTap block need to be rewritten in swift? + private var buttonTapBlock: ButtonTapBlock? + + public func addBlock(_ buttonTapBlock: @escaping ButtonTapBlock, event: Event) { + self.buttonTapBlock = buttonTapBlock + addTarget(self, action: #selector(callBlock(_:)), for: event) + } + + func callBlock(_ sender: Button) { + guard let buttonTapBlock = buttonTapBlock else { return } + buttonTapBlock(self) + } + + public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + self.actionMap = actionMap + self.titleLabel?.numberOfLines = 0 + self.titleLabel?.lineBreakMode = .byWordWrapping + setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) + + if let actionMap = self.actionMap, + let disableButtonAsAny = actionMap[KeyDisableButton], + let isDisabled = disableButtonAsAny as? Bool { + + isEnabled = !isDisabled + } + + if let mVMCoreUIDelegateObject = delegateObject as? MVMCoreUIDelegateObject { + self.buttonDelegate = mVMCoreUIDelegateObject.buttonDelegate + } + + self.addBlock({ [weak self] (sender) in + guard let self = self else { return } + var performAction = true + if let shouldPerformAction = self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) { + performAction = shouldPerformAction + } + if performAction { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + + }, event: .touchUpInside) + } +} diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index b01d2758..f1b391d8 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -8,7 +8,7 @@ // -open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol { +open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol { //------------------------------------------------------ // MARK: - Constants @@ -46,10 +46,10 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI super.layoutSubviews() } - public func setEnabled(_ enabled: Bool) { - super.isEnabled = enabled - - changeCaretColor() + override public var isEnabled: Bool { + didSet { + changeCaretColor() + } } public func updateView(_ size: CGFloat) { From 4b855a1a63c4e9df57ff86ed112e2e8e74e7b7fa Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 09:28:41 -0500 Subject: [PATCH 02/13] Removes unused property heightConstraint --- MVMCoreUI/Atoms/Buttons/Button.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index d87ee030..c6c187fe 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -10,7 +10,6 @@ public var actionMap: [AnyHashable: Any]? public weak var buttonDelegate: ButtonDelegateProtocol? - public var heightConstraint: NSLayoutConstraint? //Does buttonTap block need to be rewritten in swift? private var buttonTapBlock: ButtonTapBlock? From 109ef544796d75d039bfd8b82fe2898f6a618f4e Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 09:53:09 -0500 Subject: [PATCH 03/13] Rewrote ButtonTapBlock in swift --- MVMCoreUI/Atoms/Buttons/Button.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index c6c187fe..cd93f755 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -6,22 +6,22 @@ // Copyright © 2019 Verizon Wireless. All rights reserved. // +public typealias ButtonBlock = (Button) -> Void + @objcMembers open class Button: UIButton, MFButtonProtocol { public var actionMap: [AnyHashable: Any]? public weak var buttonDelegate: ButtonDelegateProtocol? + private var buttonBlock: ButtonBlock? - //Does buttonTap block need to be rewritten in swift? - private var buttonTapBlock: ButtonTapBlock? - - public func addBlock(_ buttonTapBlock: @escaping ButtonTapBlock, event: Event) { - self.buttonTapBlock = buttonTapBlock + public func addBlock(_ buttonBlock: @escaping ButtonBlock, event: Event) { + self.buttonBlock = buttonBlock addTarget(self, action: #selector(callBlock(_:)), for: event) } func callBlock(_ sender: Button) { - guard let buttonTapBlock = buttonTapBlock else { return } - buttonTapBlock(self) + guard let buttonBlock = buttonBlock else { return } + buttonBlock(self) } public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { From 2c5e2286b1cc9e691e051e02177790c67664e272 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 10:06:54 -0500 Subject: [PATCH 04/13] Removed line setting title because title won't be part of actionMap in the future --- MVMCoreUI/Atoms/Buttons/Button.swift | 1 - MVMCoreUI/Atoms/Buttons/CaretButton.swift | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index cd93f755..77a790fc 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -28,7 +28,6 @@ public typealias ButtonBlock = (Button) -> Void self.actionMap = actionMap self.titleLabel?.numberOfLines = 0 self.titleLabel?.lineBreakMode = .byWordWrapping - setTitle(actionMap?.stringForkey(KeyTitle), for: .normal) if let actionMap = self.actionMap, let disableButtonAsAny = actionMap[KeyDisableButton], diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index f1b391d8..86f1185e 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -119,6 +119,10 @@ open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewCons guard let dictionary = json else { return } + if let title = dictionary.optionalStringForKey(KeyTitle) { + setTitle(title, for: .normal) + } + if let backgroundColorHex = dictionary[KeyBackgroundColor] as? String { backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) } From 8f23dd391c338f3a41d2fbc9831f30451047c3f9 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 10:19:42 -0500 Subject: [PATCH 05/13] Removes disabled logic from Button because it won't be in the actionMap going forward --- MVMCoreUI/Atoms/Buttons/Button.swift | 7 ------- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index 77a790fc..c1e631a2 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -29,13 +29,6 @@ public typealias ButtonBlock = (Button) -> Void self.titleLabel?.numberOfLines = 0 self.titleLabel?.lineBreakMode = .byWordWrapping - if let actionMap = self.actionMap, - let disableButtonAsAny = actionMap[KeyDisableButton], - let isDisabled = disableButtonAsAny as? Bool { - - isEnabled = !isDisabled - } - if let mVMCoreUIDelegateObject = delegateObject as? MVMCoreUIDelegateObject { self.buttonDelegate = mVMCoreUIDelegateObject.buttonDelegate } diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 86f1185e..668505a8 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -123,6 +123,12 @@ open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewCons 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) } From 6cf4ba0594c70f238cbbba6ee5ea75e9012f2d48 Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 10:30:14 -0500 Subject: [PATCH 06/13] Improved swifty-ness of these lines --- MVMCoreUI/Atoms/Buttons/Button.swift | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index c1e631a2..263d5cb1 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -34,14 +34,11 @@ public typealias ButtonBlock = (Button) -> Void } self.addBlock({ [weak self] (sender) in - guard let self = self else { return } - var performAction = true - if let shouldPerformAction = self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) { - performAction = shouldPerformAction - } - if performAction { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - } + guard let self = self, + let performAction = self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData), + performAction else { return } + + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }, event: .touchUpInside) } From 1de7618e5cc0f668bfd46f5819919080bc829d2c Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 10:35:11 -0500 Subject: [PATCH 07/13] Changed to MVMCoreUIDelegateObject --- MVMCoreUI/Atoms/Buttons/Button.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index 263d5cb1..66bed2b3 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -24,14 +24,12 @@ public typealias ButtonBlock = (Button) -> Void buttonBlock(self) } - public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) { + public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.actionMap = actionMap self.titleLabel?.numberOfLines = 0 self.titleLabel?.lineBreakMode = .byWordWrapping - if let mVMCoreUIDelegateObject = delegateObject as? MVMCoreUIDelegateObject { - self.buttonDelegate = mVMCoreUIDelegateObject.buttonDelegate - } + buttonDelegate = delegateObject?.buttonDelegate self.addBlock({ [weak self] (sender) in guard let self = self, From 82c76c6084158d223cb7c189f7582d2f96da142d Mon Sep 17 00:00:00 2001 From: "Robinson, Blake" Date: Thu, 19 Dec 2019 10:37:57 -0500 Subject: [PATCH 08/13] Removed self where unnecessary --- MVMCoreUI/Atoms/Buttons/Button.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index 66bed2b3..2845e66a 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -26,12 +26,12 @@ public typealias ButtonBlock = (Button) -> Void public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.actionMap = actionMap - self.titleLabel?.numberOfLines = 0 - self.titleLabel?.lineBreakMode = .byWordWrapping + titleLabel?.numberOfLines = 0 + titleLabel?.lineBreakMode = .byWordWrapping buttonDelegate = delegateObject?.buttonDelegate - self.addBlock({ [weak self] (sender) in + addBlock({ [weak self] (sender) in guard let self = self, let performAction = self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData), performAction else { return } From e674fe4d94290c98e0accc15076640d53780bd92 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 8 Jan 2020 14:19:37 -0500 Subject: [PATCH 09/13] Adding protocols, comments, and mild reworks. --- MVMCoreUI/Atoms/Buttons/Button.swift | 115 +++++++++++++++++++--- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 16 +-- 2 files changed, 108 insertions(+), 23 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index 2845e66a..21a9b227 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -6,38 +6,129 @@ // Copyright © 2019 Verizon Wireless. All rights reserved. // -public typealias ButtonBlock = (Button) -> Void +public typealias ButtonBlock = (Button) -> () + @objcMembers open class Button: UIButton, MFButtonProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public var json: [AnyHashable: Any]? public var actionMap: [AnyHashable: Any]? - public weak var buttonDelegate: ButtonDelegateProtocol? + + private var initialSetupPerformed = false + private var buttonBlock: ButtonBlock? - public func addBlock(_ buttonBlock: @escaping ButtonBlock, event: Event) { + //-------------------------------------------------- + // MARK: - Delegate + //-------------------------------------------------- + + public weak var buttonDelegate: ButtonDelegateProtocol? + + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + + public override init(frame: CGRect) { + super.init(frame: .zero) + initialSetup() + } + + public convenience init() { + self.init(frame: .zero) + initialSetup() + } + + public required init?(coder: NSCoder) { + super.init(coder: coder) + fatalError("Button does not support xib.") + } + + //-------------------------------------------------- + // MARK: - Setup + //-------------------------------------------------- + + public func initialSetup() { + + if !initialSetupPerformed { + initialSetupPerformed = true + setupView() + } + } + + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + + public func addBlock( event: Event, _ buttonBlock: @escaping ButtonBlock) { self.buttonBlock = buttonBlock addTarget(self, action: #selector(callBlock(_:)), for: event) } func callBlock(_ sender: Button) { - guard let buttonBlock = buttonBlock else { return } - buttonBlock(self) + buttonBlock?(self) } public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.actionMap = actionMap + titleLabel?.numberOfLines = 0 titleLabel?.lineBreakMode = .byWordWrapping buttonDelegate = delegateObject?.buttonDelegate - addBlock({ [weak self] (sender) in - guard let self = self, - let performAction = self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData), - performAction else { return } + addBlock(event: .touchUpInside) { [weak self] sender in + guard let self = self else { return } - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - - }, event: .touchUpInside) + if self.buttonDelegate?.button?(self, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { + MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) + } + } + } +} + +// MARK: - MVMCoreUIMoleculeViewProtocol +extension Button: MVMCoreUIMoleculeViewProtocol { + + public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + self.json = json + + guard let dictionary = json else { return } + + if let backgroundColorString = dictionary[KeyBackgroundColor] as? String { + backgroundColor = UIColor.mfGet(forHex: backgroundColorString) + } + + if let title = dictionary[KeyTitle] as? String { + setTitle(title, for: .normal) + } + } + + public func reset() { + backgroundColor = .clear + } +} + + +// MARK: - MVMCoreViewProtocol +extension Button: MVMCoreViewProtocol { + + public func updateView(_ size: CGFloat) {} + + /// Will be called only once. + public func setupView() { + + translatesAutoresizingMaskIntoConstraints = false + insetsLayoutMarginsFromSafeArea = false + } +} + +// MARK: AppleGuidelinesProtocol +extension Button: AppleGuidelinesProtocol { + + override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { + return Self.acceptablyOutsideBounds(point: point, bounds: bounds) } } diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 22bc3cd5..5311df31 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -17,7 +17,6 @@ open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewCons private let CARET_VIEW_HEIGHT: Float = 10.5 private let CARET_VIEW_WIDTH: Float = 6.5 - //------------------------------------------------------ // MARK: - Properties //------------------------------------------------------ @@ -47,13 +46,10 @@ open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewCons } override public var isEnabled: Bool { - didSet { - changeCaretColor() - } + didSet { changeCaretColor() } } - public func updateView(_ size: CGFloat) { - } + public func updateView(_ size: CGFloat) { } //------------------------------------------------------ // MARK: - Functions @@ -86,7 +82,7 @@ open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewCons NSLayoutConstraint(item: caretView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: width).isActive = true NSLayoutConstraint(item: caretView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: height).isActive = true - let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4.0) + let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4) caretLabelSpacing.isActive = true caretSpacingConstraint = caretLabelSpacing @@ -123,9 +119,7 @@ open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewCons setTitle(title, for: .normal) } - if let disableButtonAsAny = dictionary[KeyDisableButton], - let isDisabled = disableButtonAsAny as? Bool { - + if let disableButtonAsAny = dictionary[KeyDisableButton], let isDisabled = disableButtonAsAny as? Bool { isEnabled = !isDisabled } @@ -147,7 +141,7 @@ open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewCons } open func horizontalAlignment() -> UIStackView.Alignment { - return UIStackView.Alignment.leading; + return .leading } public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { From 6b983d2f69e042b176f363900047cb30332d4d1b Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Jan 2020 14:11:50 -0500 Subject: [PATCH 10/13] Moved out. --- MVMCoreUI/Atoms/Buttons/Button.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/Atoms/Buttons/Button.swift index 21a9b227..1d5d743e 100644 --- a/MVMCoreUI/Atoms/Buttons/Button.swift +++ b/MVMCoreUI/Atoms/Buttons/Button.swift @@ -74,9 +74,6 @@ public typealias ButtonBlock = (Button) -> () public func setWithActionMap(_ actionMap: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.actionMap = actionMap - titleLabel?.numberOfLines = 0 - titleLabel?.lineBreakMode = .byWordWrapping - buttonDelegate = delegateObject?.buttonDelegate addBlock(event: .touchUpInside) { [weak self] sender in @@ -122,6 +119,8 @@ extension Button: MVMCoreViewProtocol { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false + titleLabel?.numberOfLines = 0 + titleLabel?.lineBreakMode = .byWordWrapping } } From 0b9f641d878a9c05bfe1b71fb759125a46134afa Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Jan 2020 15:43:10 -0500 Subject: [PATCH 11/13] reset super. --- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 5311df31..3b241f82 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -8,7 +8,7 @@ // -open class CaretButton: Button, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol { +open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol { //------------------------------------------------------ // MARK: - Constants From 9308d6d89234a3bde6f2c432dbd60b9fe98f2ba1 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Jan 2020 16:01:12 -0500 Subject: [PATCH 12/13] Move Button to Base Classes Folder. --- MVMCoreUI.xcodeproj/project.pbxproj | 2 +- MVMCoreUI/{Atoms/Buttons => BaseClasses}/Button.swift | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename MVMCoreUI/{Atoms/Buttons => BaseClasses}/Button.swift (100%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 820e034f..245bc8d4 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -748,7 +748,6 @@ DBC4391A224421A0001AB423 /* CaretButton.swift */, D29DF25821E6A22D003B2FB9 /* MFButtonProtocol.h */, D29DF16B21E69E1F003B2FB9 /* ButtonDelegateProtocol.h */, - C003506023AA94CD00B6AC29 /* Button.swift */, D29DF16A21E69E1F003B2FB9 /* MFCustomButton.h */, D29DF17021E69E1F003B2FB9 /* MFCustomButton.m */, D29DF16C21E69E1F003B2FB9 /* PrimaryButton.h */, @@ -915,6 +914,7 @@ D2B18B7D236090D500A9AEDC /* BaseClasses */ = { isa = PBXGroup; children = ( + C003506023AA94CD00B6AC29 /* Button.swift */, D2B18B7E2360913400A9AEDC /* Control.swift */, D2B18B802360945C00A9AEDC /* View.swift */, 0A5D59C323AD488600EFD9E9 /* Protocols */, diff --git a/MVMCoreUI/Atoms/Buttons/Button.swift b/MVMCoreUI/BaseClasses/Button.swift similarity index 100% rename from MVMCoreUI/Atoms/Buttons/Button.swift rename to MVMCoreUI/BaseClasses/Button.swift From ad4eddb45007f02fe29c6c330964b967e53d5ad5 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 14:43:16 -0500 Subject: [PATCH 13/13] some class is using a xib. --- MVMCoreUI/Atoms/Views/DashLine.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index edd911e0..c66d68b7 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -31,7 +31,6 @@ open class DashLine: View { required public init?(coder: NSCoder) { super.init(coder: coder) - fatalError("DashLine xib not supported") } //------------------------------------------------------