From 9e3e8cc0e54ecd5e8f939288277f456c434fd215 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Wed, 20 Mar 2019 13:06:52 -0400 Subject: [PATCH] Conversion and atomization of objc MFCaretView to Swift. Removed MFCaretView objc classes. Reflection change in import statements. Added new constants KeyIsOpaque. Provided default init for atoms cis setAsMolecule(). Removed extraneous @objc at class declaration line of DashLine. --- MVMCoreUI.xcodeproj/project.pbxproj | 12 +- MVMCoreUI/Atoms/Buttons/MFCaretButton.m | 8 +- MVMCoreUI/Atoms/Views/CaretView.swift | 133 ++++++++++++++++++ MVMCoreUI/Atoms/Views/DashLine.swift | 9 +- MVMCoreUI/Atoms/Views/MFCaretView.h | 15 -- MVMCoreUI/Atoms/Views/MFCaretView.m | 93 ------------ MVMCoreUI/MVMCoreUI.h | 1 - .../MVMCoreUIMoleculeMappingObject.m | 3 +- MVMCoreUI/Utility/MVMCoreUIConstants.h | 1 + MVMCoreUI/Utility/MVMCoreUIConstants.m | 1 + 10 files changed, 153 insertions(+), 123 deletions(-) create mode 100644 MVMCoreUI/Atoms/Views/CaretView.swift delete mode 100644 MVMCoreUI/Atoms/Views/MFCaretView.h delete mode 100644 MVMCoreUI/Atoms/Views/MFCaretView.m diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index de3962aa..fc1d4914 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -109,8 +109,6 @@ D29DF29E21E7AE3B003B2FB9 /* MFStyler.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF13921E68637003B2FB9 /* MFStyler.m */; }; D29DF2A121E7AF4E003B2FB9 /* MVMCoreUIUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF29F21E7AF4E003B2FB9 /* MVMCoreUIUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF2A021E7AF4E003B2FB9 /* MVMCoreUIUtility.m */; }; - D29DF2A521E7B2A0003B2FB9 /* MFCaretView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF2A321E7B29F003B2FB9 /* MFCaretView.m */; }; - D29DF2A621E7B2A0003B2FB9 /* MFCaretView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF2A421E7B2A0003B2FB9 /* MFCaretView.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF2A921E7B2F9003B2FB9 /* MVMCoreUIConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF2A721E7B2F9003B2FB9 /* MVMCoreUIConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF2AA21E7B2F9003B2FB9 /* MVMCoreUIConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF2A821E7B2F9003B2FB9 /* MVMCoreUIConstants.m */; }; D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF2AB21E7B3A4003B2FB9 /* MFTextView.m */; }; @@ -158,6 +156,7 @@ D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */; }; D2C5001D21F8EE67001DA659 /* LabelWithInternalButton.h in Headers */ = {isa = PBXBuildFile; fileRef = D2C5001B21F8EE66001DA659 /* LabelWithInternalButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; D2C5001E21F8EE67001DA659 /* LabelWithInternalButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C5001C21F8EE66001DA659 /* LabelWithInternalButton.m */; }; + DBC43900224276B7001AB423 /* CaretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC438FF224276B7001AB423 /* CaretView.swift */; }; DBD1E75522412BDB00C6AFF4 /* DashLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD1E75422412BDB00C6AFF4 /* DashLine.swift */; }; /* End PBXBuildFile section */ @@ -272,8 +271,6 @@ D29DF29421E7ADB8003B2FB9 /* MFProgrammaticTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFProgrammaticTableViewController.m; sourceTree = ""; }; D29DF29F21E7AF4E003B2FB9 /* MVMCoreUIUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIUtility.h; sourceTree = ""; }; D29DF2A021E7AF4E003B2FB9 /* MVMCoreUIUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIUtility.m; sourceTree = ""; }; - D29DF2A321E7B29F003B2FB9 /* MFCaretView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFCaretView.m; sourceTree = ""; }; - D29DF2A421E7B2A0003B2FB9 /* MFCaretView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFCaretView.h; sourceTree = ""; }; D29DF2A721E7B2F9003B2FB9 /* MVMCoreUIConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIConstants.h; sourceTree = ""; }; D29DF2A821E7B2F9003B2FB9 /* MVMCoreUIConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIConstants.m; sourceTree = ""; }; D29DF2AB21E7B3A4003B2FB9 /* MFTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFTextView.m; sourceTree = ""; }; @@ -317,6 +314,7 @@ D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIViewControllerMappingObject.m; sourceTree = ""; }; D2C5001B21F8EE66001DA659 /* LabelWithInternalButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelWithInternalButton.h; sourceTree = ""; }; D2C5001C21F8EE66001DA659 /* LabelWithInternalButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LabelWithInternalButton.m; sourceTree = ""; }; + DBC438FF224276B7001AB423 /* CaretView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaretView.swift; sourceTree = ""; }; DBD1E75422412BDB00C6AFF4 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -564,8 +562,6 @@ D29DF2AC21E7B3A4003B2FB9 /* MFTextView.xib */, D29DF15921E697DA003B2FB9 /* SeparatorView.h */, D29DF15A21E697DA003B2FB9 /* SeparatorView.m */, - D29DF2A421E7B2A0003B2FB9 /* MFCaretView.h */, - D29DF2A321E7B29F003B2FB9 /* MFCaretView.m */, D29DF2B121E7B76C003B2FB9 /* MFLoadingSpinner.h */, D29DF2B221E7B76D003B2FB9 /* MFLoadingSpinner.m */, D29DF32321ED0DA2003B2FB9 /* TextButtonView.h */, @@ -578,6 +574,7 @@ D22D1F19220341F50077CEC0 /* MVMCoreUICheckBox.m */, D22D1F44220496A30077CEC0 /* MVMCoreUISwitch.h */, D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */, + DBC438FF224276B7001AB423 /* CaretView.swift */, ); path = Views; sourceTree = ""; @@ -739,7 +736,6 @@ D29DF18221E69E54003B2FB9 /* SeparatorView.h in Headers */, D29DF26E21E6AA0B003B2FB9 /* FLAnimatedImage.h in Headers */, D29DF17321E69E1F003B2FB9 /* MFCaretButton.h in Headers */, - D29DF2A621E7B2A0003B2FB9 /* MFCaretView.h in Headers */, D2C5001D21F8EE67001DA659 /* LabelWithInternalButton.h in Headers */, D29DF11621E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.h in Headers */, D29DF17721E69E1F003B2FB9 /* MFTextButton.h in Headers */, @@ -856,6 +852,7 @@ D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, D29DF29621E7ADB8003B2FB9 /* StackableViewController.m in Sources */, D22D1F1F220343560077CEC0 /* MVMCoreUICheckMarkView.m in Sources */, + DBC43900224276B7001AB423 /* CaretView.swift in Sources */, D29DF11721E6805F003B2FB9 /* UIColor+MFConvenience.m in Sources */, D29DF25321E6A177003B2FB9 /* MFDigitTextField.m in Sources */, D29770F921F7C73800B2F0D0 /* PrimaryButtonView.m in Sources */, @@ -896,7 +893,6 @@ D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */, D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */, - D29DF2A521E7B2A0003B2FB9 /* MFCaretView.m in Sources */, D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */, D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */, D22D1F47220496A30077CEC0 /* MVMCoreUISwitch.m in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/MFCaretButton.m b/MVMCoreUI/Atoms/Buttons/MFCaretButton.m index bd8f058c..567fbb73 100644 --- a/MVMCoreUI/Atoms/Buttons/MFCaretButton.m +++ b/MVMCoreUI/Atoms/Buttons/MFCaretButton.m @@ -7,7 +7,7 @@ // #import "MFCaretButton.h" -#import "MFCaretView.h" +#import #import "UIColor+MFConvenience.h" @interface MFCaretButton () @@ -36,8 +36,8 @@ CGFloat const CaretViewWidth = 6.6f; - (void)changeCaretColor { [self setTitleColor:self.enableColor forState:UIControlStateNormal]; [self setTitleColor:self.disabledColor forState:UIControlStateDisabled]; - if ([self.rightView isKindOfClass:[MFCaretView class]]) { - MFCaretView *caretView = (MFCaretView *)self.rightView; + if ([self.rightView isKindOfClass:[CaretView class]]) { + CaretView *caretView = (CaretView *)self.rightView; if (self.enabled) { [caretView setLineColor:self.enableColor]; } else { @@ -54,7 +54,7 @@ CGFloat const CaretViewWidth = 6.6f; self.contentEdgeInsets = newInsets; UIView *caretViewIs = self.rightView; if (!self.rightView) { - caretViewIs = [[MFCaretView alloc]init]; + caretViewIs = [[CaretView alloc]init]; self.rightView = caretViewIs; } self.rightView.translatesAutoresizingMaskIntoConstraints = NO; diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift new file mode 100644 index 00000000..d6fedb46 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -0,0 +1,133 @@ +// +// CaretView.swift +// MobileFirstFramework +// +// Created by Kolli, Praneeth on 1/5/18. +// Converted by Christiano, Kevin on 1/5/18. +// Copyright © 2018 Verizon Wireless. All rights reserved. +// + + +open class CaretView: MFView { + //------------------------------------------------------ + // MARK: - Properties + //------------------------------------------------------ + + private(set) var strokeColor: UIColor? + private var lineWidth: CGFloat? + + //------------------------------------------------------ + // MARK: - Initialization + //------------------------------------------------------ + + @objc public init() { + super.init(frame: CGRect.zero) + + isOpaque = false + backgroundColor = .clear + strokeColor = .black + } + + @objc public override init(frame: CGRect) { + super.init(frame: frame) + + isOpaque = false + backgroundColor = .clear + strokeColor = .black + } + + @objc required public init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + + isOpaque = false + backgroundColor = .clear + strokeColor = .black + } + + @objc public init(lineWidth: CGFloat) { + super.init(frame: CGRect()) + + isOpaque = false + backgroundColor = .clear + self.lineWidth = lineWidth + strokeColor = .black + } + + //------------------------------------------------------ + // MARK: - Drawing + //------------------------------------------------------ + + @objc override open func draw(_ rect: CGRect) { + // Drawing Caret + let context = UIGraphicsGetCurrentContext() + context?.clear(rect) + + var lineWidthToDraw: CGFloat = 0.0 + + if let width = lineWidth { + lineWidthToDraw = width + } else { + lineWidthToDraw = frame.size.width / 2.6 + } + + let path = UIBezierPath() + path.move(to: CGPoint(x: lineWidthToDraw / 2.0, y: 0.0)) + path.addLine(to: CGPoint(x: frame.size.width, y: frame.size.height / 2.0)) + path.addLine(to: CGPoint(x: lineWidthToDraw / 2.0, y: frame.size.height)) + path.addLine(to: CGPoint(x: 0.0, y: frame.size.height - lineWidthToDraw / 2.0)) + path.addLine(to: CGPoint(x: frame.size.width - lineWidthToDraw, y: frame.size.height / 2.0)) + path.addLine(to: CGPoint(x: 0.0, y: lineWidthToDraw / 2.0)) + path.addLine(to: CGPoint(x: lineWidthToDraw / 2.0, y: 0.0)) + strokeColor?.setFill() + path.fill() + path.close() + backgroundColor = .clear + } + + @objc public func setLineColor(_ color: UIColor?) { + + strokeColor = color + setNeedsDisplay() + } + + //------------------------------------------------------ + // MARK: - Atomization + //------------------------------------------------------ + + // Default values for view. + @objc open override func setAsMolecule() { + + backgroundColor = .clear + strokeColor = .black + isHidden = false + isOpaque = false + } + + @objc override open func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegate: delegate, additionalData: additionalData) + + // Configure class properties with JSON values + guard let jsonDictionary = json else { return } + + if let backgroundColorHex = jsonDictionary[KeyBackgroundColor] as? String { + backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) + } + + if let strokeColorHex = jsonDictionary["strokeColor"] as? String { + strokeColor = UIColor.mfGet(forHex: strokeColorHex) + } + + if let isHiddenValue = jsonDictionary[KeyIsHidden] as? Bool { + isHidden = isHiddenValue + } + + if let isOpaqueValue = jsonDictionary[KeyIsOpaque] as? Bool { + isOpaque = isOpaqueValue + } + + if let lineWidthValue = jsonDictionary["lineWidth"] as? CGFloat { + lineWidth = lineWidthValue + } + } + +} diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 9c0e89f2..21ec35af 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -10,7 +10,7 @@ import MVMCore -@objc open class DashLine: MFView { +open class DashLine: MFView { //------------------------------------------------------ // MARK: - Properties //------------------------------------------------------ @@ -61,6 +61,13 @@ import MVMCore // MARK: - Atomization //------------------------------------------------------ + // Default values for view. + @objc open override func setAsMolecule() { + + backgroundColor = .clear + isHidden = false + } + @objc override open func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegate: delegate, additionalData: additionalData) diff --git a/MVMCoreUI/Atoms/Views/MFCaretView.h b/MVMCoreUI/Atoms/Views/MFCaretView.h deleted file mode 100644 index 48bc85a1..00000000 --- a/MVMCoreUI/Atoms/Views/MFCaretView.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// MFCaretView.h -// MobileFirstFramework -// -// Created by Kolli, Praneeth on 1/5/18. -// Copyright © 2018 Verizon Wireless. All rights reserved. -// - -#import - -@interface MFCaretView : UIView -@property (strong, nonatomic, readonly) UIColor *strokeColor; -- (instancetype)initWithLineWidth:(CGFloat)lineWidth; -- (void)setLineColor:(UIColor *)color; -@end diff --git a/MVMCoreUI/Atoms/Views/MFCaretView.m b/MVMCoreUI/Atoms/Views/MFCaretView.m deleted file mode 100644 index 182f7a74..00000000 --- a/MVMCoreUI/Atoms/Views/MFCaretView.m +++ /dev/null @@ -1,93 +0,0 @@ -// -// MFCaretView.m -// MobileFirstFramework -// -// Created by Kolli, Praneeth on 1/5/18. -// Copyright © 2018 Verizon Wireless. All rights reserved. -// - -#import "MFCaretView.h" -#import "UIColor+MFConvenience.h" -@interface MFCaretView () -@property (strong, nonatomic, readwrite) UIColor *strokeColor; -@property (nonatomic) NSNumber *lineWidth; - -@end - -@implementation MFCaretView - -- (instancetype)init { - self = [super init]; - if (self) { - // Initialization code - self.opaque = NO; - self.backgroundColor = [UIColor clearColor]; - self.strokeColor = [UIColor blackColor]; - } - return self; -} - -- (instancetype)initWithFrame:(CGRect)frame { - self = [super initWithFrame:frame]; - if (self) { - // Initialization code - self.opaque = NO; - self.backgroundColor = [UIColor clearColor]; - self.strokeColor = [UIColor blackColor]; - } - return self; -} - -- (instancetype)initWithCoder:(NSCoder *)aDecoder { - self = [super initWithCoder:aDecoder]; - if (self) { - // Initialization code - self.opaque = NO; - self.backgroundColor = [UIColor clearColor]; - self.strokeColor = [UIColor blackColor]; - } - return self; -} - -- (instancetype)initWithLineWidth:(CGFloat)lineWidth { - if (self = [super init]) { - self.opaque = NO; - self.backgroundColor = [UIColor clearColor]; - self.lineWidth = @(lineWidth); - self.strokeColor = [UIColor blackColor]; - } - return self; -} - -- (void)drawRect:(CGRect)rect { - // Drawing Caret - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextClearRect(context, rect); - - CGFloat lineWidth; - if (self.lineWidth) { - lineWidth = self.lineWidth.floatValue; - } else { - lineWidth = self.frame.size.width/2.6; - } - - UIBezierPath *path = [[UIBezierPath alloc] init]; - [path moveToPoint:CGPointMake(lineWidth/2.0, 0.0)]; - [path addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height/2.0)]; - [path addLineToPoint:CGPointMake(lineWidth/2.0, self.frame.size.height)]; - [path addLineToPoint:CGPointMake(0.0, self.frame.size.height-lineWidth/2.0)]; - [path addLineToPoint:CGPointMake(self.frame.size.width-lineWidth, self.frame.size.height/2.0)]; - [path addLineToPoint:CGPointMake(0.0, lineWidth/2.0)]; - [path addLineToPoint:CGPointMake(lineWidth/2.0, 0.0)]; - [self.strokeColor setFill]; - [path fill]; - [path closePath]; - [self setBackgroundColor:[UIColor clearColor]]; -} - -- (void)setLineColor:(UIColor *)color { - self.strokeColor = color; - [self setNeedsDisplay]; -} - -@end diff --git a/MVMCoreUI/MVMCoreUI.h b/MVMCoreUI/MVMCoreUI.h index 1082acaf..9d3fa052 100644 --- a/MVMCoreUI/MVMCoreUI.h +++ b/MVMCoreUI/MVMCoreUI.h @@ -80,7 +80,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[]; #import #import #import -#import #import #import #import diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index eeb93394..29fc77ce 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -29,7 +29,8 @@ @"moleculeStack": MoleculeStackView.class, @"twoButtonView": PrimaryButtonView.class, @"standardFooter": StandardFooterView.class, - @"dashLine": DashLine.class + @"dashLine": DashLine.class, + @"caretView": CaretView.class } mutableCopy]; }); return mapping; diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 112fa3e0..93f77713 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -33,6 +33,7 @@ extern NSString * const KeyText; extern NSString * const KeyTextColor; extern NSString * const KeyIsHidden; +extern NSString * const KeyIsOpaque; #pragma mark - Values diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 5ec58ac7..684f013b 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -32,6 +32,7 @@ NSString * const KeyText = @"text"; NSString * const KeyTextColor = @"textColor"; NSString * const KeyIsHidden = @"isHidden"; +NSString * const KeyIsOpaque = @"isOpaque"; #pragma mark - Values