diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 964bedfc..856b15bb 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -9,8 +9,8 @@ /* Begin PBXBuildFile section */ 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; }; 01DF567021FA5AB300CC099B /* MVMCoreUITextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* MVMCoreUITextFieldListFormViewController.swift */; }; - D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.m */; }; + D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationController.m */; }; D22D1F1A220341F60077CEC0 /* MVMCoreUICheckBox.h in Headers */ = {isa = PBXBuildFile; fileRef = D22D1F18220341F50077CEC0 /* MVMCoreUICheckBox.h */; settings = {ATTRIBUTES = (Public, ); }; }; D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */ = {isa = PBXBuildFile; fileRef = D22D1F19220341F50077CEC0 /* MVMCoreUICheckBox.m */; }; D22D1F1E220343560077CEC0 /* MVMCoreUICheckMarkView.h in Headers */ = {isa = PBXBuildFile; fileRef = D22D1F1C220343560077CEC0 /* MVMCoreUICheckMarkView.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -164,8 +164,8 @@ /* Begin PBXFileReference section */ 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = ""; }; 01DF566F21FA5AB300CC099B /* MVMCoreUITextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MVMCoreUITextFieldListFormViewController.swift; sourceTree = ""; }; - D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationControllerViewController.h; sourceTree = ""; }; - D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUINavigationControllerViewController.m; sourceTree = ""; }; + D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = ""; }; + D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUINavigationController.m; sourceTree = ""; }; D22D1F18220341F50077CEC0 /* MVMCoreUICheckBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUICheckBox.h; sourceTree = ""; }; D22D1F19220341F50077CEC0 /* MVMCoreUICheckBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUICheckBox.m; sourceTree = ""; }; D22D1F1C220343560077CEC0 /* MVMCoreUICheckMarkView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUICheckMarkView.h; sourceTree = ""; }; @@ -464,8 +464,8 @@ children = ( D29DF2B721E7BE79003B2FB9 /* TabBarController */, D29DF2B621E7BE66003B2FB9 /* SplitViewController */, - D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.h */, - D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.m */, + D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */, + D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationController.m */, ); path = Containers; sourceTree = ""; @@ -704,7 +704,7 @@ D29DF26421E6A9D9003B2FB9 /* MFTransparentGIFView.h in Headers */, D29DF27921E7A533003B2FB9 /* MVMCoreUISession.h in Headers */, D29DF25C21E6A2B6003B2FB9 /* DashLine.h in Headers */, - D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.h in Headers */, + D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationController.h in Headers */, D29DF29D21E7AE38003B2FB9 /* MFStyler.h in Headers */, D29DF2B021E7B3A4003B2FB9 /* MFTextView.h in Headers */, D29DF2A921E7B2F9003B2FB9 /* MVMCoreUIConstants.h in Headers */, @@ -889,7 +889,7 @@ D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */, D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, D29DF28A21E7AC2B003B2FB9 /* MFLabel.m in Sources */, - D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationControllerViewController.m in Sources */, + D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationController.m in Sources */, D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */, 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */, D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m index 3e44f2bd..5300d774 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m @@ -8,6 +8,7 @@ #import "PrimaryButton.h" #import +#import #import "MVMCoreUISplitViewController.h" #import "MFStyler.h" #import "UIColor+MFConvenience.h" @@ -566,7 +567,7 @@ self.primaryButtonType = PrimaryButtonTypeCustom; NSString *color = [json string:@"fillColor"]; self.fillColor = (color ? [UIColor mfGetColorForHex:color] : nil); - color = [json string:@"textColor"]; + color = [json string:KeyTextColor]; self.textColor = (color ? [UIColor mfGetColorForHex:color] : nil); color = [json string:@"borderColor"]; self.borderColor = (color ? [UIColor mfGetColorForHex:color] : nil); diff --git a/MVMCoreUI/Atoms/Views/MFLabel.h b/MVMCoreUI/Atoms/Views/MFLabel.h index a7386425..a9c11358 100644 --- a/MVMCoreUI/Atoms/Views/MFLabel.h +++ b/MVMCoreUI/Atoms/Views/MFLabel.h @@ -10,7 +10,7 @@ #import @class MFSizeObject; -@interface MFLabel : UILabel +@interface MFLabel : UILabel - (nullable instancetype)initWithStandardFontSize:(CGFloat)size; @@ -23,6 +23,9 @@ // 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 + (nonnull MFLabel *)commonLabelB2:(BOOL)scale; diff --git a/MVMCoreUI/Atoms/Views/MFLabel.m b/MVMCoreUI/Atoms/Views/MFLabel.m index 39aeb851..17551385 100644 --- a/MVMCoreUI/Atoms/Views/MFLabel.m +++ b/MVMCoreUI/Atoms/Views/MFLabel.m @@ -7,23 +7,60 @@ // #import "MFLabel.h" -#import "MFStyler.h" +#import #import +#import #import "UIColor+MFConvenience.h" #import "MFFonts.h" #import "MVMCoreUISplitViewController.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 -- (instancetype)initWithStandardFontSize:(CGFloat)size { +- (void)setupView { + self.backgroundColor = [UIColor clearColor]; + self.numberOfLines = 0; + self.lineBreakMode = NSLineBreakByWordWrapping; + self.translatesAutoresizingMaskIntoConstraints = NO; + [self styleB2:YES]; +} + +- (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; @@ -31,7 +68,16 @@ - (void)updateView:(CGFloat)size { self.scaleSize = @(size); - if (!fequal(self.standardFontSize, 0)) { + 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]; @@ -56,13 +102,12 @@ #pragma mark - Getters +- (BOOL)hasText { + return self.text.length > 0 || self.attributedText.length > 0; +} + + (nonnull MFLabel *)label { - MFLabel *label = [[MFLabel alloc] initWithFrame:CGRectZero]; - label.backgroundColor = [UIColor clearColor]; - label.numberOfLines = 0; - label.lineBreakMode = NSLineBreakByWordWrapping; - label.translatesAutoresizingMaskIntoConstraints = NO; - return label; + return [[MFLabel alloc] initWithFrame:CGRectZero]; } + (nonnull MFLabel *)commonLabelB2:(BOOL)scale { @@ -193,6 +238,72 @@ #pragma mark - Setters ++ (void)setUILabel:(nullable UILabel *)label withJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { + if (label) { + label.text = [json string:KeyText]; + 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 delegate:(NSObject *)delegate additionalData:(NSDictionary *)additionalData { + [MFLabel setUILabel:self withJSON:json delegate:delegate additionalData:additionalData]; + self.originalAttributedString = self.attributedText; +} + - (void)styleB2:(BOOL)scale { [MFStyler styleLabelB2:self genericScaling:NO]; [self setScale:scale]; diff --git a/MVMCoreUI/Atoms/Views/SeparatorView.m b/MVMCoreUI/Atoms/Views/SeparatorView.m index 98e61f33..73cd84ff 100644 --- a/MVMCoreUI/Atoms/Views/SeparatorView.m +++ b/MVMCoreUI/Atoms/Views/SeparatorView.m @@ -8,8 +8,11 @@ #import "SeparatorView.h" #import +#import #import "MVMCoreUICommonViewsUtility.h" #import "UIColor+MFConvenience.h" +@import MVMCore.MVMCoreJSONConstants; +@import MVMCore.NSDictionary_MFConvenience; @interface SeparatorView() @@ -17,9 +20,6 @@ @implementation SeparatorView - - - #pragma mark - class methods + (nullable SeparatorView *)separatorAddToView:(nullable UIView *)superView position:(SeparatorPosition)position positionPadding:(CGFloat)positionPadding withHorizontalPadding:(CGFloat)padding { @@ -95,6 +95,27 @@ } } +- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(NSDictionary *)additionalData { + [super setWithJSON:json delegate:delegate additionalData:additionalData]; + if (json) { + self.hidden = NO; + NSString *type = [json string:KeyType]; + if ([type isEqualToString:@"standard"]) { + [self setSize:1]; + } else if ([type isEqualToString:@"medium"]) { + [self setSize:2]; + } else if ([type isEqualToString:@"heavy"]) { + [self setSize:4]; + } + NSString *backgroundColor = [json string:KeyBackgroundColor]; + if (backgroundColor) { + self.backgroundColor = [UIColor mfGetColorForHex:backgroundColor]; + } + } else { + self.hidden = YES; + } +} + #pragma mark - helper - (void)hide { @@ -104,37 +125,37 @@ self.hidden = NO; } -- (void)setAsHeavy { - self.heightSizeObject.standardSize = 4; +- (void)setSize:(CGFloat)size { + self.heightSizeObject.standardSize = size; self.height.constant = [self.heightSizeObject getValueBasedOnScreenSize]; +} + +- (void)setAsHeavy { + [self setSize:4]; self.backgroundColor = [UIColor blackColor]; [self setNeedsLayout]; [self layoutIfNeeded]; } - (void)setAsRegular { - self.heightSizeObject.standardSize = 1; - self.height.constant = [self.heightSizeObject getValueBasedOnScreenSize]; + [self setSize:1]; self.backgroundColor = [UIColor blackColor]; [self setNeedsLayout]; [self layoutIfNeeded]; } - (void)setAsLight { - self.heightSizeObject.standardSize = 1; - self.height.constant = [self.heightSizeObject getValueBasedOnScreenSize]; + [self setSize:1]; self.backgroundColor = [UIColor mfSilver]; [self setNeedsLayout]; [self layoutIfNeeded]; } - (void)setAsMedium { - self.heightSizeObject.standardSize = 2; - self.height.constant = [self.heightSizeObject getValueBasedOnScreenSize]; + [self setSize:2]; self.backgroundColor = [UIColor blackColor]; [self setNeedsLayout]; [self layoutIfNeeded]; } - @end diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index cd245630..6bcd4984 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -35,7 +35,7 @@ #import "MVMCoreUISession.h" #import "MVMCoreUILoggingHandler.h" #import "MVMCoreUITabBarPageControlViewController.h" -#import "MVMCoreUINavigationControllerViewController.h" +#import "MVMCoreUINavigationController.h" @import MVMAnimationFramework; @interface MFViewController () diff --git a/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.h b/MVMCoreUI/Containers/MVMCoreUINavigationController.h similarity index 86% rename from MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.h rename to MVMCoreUI/Containers/MVMCoreUINavigationController.h index 2fe06d1e..abe6efa7 100644 --- a/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.h +++ b/MVMCoreUI/Containers/MVMCoreUINavigationController.h @@ -1,5 +1,5 @@ // -// MVMCoreUINavigationControllerViewController.h +// MVMCoreUINavigationController.h // MVMCoreUI // // Created by Scott Pfeil on 1/25/19. @@ -10,7 +10,7 @@ @class SeparatorView; NS_ASSUME_NONNULL_BEGIN -@interface MVMCoreUINavigationControllerViewController : UINavigationController +@interface MVMCoreUINavigationController : UINavigationController // Convenience getter + (nullable instancetype)navigationController; diff --git a/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.m b/MVMCoreUI/Containers/MVMCoreUINavigationController.m similarity index 81% rename from MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.m rename to MVMCoreUI/Containers/MVMCoreUINavigationController.m index f0143315..bbfe856e 100644 --- a/MVMCoreUI/Containers/MVMCoreUINavigationControllerViewController.m +++ b/MVMCoreUI/Containers/MVMCoreUINavigationController.m @@ -1,12 +1,12 @@ // -// MVMCoreUINavigationControllerViewController.m +// MVMCoreUINavigationController.m // MVMCoreUI // // Created by Scott Pfeil on 1/25/19. // Copyright © 2019 Verizon Wireless. All rights reserved. // -#import "MVMCoreUINavigationControllerViewController.h" +#import "MVMCoreUINavigationController.h" #import "UIColor+MFConvenience.h" #import "SeparatorView.h" #import "MFFonts.h" @@ -14,18 +14,18 @@ #import "MVMCoreUISession.h" @import MVMCore.MVMCoreActionUtility; @import MVMCore.MVMCoreNavigationHandler; -@interface MVMCoreUINavigationControllerViewController () +@interface MVMCoreUINavigationController () @end -@implementation MVMCoreUINavigationControllerViewController +@implementation MVMCoreUINavigationController + (nullable instancetype)navigationController { return [MVMCoreActionUtility initializerClassCheck:[MVMCoreUISession sharedGlobal].navigationController classToVerify:self]; } + (nullable instancetype)setupNavigationController { - MVMCoreUINavigationControllerViewController *navigationController = [[MVMCoreUINavigationControllerViewController alloc] init]; + MVMCoreUINavigationController *navigationController = [[MVMCoreUINavigationController alloc] init]; [UIColor mfSetBackgroundColorForNavigationBar:[UIColor whiteColor] navigationBar:navigationController.navigationBar transparent:NO]; [navigationController.navigationBar setShadowImage:[[UIImage alloc] init]]; navigationController.navigationBar.translucent = NO; @@ -44,7 +44,7 @@ } + (nullable instancetype)setupWithNavigationControllerAsMainController { - MVMCoreUINavigationControllerViewController *navigationController = [self setupNavigationController]; + MVMCoreUINavigationController *navigationController = [self setupNavigationController]; [[MVMCoreUISession sharedGlobal] setupAsStandardLoadViewDelegate:navigationController]; return navigationController; } diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h index a5e5b6a9..432a674b 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.h @@ -12,7 +12,7 @@ #import #import -@class MVMCoreUINavigationControllerViewController; +@class MVMCoreUINavigationController; @class MVMCoreUITopAlertView; @class MFViewController; @@ -34,7 +34,7 @@ typedef NS_ENUM(NSInteger, MFNumberOfDrawers) { @property (nullable, strong, nonatomic) UIBarButtonItem *backButton; -@property (nullable, weak, nonatomic, readonly) MVMCoreUINavigationControllerViewController *navigationController; +@property (nullable, weak, nonatomic, readonly) MVMCoreUINavigationController *navigationController; // Reference to the top alert view @property (nullable, weak, nonatomic) MVMCoreUITopAlertView *topAlertView; diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index 7dfb97e0..d70bdb6e 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -23,7 +23,7 @@ #import "MVMCoreUIConstants.h" #import "MVMCoreUICommonViewsUtility.h" #import "MVMCoreUITopAlertView.h" -#import "MVMCoreUINavigationControllerViewController.h" +#import "MVMCoreUINavigationController.h" @interface MVMCoreUISplitViewController () @@ -40,7 +40,7 @@ @property (weak, nonatomic, readwrite) UIViewController *leftPanel; @property (weak, nonatomic, readwrite) UIViewController *rightPanel; -@property (weak, nonatomic, readwrite) MVMCoreUINavigationControllerViewController *navigationController; +@property (weak, nonatomic, readwrite) MVMCoreUINavigationController *navigationController; // A view that covers the detail view when the master is out. @property (weak, nonatomic) IBOutlet UIView *mainViewCoverView; @@ -694,7 +694,7 @@ CGFloat const PanelAnimationDuration = 0.2; } // The main view. - MVMCoreUINavigationControllerViewController *navigationController = [MVMCoreUINavigationControllerViewController setupNavigationController]; + MVMCoreUINavigationController *navigationController = [MVMCoreUINavigationController setupNavigationController]; self.navigationController = navigationController; self.automaticallyAdjustsScrollViewInsets = NO; diff --git a/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m b/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m index ad80eb3e..489a4696 100644 --- a/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m +++ b/MVMCoreUI/Containers/TabBarController/MVMCoreUITabBarPageControlViewController.m @@ -164,7 +164,7 @@ // If we are not loading from the cache, check if the server has provided an index to start with. (When loading from the cache, we use the requested pagetype and modules to find the tab) __block NSInteger currentIndex = NSNotFound; if (!self.loadObject.pageDataFromCache) { - NSNumber *currentIndexNumber = [self.loadObject.pageJSON objectForKey:@"currentTabIndex" ofType:[NSNumber class]]; + NSNumber *currentIndexNumber = [self.loadObject.pageJSON optionalNumberForKey:@"currentTabIndex"]; if (currentIndexNumber) { currentIndex = [currentIndexNumber integerValue]; } diff --git a/MVMCoreUI/MVMCoreUI.h b/MVMCoreUI/MVMCoreUI.h index 9fa02348..f1fdd0b9 100644 --- a/MVMCoreUI/MVMCoreUI.h +++ b/MVMCoreUI/MVMCoreUI.h @@ -56,7 +56,7 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[]; #import #pragma mark - Containers -#import +#import #import #import diff --git a/MVMCoreUI/Molecules/MVMCoreUIHeaderView.swift b/MVMCoreUI/Molecules/MVMCoreUIHeaderView.swift index 82babc58..a1a0ffba 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIHeaderView.swift +++ b/MVMCoreUI/Molecules/MVMCoreUIHeaderView.swift @@ -24,6 +24,7 @@ public class MVMCoreUIHeaderView: ViewConstrainingView { headlineLabel.updateView(size) messageLabel.updateView(size) separatorView?.updateView(size) + setSpacing() } public override func setupView() { @@ -74,6 +75,30 @@ public class MVMCoreUIHeaderView: ViewConstrainingView { } } + public func setSpacing() { + if headlineLabel.hasText() && messageLabel.hasText() { + spaceBetweenLabels?.constant = PaddingTwo + show() + } else if headlineLabel.hasText() || messageLabel.hasText() { + spaceBetweenLabels?.constant = 0 + show() + } else { + hide() + } + } + + public override func show() { + super.show() + heightConstraint?.isActive = false + layoutIfNeeded() + } + + public override func hide() { + super.hide() + heightConstraint?.isActive = true + layoutIfNeeded() + } + public override func setLeftPinConstant(_ constant: CGFloat) { leftConstraintTitle?.constant = constant leftConstraintMessage?.constant = constant @@ -88,10 +113,7 @@ public class MVMCoreUIHeaderView: ViewConstrainingView { public override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) { super.setWithJSON(json, delegate: delegate, additionalData: additionalData) - headlineLabel.text = json?.optionalStringForKey(KeyTitle) - messageLabel.text = json?.optionalStringForKey(KeyMessage) - separatorView?.isHidden = !(json?.boolForKey("showSeparator") ?? false) - if let colorString = json?.optionalStringForKey("backgroundColor") { + if let colorString = json?.optionalStringForKey(KeyBackgroundColor) { backgroundColor = .mfGet(forHex: colorString) } if let colorString = json?.optionalStringForKey("contentColor") { @@ -101,6 +123,13 @@ public class MVMCoreUIHeaderView: ViewConstrainingView { separatorView?.backgroundColor = color } + let headlineJSON = json?.optionalDictionaryForKey("headline") + headlineLabel.setWithJSON(headlineJSON, delegate: delegate, additionalData: additionalData) + let bodyJSON = json?.optionalDictionaryForKey("body") + messageLabel.setWithJSON(bodyJSON, delegate: delegate, additionalData: additionalData) + let separatorJSON = json?.optionalDictionaryForKey("separator") + separatorView?.setWithJSON(separatorJSON, delegate: delegate, additionalData: additionalData) + if separatorView?.isHidden ?? true { bottomPin?.constant = 0 } else { diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeStackView.swift b/MVMCoreUI/Molecules/MVMCoreUIMoleculeStackView.swift index af336673..e8f6cc26 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIMoleculeStackView.swift +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeStackView.swift @@ -12,6 +12,10 @@ public class MVMCoreUIMoleculeStackView: MFView { var spacingBlock: ((Any) -> UIEdgeInsets)? var moleculesArray: [UIView]? + public override init(frame: CGRect) { + super.init(frame: frame) + } + init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) { super.init(frame: CGRect.zero) setWithJSON(json, delegate: delegate, additionalData: additionalData) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUISession.h b/MVMCoreUI/OtherHandlers/MVMCoreUISession.h index 72e7728e..a5ce493c 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUISession.h +++ b/MVMCoreUI/OtherHandlers/MVMCoreUISession.h @@ -11,7 +11,7 @@ @class MVMCoreUITopAlertView; @class MVMCoreUISplitViewController; @class MFViewController; -@class MVMCoreUINavigationControllerViewController; +@class MVMCoreUINavigationController; @class MFLoadingViewController; NS_ASSUME_NONNULL_BEGIN @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN @property (weak, nonatomic, nullable) MVMCoreUITopAlertView *topAlertView; @property (weak, nonatomic, nullable) MVMCoreUISplitViewController *splitViewController; -@property (weak, nonatomic, nullable) MVMCoreUINavigationControllerViewController *navigationController; +@property (weak, nonatomic, nullable) MVMCoreUINavigationController *navigationController; @property (weak, nonatomic, nullable) MFLoadingViewController *loadingViewController; // for handscroll Animation on subclasses of MFScrollingViewController diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index a5c07695..b2349d70 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -11,7 +11,7 @@ import UIKit public class MoleculeStackTemplate: ThreeLayerViewController { - public override func spaceBetweenMiddleAndBottom() -> CGFloat? { + public override func spaceBetweenTopAndMiddle() -> CGFloat? { return PaddingTwo } diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m index 01870572..d05132f4 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertMainView.m @@ -193,6 +193,7 @@ PrimaryButton *button = [PrimaryButton primaryWhiteButton:YES]; button.bordered = YES; [button setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal]; + [button setContentHuggingPriority:800 forAxis:UILayoutConstraintAxisHorizontal]; button.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:button]; diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h index 05943ee8..46d56cb6 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.h @@ -31,6 +31,9 @@ // Returns the top alert view + (nullable instancetype)sharedGlobal; +// Returns a TopAlertView with the mvm styling. Also sets the property in the session. ++ (nullable instancetype)setupTopAlertView; + // Pins the status bar view at the top of the passed in view controller. - (void)pinATopViewController:(nonnull UIViewController *)viewController; diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m index 88d73cbd..735f28d9 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m @@ -54,6 +54,13 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; return [MVMCoreUISession sharedGlobal].topAlertView; } ++ (nullable instancetype)setupTopAlertView { + MVMCoreUITopAlertView *topAlertView = [[self alloc] init]; + topAlertView.translatesAutoresizingMaskIntoConstraints = NO; + [MVMCoreUISession sharedGlobal].topAlertView = topAlertView; + return topAlertView; +} + - (void)setupView { [super setupView]; if (!self.statusBarView) { diff --git a/MVMCoreUI/Utility/MFFonts.h b/MVMCoreUI/Utility/MFFonts.h index 01e2c427..484e2c82 100644 --- a/MVMCoreUI/Utility/MFFonts.h +++ b/MVMCoreUI/Utility/MFFonts.h @@ -15,5 +15,6 @@ + (nullable UIFont *)mfFont75Bd:(CGFloat)size; + (nullable UIFont *)mfFont55Rg:(CGFloat)size; + (nullable UIFont *)mfFontOcratxt:(CGFloat)size; ++ (nullable UIFont *)mfFontWithName:(nonnull NSString *)name size:(CGFloat)size; @end diff --git a/MVMCoreUI/Utility/MFFonts.m b/MVMCoreUI/Utility/MFFonts.m index 5948a527..65326e6c 100644 --- a/MVMCoreUI/Utility/MFFonts.m +++ b/MVMCoreUI/Utility/MFFonts.m @@ -13,6 +13,15 @@ @implementation MFFonts ++ (void)loadMVMFonts { + static dispatch_once_t once; + dispatch_once(&once, ^{ + [MFFonts loadFont:@"NHaasGroteskDSStd-75Bd" type:@"otf"]; + [MFFonts loadFont:@"NHaasGroteskDSStd-55Rg" type:@"otf"]; + [MFFonts loadFont:@"OCRAExtended" type:@"ttf"]; + }); +} + + (void)loadFont:(NSString *)fontName type:(NSString *)type{ NSString *fontPath = [[MVMCoreUIUtility bundleForMVMCoreUI] pathForResource:fontName ofType:type]; @@ -31,30 +40,22 @@ } + (nullable UIFont *)mfFont75Bd:(CGFloat)size { - NSString *fontName = @"NHaasGroteskDSStd-75Bd"; - static dispatch_once_t once; - dispatch_once(&once, ^{ - [MFFonts loadFont:fontName type:@"otf"]; - }); - return [UIFont fontWithName:fontName size:size]; + [self loadMVMFonts]; + return [UIFont fontWithName:@"NHaasGroteskDSStd-75Bd" size:size]; } + (nullable UIFont *)mfFont55Rg:(CGFloat)size { - NSString *fontName = @"NHaasGroteskDSStd-55Rg"; - static dispatch_once_t once; - dispatch_once(&once, ^{ - [MFFonts loadFont:fontName type:@"otf"]; - }); - return [UIFont fontWithName:fontName size:size]; + [self loadMVMFonts]; + return [UIFont fontWithName:@"NHaasGroteskDSStd-55Rg" size:size]; } + (nullable UIFont *)mfFontOcratxt:(CGFloat)size { - NSString *fontName = @"OCRAExtended"; - static dispatch_once_t once; - dispatch_once(&once, ^{ - [MFFonts loadFont:fontName type:@"ttf"]; - }); - return [UIFont fontWithName:fontName size:size]; + [self loadMVMFonts]; + return [UIFont fontWithName:@"OCRAExtended" size:size]; +} + ++ (nullable UIFont *)mfFontWithName:(nonnull NSString *)name size:(CGFloat)size { + return [UIFont fontWithName:name size:size] ?: [self mfFont55Rg:size]; } @end diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 2b7b625d..40f0e2ac 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -28,6 +28,10 @@ extern NSString * const KeySecondaryButton; extern NSString * const KeyTitlePrefix; extern NSString * const KeyTitlePostfix; +extern NSString * const KeyBackgroundColor; +extern NSString * const KeyText; +extern NSString * const KeyTextColor; + #pragma mark - Values extern NSString * const StringY; diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 6a0bb090..0bf34449 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -27,6 +27,10 @@ NSString * const KeySecondaryButton = @"SecondaryButton"; NSString * const KeyTitlePrefix = @"titlePrefix"; NSString * const KeyTitlePostfix = @"titlePostfix"; +NSString * const KeyBackgroundColor = @"backgroundColor"; +NSString * const KeyText = @"text"; +NSString * const KeyTextColor = @"textColor"; + #pragma mark - Values NSString * const StringY = @"Y";