change CaretButton to MFCaretButton in legacy view/viewcontroller, CaretButton will be only used in molecule

This commit is contained in:
Xinlei(Ryan) Pan 2020-02-04 13:59:14 -05:00
parent 8d6e448817
commit 2b74531ce1
6 changed files with 266 additions and 0 deletions

View File

@ -106,6 +106,10 @@
9455B19C234F8A0400A574DB /* MVMAnimationFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */; };
946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */; };
948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; };
94AF4A3E23E9D13900676048 /* MFCaretButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 94AF4A3C23E9D13900676048 /* MFCaretButton.h */; settings = {ATTRIBUTES = (Public, ); }; };
94AF4A3F23E9D13900676048 /* MFCaretButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 94AF4A3D23E9D13900676048 /* MFCaretButton.m */; };
94AF4A4223E9D19E00676048 /* MFCaretView.h in Headers */ = {isa = PBXBuildFile; fileRef = 94AF4A4023E9D19E00676048 /* MFCaretView.h */; settings = {ATTRIBUTES = (Public, ); }; };
94AF4A4323E9D19E00676048 /* MFCaretView.m in Sources */ = {isa = PBXBuildFile; fileRef = 94AF4A4123E9D19E00676048 /* MFCaretView.m */; };
94C2D9842386F3F80006CF46 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */; };
94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */; };
94C2D9A323872C110006CF46 /* LabelAttributeStrikeThroughModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A223872C110006CF46 /* LabelAttributeStrikeThroughModel.swift */; };
@ -420,6 +424,10 @@
9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MVMAnimationFramework.framework; path = ../SharedFrameworks/MVMAnimationFramework.framework; sourceTree = "<group>"; };
946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeModelHelper.swift; sourceTree = "<group>"; };
948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = "<group>"; };
94AF4A3C23E9D13900676048 /* MFCaretButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MFCaretButton.h; sourceTree = "<group>"; };
94AF4A3D23E9D13900676048 /* MFCaretButton.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MFCaretButton.m; sourceTree = "<group>"; };
94AF4A4023E9D19E00676048 /* MFCaretView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MFCaretView.h; sourceTree = "<group>"; };
94AF4A4123E9D19E00676048 /* MFCaretView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MFCaretView.m; sourceTree = "<group>"; };
94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = "<group>"; };
94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeUnderlineModel.swift; sourceTree = "<group>"; };
94C2D9A223872C110006CF46 /* LabelAttributeStrikeThroughModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeStrikeThroughModel.swift; sourceTree = "<group>"; };
@ -828,6 +836,10 @@
D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */,
D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */,
D282AACA2243C61700C46919 /* ButtonView.swift */,
94AF4A3C23E9D13900676048 /* MFCaretButton.h */,
94AF4A3D23E9D13900676048 /* MFCaretButton.m */,
94AF4A4023E9D19E00676048 /* MFCaretView.h */,
94AF4A4123E9D19E00676048 /* MFCaretView.m */,
);
path = Views;
sourceTree = "<group>";
@ -1408,6 +1420,7 @@
D29DF27521E79E81003B2FB9 /* MVMCoreUILoggingHandler.h in Headers */,
D29DF28B21E7AC2B003B2FB9 /* ViewConstrainingView.h in Headers */,
D29DF2B321E7B76D003B2FB9 /* MFLoadingSpinner.h in Headers */,
94AF4A3E23E9D13900676048 /* MFCaretButton.h in Headers */,
0A21DB8A235E06EF00C160A2 /* MFDigitTextBox.h in Headers */,
D29DF32521ED0DA2003B2FB9 /* TextButtonView.h in Headers */,
0A21DB8C235E06EF00C160A2 /* MFDigitTextField.h in Headers */,
@ -1426,6 +1439,7 @@
D29DF2CA21E7BFC8003B2FB9 /* MFSizeThreshold.h in Headers */,
D29DF28021E7AA51003B2FB9 /* MVMCoreUIDetailViewProtocol.h in Headers */,
D29DF2BD21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.h in Headers */,
94AF4A4223E9D19E00676048 /* MFCaretView.h in Headers */,
D29DF2EE21ECEADF003B2FB9 /* MFFonts.h in Headers */,
D29DF12D21E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.h in Headers */,
D29770F321F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h in Headers */,
@ -1671,6 +1685,7 @@
944589212385D6E900DE9FD4 /* DashLineModel.swift in Sources */,
D2E2A99623D8CF85000B42E6 /* HeadlineBodyLinkToggleModel.swift in Sources */,
C6FA7D5323C77A4A00A3614A /* StringAndMoleculeStack.swift in Sources */,
94AF4A3F23E9D13900676048 /* MFCaretButton.m in Sources */,
D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */,
D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */,
D28A838F23CCDEDE00DFE4FC /* TwoButtonViewModel.swift in Sources */,
@ -1720,6 +1735,7 @@
D2B1E3E522F37D6A0065F95C /* ImageHeadlineBody.swift in Sources */,
0A21DB94235E24ED00C160A2 /* DigitEntryField.swift in Sources */,
0A21DB8D235E06EF00C160A2 /* MFDigitTextField.m in Sources */,
94AF4A4323E9D19E00676048 /* MFCaretView.m in Sources */,
943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */,
D29DF2AA21E7B2F9003B2FB9 /* MVMCoreUIConstants.m in Sources */,
948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */,

View File

@ -0,0 +1,26 @@
//
// MFCaretButton.h
// MobileFirstFramework
//
// Created by Kolli, Praneeth on 1/5/18.
// Copyright © 2018 Verizon Wireless. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MVMCoreUI/MFCustomButton.h>
@interface MFCaretButton : MFCustomButton
@property (nullable, nonatomic, strong) UIView *rightView;
@property (nullable, nonatomic, strong) NSNumber *rightViewHeight;
@property (nullable, nonatomic, strong) NSNumber *rightViewWidth;
-(void)updateCaretSpacing:(CGFloat)spacing;
/* The fill color of the Caret and titleLabel. The default is blackColor */
-(void)setEnableCaretColor:(nullable UIColor *)enableCaretColor;
/* The fill color of the Caret and titleLabel. The default is mfSilver */
-(void)setDisabledCaretColor:(nullable UIColor *)disabledCaretColor;
@end

View File

@ -0,0 +1,113 @@
//
// MFCaretButton.m
// MobileFirstFramework
//
// Created by Kolli, Praneeth on 1/5/18.
// Copyright © 2018 Verizon Wireless. All rights reserved.
//
#import "MFCaretButton.h"
#import "MFCaretView.h"
#import "UIColor+MFConvenience.h"
@interface MFCaretButton ()
@property (nonatomic, strong) UIColor *enableColor;
@property (nonatomic, strong) UIColor *disabledColor;
@property (nonatomic, strong) NSLayoutConstraint *caretSpacingConstraint;
@end
@implementation MFCaretButton
CGFloat const CaretViewHeight = 10.8f;
CGFloat const CaretViewWidth = 6.6f;
- (void)layoutSubviews {
[self addCaretImageView];
[super layoutSubviews];
}
- (void)setEnabled:(BOOL)enabled {
[super setEnabled:enabled];
[self changeCaretColor];
}
- (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.enabled) {
[caretView setLineColor:self.enableColor];
} else {
[caretView setLineColor:self.disabledColor];
}
}
}
- (void)addCaretImageView {
[self.rightView removeFromSuperview];
UIEdgeInsets edgeInsets = self.contentEdgeInsets;
CGFloat rightInset = self.rightViewWidth?self.rightViewWidth.floatValue:CaretViewWidth;
UIEdgeInsets newInsets = UIEdgeInsetsMake(edgeInsets.top, edgeInsets.left, edgeInsets.bottom, 4 + rightInset);
self.contentEdgeInsets = newInsets;
UIView *caretViewIs = self.rightView;
if (!self.rightView) {
caretViewIs = [[MFCaretView alloc]init];
self.rightView = caretViewIs;
}
self.rightView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.rightView];
CGFloat width = self.rightViewWidth?self.rightViewWidth.floatValue:CaretViewWidth;
NSLayoutConstraint *caretViewWidthConstraint = [NSLayoutConstraint constraintWithItem:caretViewIs attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:width];
caretViewWidthConstraint.active = YES;
CGFloat height = self.rightViewHeight?self.rightViewHeight.floatValue:CaretViewHeight;
NSLayoutConstraint *caretViewHeightConstraint = [NSLayoutConstraint constraintWithItem:caretViewIs attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:height];
caretViewHeightConstraint.active = YES;
NSLayoutConstraint *caretLabelSpacing = [NSLayoutConstraint constraintWithItem:caretViewIs attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.titleLabel attribute:NSLayoutAttributeRight multiplier:1.0 constant:4.0];
caretLabelSpacing.active = YES;
self.caretSpacingConstraint = caretLabelSpacing;
NSLayoutConstraint *caretCenterY = [NSLayoutConstraint constraintWithItem:caretViewIs attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];
caretCenterY.active = YES;
NSLayoutConstraint *caretLabelRightPin = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:caretViewIs attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
caretLabelRightPin.active = YES;
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//set correct color after layout
[self changeCaretColor];
}
- (void)updateCaretSpacing:(CGFloat)spacing {
if (self.caretSpacingConstraint != nil) {
self.caretSpacingConstraint.constant = spacing;
}
}
- (void)setEnableCaretColor:(UIColor *)enableCaretColor {
self.enableColor = enableCaretColor;
[self changeCaretColor];
}
- (void)setDisabledCaretColor:(UIColor *)disabledCaretColor {
self.disabledColor = disabledCaretColor;
[self changeCaretColor];
}
@synthesize enableColor = _enableColor;
- (UIColor *)enableColor {
if (!_enableColor) {
_enableColor = [UIColor blackColor];
}
return _enableColor;
}
@synthesize disabledColor = _disabledColor;
- (UIColor *)disabledColor {
if (!_disabledColor) {
_disabledColor = [UIColor mfSilver];
}
return _disabledColor;
}
@end

View File

@ -0,0 +1,16 @@
//
// MFCaretView.h
// MobileFirstFramework
//
// Created by Kolli, Praneeth on 1/5/18.
// Copyright © 2018 Verizon Wireless. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface MFCaretView : UIView
@property (strong, nonatomic, readonly) UIColor *strokeColor;
- (instancetype)initWithLineWidth:(CGFloat)lineWidth;
- (void)setLineColor:(UIColor *)color;
@end

View File

@ -0,0 +1,93 @@
//
// 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

View File

@ -81,6 +81,7 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[];
#import <MVMCoreUI/MVMCoreUICheckBox.h>
#import <MVMCoreUI/MVMCoreUISwitch.h>
#import <MVMCoreUI/MFRadioButton.h>
#import <MVMCoreUI/MFCaretView.h>
#pragma mark Buttons
#import <MVMCoreUI/MFButtonProtocol.h>
@ -89,6 +90,7 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[];
#import <MVMCoreUI/PrimaryButton.h>
#import <MVMCoreUI/MFTextButton.h>
#import <MVMCoreUI/PrimaryButtonView.h>
#import <MVMCoreUI/MFCaretButton.h>
#pragma mark TextFields
#import <MVMCoreUI/MFTextField.h>