From d0f073636038f49c2f8098f7fa052eb8ceb3fe55 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 25 Jan 2019 12:56:29 -0500 Subject: [PATCH] attempt to standardize json for top labels --- MVMCoreUI/Atoms/Views/MFLabel.h | 3 ++ MVMCoreUI/Atoms/Views/MFLabel.m | 5 ++++ ...abelsAndBottomButtonsTableViewController.m | 23 +++------------ .../TopLabelsAndBottomButtonsViewController.m | 6 +--- MVMCoreUI/Molecules/TopLabelsView.h | 3 ++ MVMCoreUI/Molecules/TopLabelsView.m | 29 +++++++++++++++++-- .../MVMCoreUILargeHeaderSingleLabelTemplate.h | 14 ++++++++- .../MVMCoreUILargeHeaderSingleLabelTemplate.m | 20 +------------ 8 files changed, 57 insertions(+), 46 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MFLabel.h b/MVMCoreUI/Atoms/Views/MFLabel.h index 1284137b..a7386425 100644 --- a/MVMCoreUI/Atoms/Views/MFLabel.h +++ b/MVMCoreUI/Atoms/Views/MFLabel.h @@ -74,4 +74,7 @@ - (void)styleB1:(BOOL)scale; - (void)styleTableRow:(BOOL)scale; +// Without color +- (void)setFontH1:(BOOL)scale; + @end diff --git a/MVMCoreUI/Atoms/Views/MFLabel.m b/MVMCoreUI/Atoms/Views/MFLabel.m index 9167884e..39aeb851 100644 --- a/MVMCoreUI/Atoms/Views/MFLabel.m +++ b/MVMCoreUI/Atoms/Views/MFLabel.m @@ -308,6 +308,11 @@ [self setScale:scale]; } +- (void)setFontH1:(BOOL)scale { + self.font = [MFStyler fontH1:NO]; + [self setScale:scale]; +} + - (void)setAccessibilityTraits:(UIAccessibilityTraits)accessibilityTraits { if (accessibilityTraits& UIAccessibilityTraitHeader) { diff --git a/MVMCoreUI/BaseControllers/TopLabelsAndBottomButtonsTableViewController.m b/MVMCoreUI/BaseControllers/TopLabelsAndBottomButtonsTableViewController.m index 2711aae9..ed6d242d 100644 --- a/MVMCoreUI/BaseControllers/TopLabelsAndBottomButtonsTableViewController.m +++ b/MVMCoreUI/BaseControllers/TopLabelsAndBottomButtonsTableViewController.m @@ -37,19 +37,6 @@ @implementation TopLabelsAndBottomButtonsTableViewController -- (void)backButtonPressed { - [super backButtonPressed]; - - //[self tryToCleanUpMemory]; -} - -- (void)tryToCleanUpMemory { - //[self.footerView removeFromSuperview]; - //self.footerView = nil; - //self.footerAccessoryView = nil; - //self.bottomView = nil; -} - - (void)initialLoad { [super initialLoad]; self.rebuildUIOnSizeChange = YES; @@ -156,9 +143,11 @@ [self.tableView reloadData]; } --(void)setHeadlineAndMessage { - [self.topLabelsView setHeadlineString:[[self mapForTopLabels] stringForKey:KeyTitle] messageString:[[self mapForTopLabels] stringForKey:KeyMessage]]; + +- (void)setHeadlineAndMessage { + [self.topLabelsView setWtihJSON:[self mapForTopLabels]]; } + - (void)updateViewConstraints { [super updateViewConstraints]; @@ -217,10 +206,6 @@ } } -- (void)viewDidLoad { - [super viewDidLoad]; -} - - (void)setUpHeaderAccessoryView { UIView *headerAccessoryView = [[UIView alloc] initWithFrame:CGRectZero]; headerAccessoryView.translatesAutoresizingMaskIntoConstraints = NO; diff --git a/MVMCoreUI/BaseControllers/TopLabelsAndBottomButtonsViewController.m b/MVMCoreUI/BaseControllers/TopLabelsAndBottomButtonsViewController.m index e29c26dc..66216dd2 100644 --- a/MVMCoreUI/BaseControllers/TopLabelsAndBottomButtonsViewController.m +++ b/MVMCoreUI/BaseControllers/TopLabelsAndBottomButtonsViewController.m @@ -113,6 +113,7 @@ self.topLabelsView = topLabelsView; topView = topLabelsView; self.topView = topView; + [topLabelsView setWtihJSON:[self mapForTopLabels]]; } [self.contentView addSubview:topView]; [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[topView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topView)]]; @@ -263,11 +264,6 @@ [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topBetweenEdgeView]-0-[spacer]-0-[bottomBetweenEdgeView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topBetweenEdgeView,spacer,bottomBetweenEdgeView)]]; } - - if (self.topLabelsView) { - [self.topLabelsView setHeadlineString:[[self mapForTopLabels] stringForKey:KeyTitle] messageString:[[self mapForTopLabels] stringForKey:KeyMessage]]; - } - } - (void)updateViewConstraints { diff --git a/MVMCoreUI/Molecules/TopLabelsView.h b/MVMCoreUI/Molecules/TopLabelsView.h index e4e6494a..3e2f8d2d 100644 --- a/MVMCoreUI/Molecules/TopLabelsView.h +++ b/MVMCoreUI/Molecules/TopLabelsView.h @@ -50,4 +50,7 @@ - (void)setLeftConstant:(CGFloat)leftConstant; - (void)setRightConstant:(CGFloat)rightConstant; +// Sets up the ui based on the json +- (void)setWtihJSON:(nullable NSDictionary *)json; + @end diff --git a/MVMCoreUI/Molecules/TopLabelsView.m b/MVMCoreUI/Molecules/TopLabelsView.m index 54275f75..ccd45caf 100644 --- a/MVMCoreUI/Molecules/TopLabelsView.m +++ b/MVMCoreUI/Molecules/TopLabelsView.m @@ -14,6 +14,7 @@ #import #import #import +#import @interface TopLabelsView () @@ -30,8 +31,6 @@ @implementation TopLabelsView - - - (nullable instancetype)initWithTableView:(nullable TopLabelsAndBottomButtonsTableViewController *)tableView { if (self = [super init]) { self.tableView = tableView; @@ -216,5 +215,31 @@ self.rightConstraintSeparator.constant = rightConstant; } +- (void)setWtihJSON:(nullable NSDictionary *)json { + [self setHeadlineString:[json stringForKey:KeyTitle] messageString:[json stringForKey:KeyMessage]]; + UIColor *textColor = [self colorForTopLabelsWithJSON:json]; + self.headlineLabel.textColor = textColor; + self.messageLabel.textColor = textColor; + self.backgroundColor = [self colorForBackgroundWithJSON:json]; + self.separatorView.hidden = ![json boolForKey:@"showBottomLine"]; +} + +- (nonnull UIColor *)colorForTopLabelsWithJSON:(nullable NSDictionary *)json { + NSString *titleColor = [json string:@"titleBgColor"]; + if (titleColor) { + return [UIColor mfGetColorForHex:titleColor]; + } else { + return [UIColor blackColor]; + } +} + +- (nonnull UIColor *)colorForBackgroundWithJSON:(nullable NSDictionary *)json { + NSString *color = [json string:@"backgroundColor"]; + if (color) { + return [UIColor mfGetColorForHex:color]; + } else { + return [UIColor clearColor]; + } +} @end diff --git a/MVMCoreUI/Templates/MVMCoreUILargeHeaderSingleLabelTemplate.h b/MVMCoreUI/Templates/MVMCoreUILargeHeaderSingleLabelTemplate.h index 75a7474e..a73dd8cc 100644 --- a/MVMCoreUI/Templates/MVMCoreUILargeHeaderSingleLabelTemplate.h +++ b/MVMCoreUI/Templates/MVMCoreUILargeHeaderSingleLabelTemplate.h @@ -8,10 +8,22 @@ #import #import - +@class LabelView; +@class LabelWithInternalButton; NS_ASSUME_NONNULL_BEGIN @interface MVMCoreUILargeHeaderSingleLabelTemplate : TopLabelsAndBottomButtonsViewController + +// A label that can go below the top labels. Can be a normal label or one with internal buttons. +@property (nullable, weak, nonatomic) LabelView *labelViewUnderTopLabels; +@property (nullable, weak, nonatomic) LabelWithInternalButton *labelUnderTopLabelsWithInternalButton; + +// Override to specifiy the label under top label. Default uses the value for key "description" in the page json. +- (nullable NSString *)stringForLabelUnderTopLabels; + +// Override to specifiy the label under top label with internal button. Default uses the value for key "Link" in the "ButtonMap" of the page json. +- (nullable NSDictionary *)actionMapForLabelUnderTopLabelsWithInternalButton; + @end NS_ASSUME_NONNULL_END diff --git a/MVMCoreUI/Templates/MVMCoreUILargeHeaderSingleLabelTemplate.m b/MVMCoreUI/Templates/MVMCoreUILargeHeaderSingleLabelTemplate.m index b11a8871..6f00dc6e 100644 --- a/MVMCoreUI/Templates/MVMCoreUILargeHeaderSingleLabelTemplate.m +++ b/MVMCoreUI/Templates/MVMCoreUILargeHeaderSingleLabelTemplate.m @@ -13,19 +13,13 @@ @interface MVMCoreUILargeHeaderSingleLabelTemplate () -// A label that can go below the top labels. Can be a normal label or one with internal buttons. -@property (nullable, weak, nonatomic) LabelView *labelViewUnderTopLabels; -@property (nullable, weak, nonatomic) LabelWithInternalButton *labelUnderTopLabelsWithInternalButton; - @end @implementation MVMCoreUILargeHeaderSingleLabelTemplate - (void)newDataBuildScreen { [super newDataBuildScreen]; - [self.topLabelsView.headlineLabel styleH1:YES]; - self.topLabelsView.separatorView.hidden = YES; - [self updateTopLabelsColor]; + [self.topLabelsView.headlineLabel setFontH1:YES]; } - (void)initialLoad { @@ -81,18 +75,6 @@ // Dispose of any resources that can be recreated. } -#pragma mark - Top labels style - -- (void)updateTopLabelsColor { - self.topLabelsView.headlineLabel.textColor = [UIColor blackColor]; - self.topLabelsView.messageLabel.textColor = [UIColor blackColor]; - NSString *titleColor = [[self mapForTopLabels] string:@"titleBgColor"]; - if (titleColor) { - self.topLabelsView.headlineLabel.textColor = [UIColor mfGetColorForHex:titleColor]; - self.topLabelsView.messageLabel.textColor = [UIColor mfGetColorForHex:titleColor]; - } -} - - (UIEdgeInsets)paddingForTopLabels { UIEdgeInsets edge = [super paddingForTopLabels]; edge.bottom = PaddingTwo;