Converted DashLine class, replacing objective-c version. Provided capacity for atomization. Added constant value "isHidden". Updated import statements to allow for cross language interpretation.

This commit is contained in:
Christiano, Kevin 2019-03-19 11:28:05 -04:00
parent 1c55f01f43
commit a5ff57f65c
8 changed files with 97 additions and 73 deletions

View File

@ -78,8 +78,6 @@
D29DF25621E6A177003B2FB9 /* MFTextFieldSubclassExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF24B21E6A177003B2FB9 /* MFTextFieldSubclassExtension.h */; settings = {ATTRIBUTES = (Public, ); }; };
D29DF25721E6A177003B2FB9 /* MFTextField.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF24C21E6A177003B2FB9 /* MFTextField.h */; settings = {ATTRIBUTES = (Public, ); }; };
D29DF25921E6A22D003B2FB9 /* MFButtonProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF25821E6A22D003B2FB9 /* MFButtonProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
D29DF25C21E6A2B6003B2FB9 /* DashLine.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF25A21E6A2B6003B2FB9 /* DashLine.h */; settings = {ATTRIBUTES = (Public, ); }; };
D29DF25D21E6A2B6003B2FB9 /* DashLine.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF25B21E6A2B6003B2FB9 /* DashLine.m */; };
D29DF26021E6A985003B2FB9 /* MFLoadImageView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF25E21E6A985003B2FB9 /* MFLoadImageView.h */; settings = {ATTRIBUTES = (Public, ); }; };
D29DF26121E6A985003B2FB9 /* MFLoadImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF25F21E6A985003B2FB9 /* MFLoadImageView.m */; };
D29DF26421E6A9D9003B2FB9 /* MFTransparentGIFView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF26221E6A9D9003B2FB9 /* MFTransparentGIFView.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -160,6 +158,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 */; };
DBD1E75522412BDB00C6AFF4 /* DashLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBD1E75422412BDB00C6AFF4 /* DashLine.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -244,8 +243,6 @@
D29DF24B21E6A177003B2FB9 /* MFTextFieldSubclassExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFTextFieldSubclassExtension.h; sourceTree = "<group>"; };
D29DF24C21E6A177003B2FB9 /* MFTextField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFTextField.h; sourceTree = "<group>"; };
D29DF25821E6A22D003B2FB9 /* MFButtonProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFButtonProtocol.h; sourceTree = "<group>"; };
D29DF25A21E6A2B6003B2FB9 /* DashLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DashLine.h; sourceTree = "<group>"; };
D29DF25B21E6A2B6003B2FB9 /* DashLine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DashLine.m; sourceTree = "<group>"; };
D29DF25E21E6A985003B2FB9 /* MFLoadImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFLoadImageView.h; sourceTree = "<group>"; };
D29DF25F21E6A985003B2FB9 /* MFLoadImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFLoadImageView.m; sourceTree = "<group>"; };
D29DF26221E6A9D9003B2FB9 /* MFTransparentGIFView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFTransparentGIFView.h; sourceTree = "<group>"; };
@ -320,6 +317,7 @@
D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIViewControllerMappingObject.m; sourceTree = "<group>"; };
D2C5001B21F8EE66001DA659 /* LabelWithInternalButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelWithInternalButton.h; sourceTree = "<group>"; };
D2C5001C21F8EE66001DA659 /* LabelWithInternalButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LabelWithInternalButton.m; sourceTree = "<group>"; };
DBD1E75422412BDB00C6AFF4 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -546,6 +544,7 @@
D29DF17D21E69E26003B2FB9 /* Views */ = {
isa = PBXGroup;
children = (
DBD1E75422412BDB00C6AFF4 /* DashLine.swift */,
D29DF17E21E69E2E003B2FB9 /* MFView.h */,
D29DF17F21E69E2E003B2FB9 /* MFView.m */,
D29DF28521E7AC2B003B2FB9 /* MFLabel.h */,
@ -565,8 +564,6 @@
D29DF2AC21E7B3A4003B2FB9 /* MFTextView.xib */,
D29DF15921E697DA003B2FB9 /* SeparatorView.h */,
D29DF15A21E697DA003B2FB9 /* SeparatorView.m */,
D29DF25A21E6A2B6003B2FB9 /* DashLine.h */,
D29DF25B21E6A2B6003B2FB9 /* DashLine.m */,
D29DF2A421E7B2A0003B2FB9 /* MFCaretView.h */,
D29DF2A321E7B29F003B2FB9 /* MFCaretView.m */,
D29DF2B121E7B76C003B2FB9 /* MFLoadingSpinner.h */,
@ -706,7 +703,6 @@
D29DF18021E69E49003B2FB9 /* MFView.h in Headers */,
D29DF26421E6A9D9003B2FB9 /* MFTransparentGIFView.h in Headers */,
D29DF27921E7A533003B2FB9 /* MVMCoreUISession.h in Headers */,
D29DF25C21E6A2B6003B2FB9 /* DashLine.h in Headers */,
D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationController.h in Headers */,
D29DF29D21E7AE38003B2FB9 /* MFStyler.h in Headers */,
D29DF2B021E7B3A4003B2FB9 /* MFTextView.h in Headers */,
@ -868,6 +864,7 @@
D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */,
D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */,
D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */,
DBD1E75522412BDB00C6AFF4 /* DashLine.swift in Sources */,
D29DF12E21E6851E003B2FB9 /* MVMCoreUITopAlertView.m in Sources */,
D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */,
D22D1F572204CE5D0077CEC0 /* MVMCoreUIStackableViewController.m in Sources */,
@ -900,7 +897,6 @@
D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */,
D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */,
D29DF2A521E7B2A0003B2FB9 /* MFCaretView.m in Sources */,
D29DF25D21E6A2B6003B2FB9 /* DashLine.m in Sources */,
D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */,
D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */,
D22D1F47220496A30077CEC0 /* MVMCoreUISwitch.m in Sources */,

View File

@ -7,7 +7,7 @@
//
#import "MFTextField.h"
#import "DashLine.h"
#import <MVMCoreUI/MVMCoreUI-Swift.h>
#import "MFTextFieldSubclassExtension.h"
#import "MFStyler.h"
#import "UIColor+MFConvenience.h"

View File

@ -1,17 +0,0 @@
//
// DashLine.h
// mobilefirst
//
// Created by Chris Yang on 2/11/16.
// Copyright © 2016 Verizon Wireless. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MVMCoreUI/MFView.h>
@interface DashLine : MFView
@property (nonatomic, strong) UIColor *bgColor;
@property (nonatomic, strong) UIColor *dashColor;
@end

View File

@ -1,46 +0,0 @@
//
// DashLine.m
// mobilefirst
//
// Created by Chris Yang on 2/11/16.
// Copyright © 2016 Verizon Wireless. All rights reserved.
//
#import "DashLine.h"
#import "UIColor+MFConvenience.h"
@import MVMCore.MVMCoreDispatchUtility;
@implementation DashLine
- (void)updateView:(CGFloat)size {
[MVMCoreDispatchUtility performBlockOnMainThread:^{
[self setNeedsDisplay];
}];
}
- (void)drawRect:(CGRect)rect {
CAShapeLayer *dashLayer = [[CAShapeLayer alloc]init];
dashLayer.backgroundColor = [UIColor clearColor].CGColor;
dashLayer.frame = self.bounds;
for (CAShapeLayer *sublayer in self.layer.sublayers) {
[sublayer removeFromSuperlayer];
}
[self.layer addSublayer:dashLayer];
UIBezierPath *path = [[UIBezierPath alloc]init];
[path moveToPoint:CGPointMake(dashLayer.frame.origin.x, dashLayer.frame.size.height/2.f)]; //add yourStartPoint here
[path addLineToPoint:CGPointMake(dashLayer.frame.size.width, 0)];
[path stroke];
dashLayer.strokeStart = 0.0;
dashLayer.lineWidth = 1;
dashLayer.lineJoin = kCALineJoinMiter;
dashLayer.lineCap = kCALineCapRound;
dashLayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:2],[NSNumber numberWithInt:2], nil];
dashLayer.path = path.CGPath;
dashLayer.strokeColor = self.dashColor.CGColor ?: [UIColor mfLighterGrayColor].CGColor;
dashLayer.fillColor = [UIColor clearColor].CGColor;
dashLayer.backgroundColor = self.bgColor.CGColor ?: [UIColor whiteColor].CGColor;
}
@end

View File

@ -0,0 +1,88 @@
//
// DashLine_Swift.swift
// MVMCoreUI
// Created by Chris Yang on 2/11/16.
// Converted by Christiano, Kevin on 3/18/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import MVMCore
@objc open class DashLine: MFView {
//------------------------------------------------------
// MARK: - Properties
//------------------------------------------------------
@objc public var bgColor: UIColor?
@objc public var dashColor: UIColor?
//------------------------------------------------------
// MARK: - Lifecycle
//------------------------------------------------------
@objc override open func updateView(_ size: CGFloat) {
MVMCoreDispatchUtility.performBlock(onMainThread: {
self.setNeedsDisplay()
})
}
@objc override open func draw(_ rect: CGRect) {
let dashLayer = CAShapeLayer()
dashLayer.backgroundColor = UIColor.clear.cgColor
dashLayer.frame = bounds
if let sublayers = self.layer.sublayers {
for sublayer in sublayers {
sublayer.removeFromSuperlayer()
}
}
self.layer.addSublayer(dashLayer)
let path = UIBezierPath()
path.move(to: CGPoint(x: dashLayer.frame.origin.x, y: dashLayer.frame.size.height / 2.0)) //add yourStartPoint here
path.addLine(to: CGPoint(x: dashLayer.frame.size.width, y: 0))
path.stroke()
dashLayer.strokeStart = 0.0
dashLayer.lineWidth = 1
dashLayer.lineJoin = .miter
dashLayer.lineCap = .round
dashLayer.lineDashPattern = [NSNumber(value: 2), NSNumber(value: 2)]
dashLayer.path = path.cgPath
dashLayer.strokeColor = self.dashColor?.cgColor ?? UIColor.mfLighterGray().cgColor
dashLayer.fillColor = UIColor.clear.cgColor
dashLayer.backgroundColor = self.bgColor?.cgColor ?? UIColor.white.cgColor
}
//------------------------------------------------------
// MARK: - Atomization
//------------------------------------------------------
@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 {
self.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex)
}
if let isHiddenValue = jsonDictionary[KeyIsHidden] as? Bool {
self.isHidden = isHiddenValue
}
if let bgColorHex = jsonDictionary["bgColor"] as? String {
self.bgColor = UIColor.mfGet(forHex: bgColorHex)
}
if let dashColorHex = jsonDictionary["dashColor"] as? String {
self.dashColor = UIColor.mfGet(forHex: dashColorHex)
}
}
}

View File

@ -84,7 +84,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[];
#import <MVMCoreUI/SeparatorView.h>
#import <MVMCoreUI/LabelView.h>
#import <MVMCoreUI/TextButtonView.h>
#import <MVMCoreUI/DashLine.h>
#import <MVMCoreUI/MVMCoreUITextFieldView.h>
#import <MVMCoreUI/MVMCoreUICheckMarkView.h>
#import <MVMCoreUI/MVMCoreUICheckBox.h>

View File

@ -32,6 +32,8 @@ extern NSString * const KeyBackgroundColor;
extern NSString * const KeyText;
extern NSString * const KeyTextColor;
extern NSString * const KeyIsHidden;
#pragma mark - Values
extern NSString * const StringY;

View File

@ -31,6 +31,8 @@ NSString * const KeyBackgroundColor = @"backgroundColor";
NSString * const KeyText = @"text";
NSString * const KeyTextColor = @"textColor";
NSString * const KeyIsHidden = @"isHidden";
#pragma mark - Values
NSString * const StringY = @"Y";