Removed MFLabel. Reflected delegate paradigm.

This commit is contained in:
Christiano, Kevin 2019-04-18 10:01:35 -04:00
parent 17decc6602
commit 83dda81d55
4 changed files with 4 additions and 359 deletions

View File

@ -316,8 +316,8 @@
D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerViewController.swift; sourceTree = "<group>"; };
D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewControllerMappingObject.h; sourceTree = "<group>"; };
D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIViewControllerMappingObject.m; sourceTree = "<group>"; };
DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
D2E1FADA2260D3D200AEFD8C /* MVMCoreUIDelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreUIDelegateObject.swift; sourceTree = "<group>"; };
DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
DBC4391622442196001AB423 /* CaretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretView.swift; sourceTree = "<group>"; };
DBC4391722442197001AB423 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = "<group>"; };
DBC4391A224421A0001AB423 /* CaretButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretButton.swift; sourceTree = "<group>"; };

View File

@ -151,7 +151,7 @@ import MVMCore
}
}
@objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) {
@objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) {
guard let label = label else { return }
@ -307,8 +307,8 @@ import MVMCore
setupView()
}
@objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) {
Label.setUILabel(self, withJSON: json, delegate: delegate, additionalData: additionalData)
@objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
Label.setUILabel(self, withJSON: json, delegate: delegateObject, additionalData: additionalData)
// guard let dictionary = json else { return }

View File

@ -1,64 +0,0 @@
//
// MFLabel.h
// mobilefirst
//
// Created by Scott Pfeil on 3/22/17.
// Copyright © 2017 Verizon Wireless. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MVMCoreUI/MFView.h>
@class MFSizeObject;
@class DelegateObject;
@interface MFLabel : UILabel <MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol>
- (nullable instancetype)initWithStandardFontSize:(CGFloat)size;
// Set this property if you want updateView to update the font based on this standard and the size passed in.
@property (nonatomic) CGFloat standardFontSize;
// Set this to use a custom sizing object during updateView instead of the standard.
@property (nonatomic, strong, nullable) MFSizeObject *sizeObject;
// Set the font and set to scale
- (void)setFont:(nonnull UIFont *)font scale:(BOOL)scale;
// Convenience checker for text or attributed text.
- (BOOL)hasText;
#pragma mark - 2.0
//75Bd 40pt
+ (nonnull MFLabel *)commonLabelH1:(BOOL)scale;
//75Bd 25pt
+ (nonnull MFLabel *)commonLabelH2:(BOOL)scale;
//75Bd 18pt
+ (nonnull MFLabel *)commonLabelH3:(BOOL)scale;
//75Bd 32pt
+ (nonnull MFLabel *)commonLabelH32:(BOOL)scale;
//75Bd 13pt
+ (nonnull MFLabel *)commonLabelB1:(BOOL)scale;
//55Rg 13pt
+ (nonnull MFLabel *)commonLabelB2:(BOOL)scale;
//55Rg 11pt gray
+ (nonnull MFLabel *)commonLabelB3:(BOOL)scale;
//55Rg 20pt
+ (nonnull MFLabel *)commonLabelB20:(BOOL)scale;
// Getters
+ (nonnull MFLabel *)label NS_SWIFT_NAME(commonLabel());
// Setters
+ (void)setLabel:(nullable UILabel *)label withHTML:(nullable NSString *)html;
+ (void)setUILabel:(nullable UILabel *)label withJSON:(nullable NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData;
- (void)styleH1:(BOOL)scale;
- (void)styleH2:(BOOL)scale;
- (void)styleH3:(BOOL)scale;
- (void)styleH32:(BOOL)scale;
- (void)styleB1:(BOOL)scale;
- (void)styleB2:(BOOL)scale;
- (void)styleB3:(BOOL)scale;
- (void)styleB20:(BOOL)scale;
@end

View File

@ -1,291 +0,0 @@
//
// MFLabel.m
// mobilefirst
//
// Created by Scott Pfeil on 3/22/17.
// Copyright © 2017 Verizon Wireless. All rights reserved.
//
#import "MFLabel.h"
#import <MVMCoreUI/MFStyler.h>
#import <MVMCoreUI/MFSizeObject.h>
#import <MVMCoreUI/MVMCoreUIConstants.h>
#import "UIColor+MFConvenience.h"
#import "MFFonts.h"
#import "MVMCoreUISplitViewController.h"
#import "MVMCoreUILoggingHandler.h"
@import MVMCore.MVMCoreGetterUtility;
@import MVMCore.NSDictionary_MFConvenience;
@import MVMCore.MVMCoreJSONConstants;
@interface MFLabel ()
@property (strong, nonatomic) NSNumber *scaleSize;
// Used for scaling the font in updateView.
@property (strong, nonatomic) NSAttributedString *originalAttributedString;
@end
@implementation MFLabel
- (void)setupView {
self.backgroundColor = [UIColor clearColor];
self.numberOfLines = 0;
self.lineBreakMode = NSLineBreakByWordWrapping;
self.translatesAutoresizingMaskIntoConstraints = NO;
}
- (instancetype)init {
if (self = [super init]) {
[self setupView];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
[self setupView];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setupView];
}
return self;
}
- (instancetype)initWithStandardFontSize:(CGFloat)size {
if ([self init]) {
self.standardFontSize = size;
}
return self;
}
- (void)updateView:(CGFloat)size {
self.scaleSize = @(size);
if (self.originalAttributedString) {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.originalAttributedString];
[attributedString removeAttribute:NSFontAttributeName range:NSMakeRange(0, attributedString.length)];
[self.originalAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, self.originalAttributedString.length) options:0 usingBlock:^(UIFont *value, NSRange range, BOOL * _Nonnull stop) {
// Loop the original attributed string, resize the fonts.
UIFont *font = [value fontWithSize:[[MFStyler sizeObjectGenericForCurrentDevice:value.pointSize] getValueBasedOnSize:size]];
[attributedString addAttribute:NSFontAttributeName value:font range:range];
}];
self.attributedText = attributedString;
} else if (!fequal(self.standardFontSize, 0)) {
MFSizeObject *sizeObject = self.sizeObject;
if (!sizeObject) {
sizeObject = [MFStyler sizeObjectGenericForCurrentDevice:self.standardFontSize];
}
self.font = [self.font fontWithSize:[sizeObject getValueBasedOnSize:size]];
}
}
- (void)setFont:(nonnull UIFont *)font scale:(BOOL)scale {
self.font = font;
[self setScale:scale];
}
- (void)setScale:(BOOL)scale {
if (scale) {
self.standardFontSize = self.font.pointSize;
[self updateView:(self.scaleSize ? self.scaleSize.floatValue : [MVMCoreUISplitViewController getApplicationViewWidth])];
} else {
self.standardFontSize = 0;
}
}
- (BOOL)hasText {
return self.text.length > 0 || self.attributedText.length > 0;
}
#pragma mark - 2.0
+ (nonnull MFLabel *)commonLabelH1:(BOOL)scale {
MFLabel *label = [MFLabel label];
[label styleH1:scale];
return label;
}
+ (nonnull MFLabel *)commonLabelH2:(BOOL)scale {
MFLabel *label = [MFLabel label];
[label styleH2:scale];
return label;
}
+ (nonnull MFLabel *)commonLabelH3:(BOOL)scale {
MFLabel *label = [MFLabel label];
[label styleH3:scale];
return label;
}
+ (nonnull MFLabel *)commonLabelH32:(BOOL)scale {
MFLabel *label = [MFLabel label];
[label styleH32:scale];
return label;
}
+ (nonnull MFLabel *)commonLabelB1:(BOOL)scale {
MFLabel *label = [MFLabel label];
[label styleB1:scale];
return label;
}
+ (nonnull MFLabel *)commonLabelB2:(BOOL)scale {
MFLabel *label = [MFLabel label];
[label styleB2:scale];
return label;
}
+ (nonnull MFLabel *)commonLabelB3:(BOOL)scale {
MFLabel *label = [MFLabel label];
[label styleB3:scale];
return label;
}
+ (nonnull MFLabel *)commonLabelB20:(BOOL)scale {
MFLabel *label = [MFLabel label];
[label styleB20:scale];
return label;
}
+ (nonnull MFLabel *)label {
return [[MFLabel alloc] initWithFrame:CGRectZero];
}
#pragma mark - Setters
+ (void)setLabel:(nullable UILabel *)label withHTML:(nullable NSString *)html {
NSData *data = [html dataUsingEncoding:kCFStringEncodingUTF8];
if (data) {
NSError *error = nil;
label.attributedText = [[NSAttributedString alloc] initWithData:data options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:&error];
if (error) {
[[MVMCoreUILoggingHandler sharedLoggingHandler] addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:@"LabelHTMLParse"]];
}
}
}
+ (void)setUILabel:(nullable UILabel *)label withJSON:(nullable NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData {
if (label) {
label.text = [json string:KeyText];
[self setLabel:label withHTML:[json string:@"html"]];
NSString *textColor = [json string:KeyTextColor];
if (textColor) {
label.textColor = [UIColor mfGetColorForHex:textColor];
}
NSString *backgroundColor = [json string:KeyBackgroundColor];
if (backgroundColor) {
label.backgroundColor = [UIColor mfGetColorForHex:backgroundColor];
}
NSString *accessibilityText = [json string:@"accessibilityText"];
if (accessibilityText) {
label.accessibilityLabel = accessibilityText;
}
NSString *fontName = [json string:@"fontName"];
NSNumber *fontSize = [json optionalNumberForKey:@"fontSize"];
if (fontName) {
label.font = [MFFonts mfFontWithName:fontName size:fontSize ? fontSize.doubleValue : label.font.pointSize];
} else if (fontSize) {
label.font = [label.font fontWithSize:fontSize.doubleValue];
}
NSArray *attributes = [json array:@"attributes"];
if (attributes) {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text attributes:@{NSFontAttributeName:label.font,NSForegroundColorAttributeName:label.textColor}];
for (NSDictionary *attribute in attributes) {
NSNumber *location = [attribute optionalNumberForKey:@"location"];
NSNumber *length = [attribute optionalNumberForKey:@"length"];
if (location && length) {
NSRange range = NSMakeRange(location.unsignedIntegerValue, length.unsignedIntegerValue);
NSString *type = [attribute string:KeyType];
if ([type isEqualToString:@"underline"]) {
[attributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
} else if ([type isEqualToString:@"strikethrough"]) {
[attributedString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleThick) range:range];
} else if ([type isEqualToString:@"color"]) {
NSString *color = [attribute string:KeyTextColor];
if (color) {
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor mfGetColorForHex:color] range:range];
}
} else if ([type isEqualToString:@"font"]) {
NSString *fontName = [attribute string:@"name"];
NSNumber *fontSize = [attribute optionalNumberForKey:@"size"];
UIFont *font = nil;
if (fontName) {
font = [MFFonts mfFontWithName:fontName size:fontSize ? fontSize.doubleValue : label.font.pointSize];
} else if (fontSize) {
font = [label.font fontWithSize:fontSize.doubleValue];
}
if (font) {
[attributedString addAttribute:NSFontAttributeName value:font range:range];
}
}
}
}
label.attributedText = attributedString;
}
}
}
- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
[MFLabel setUILabel:self withJSON:json delegateObject:delegateObject additionalData:additionalData];
self.originalAttributedString = self.attributedText;
}
- (void)styleH1:(BOOL)scale {
[MFStyler styleLabelH1:self genericScaling:NO];
[self setScale:scale];
}
- (void)styleH2:(BOOL)scale {
[MFStyler styleLabelH2:self genericScaling:NO];
[self setScale:scale];
}
- (void)styleH3:(BOOL)scale {
[MFStyler styleLabelH3:self genericScaling:NO];
[self setScale:scale];
}
- (void)styleH32:(BOOL)scale {
[MFStyler styleLabelH32:self genericScaling:NO];
[self setScale:scale];
}
- (void)styleB1:(BOOL)scale {
[MFStyler styleLabelB1:self genericScaling:NO];
[self setScale:scale];
}
- (void)styleB2:(BOOL)scale {
[MFStyler styleLabelB2:self genericScaling:NO];
[self setScale:scale];
}
- (void)styleB3:(BOOL)scale {
[MFStyler styleLabelB3:self genericScaling:NO];
[self setScale:scale];
}
- (void)styleB20:(BOOL)scale {
[MFStyler styleLabelB20:self genericScaling:NO];
[self setScale:scale];
}
- (void)setAccessibilityTraits:(UIAccessibilityTraits)accessibilityTraits {
if (accessibilityTraits& UIAccessibilityTraitHeader) {
UIAccessibilityTraits noHeaderTraits = accessibilityTraits - UIAccessibilityTraitHeader;
[super setAccessibilityTraits:noHeaderTraits];
} else {
[super setAccessibilityTraits:accessibilityTraits];
}
}
@end