From 4fb8e05498be74323d9dd0b4d442dc655f9b2323 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Apr 2020 15:44:45 -0400 Subject: [PATCH] now --- MVMCoreUI/BaseClasses/TextView.swift | 40 ++++++++++++----------- MVMCoreUI/BaseClasses/TextViewModel.swift | 11 ++++--- MVMCoreUI/Styles/MFStyler.h | 1 - MVMCoreUI/Styles/MFStyler.m | 22 ------------- MVMCoreUI/Styles/Styler.swift | 2 +- 5 files changed, 29 insertions(+), 47 deletions(-) diff --git a/MVMCoreUI/BaseClasses/TextView.swift b/MVMCoreUI/BaseClasses/TextView.swift index 735abfaf..b0076c09 100644 --- a/MVMCoreUI/BaseClasses/TextView.swift +++ b/MVMCoreUI/BaseClasses/TextView.swift @@ -26,8 +26,10 @@ import UIKit /// Set to true to hide the blinking textField cursor. public var hideBlinkingCaret = false - private var textTraits: (color: UIColor, font: UIFont) = (color: .mvmBlack, font: MFStyler.fontRegularBodySmall()) - private var placeholderTraits: (text: String, color: UIColor, font: UIFont) = (text: "", color: .mvmCoolGray3, font: MFStyler.fontRegularMicro() ) + private var textTraits: (color: UIColor, font: UIFont) = (color: .mvmBlack, + font: Styler.Font.RegularBodySmall.getFont()) + private var placeholderTraits: (text: String, color: UIColor, font: UIFont) = (text: "", + color: .mvmCoolGray3, font: Styler.Font.RegularMicro.getFont()) //-------------------------------------------------- // MARK: - Delegate @@ -201,9 +203,9 @@ extension TextView: MoleculeViewProtocol { textColor = model.textColor.uiColor layer.borderColor = model.borderColor?.cgColor layer.borderWidth = model.borderWidth -// placeholderFont = model.placeholderFont text = model.text isShowingPlaceholder = model.text.isEmpty + placeholderTraits.font = model.placeholderFont.getFont() placeholderTraits.text = model.placeholder uiTextViewDelegate = delegateObject?.uiTextViewDelegate @@ -211,22 +213,22 @@ extension TextView: MoleculeViewProtocol { accessibilityLabel = accessibilityText } - if let fontStyle = model.fontStyle?.rawValue { - MFStyler.styleTextView(self, withStyle: fontStyle, genericScaling: false) - standardFontSize = font?.pointSize ?? 0 - if let font = font { - textTraits.font = font - } - } else { - let fontSize = model.fontSize - if let fontSize = fontSize { - standardFontSize = fontSize - } - if let fontName = model.fontName { - font = MFFonts.mfFont(withName: fontName, size: fontSize ?? standardFontSize) - } else if let fontSize = fontSize { - font = font?.updateSize(fontSize) - } + font = model.fontStyle.getFont() + standardFontSize = model.fontStyle.pointSize() + if let font = font { + textTraits.font = font + } + + let fontSize = model.fontSize + if let fontSize = fontSize { + standardFontSize = fontSize + } + if let fontName = model.fontName { + font = Styler.Font(rawValue: fontName)?.getFont() + textTraits.font = font! + } else if let fontSize = fontSize { + font = font?.updateSize(fontSize) + textTraits.font = font! } if isEditable { diff --git a/MVMCoreUI/BaseClasses/TextViewModel.swift b/MVMCoreUI/BaseClasses/TextViewModel.swift index a4660b54..7cff3119 100644 --- a/MVMCoreUI/BaseClasses/TextViewModel.swift +++ b/MVMCoreUI/BaseClasses/TextViewModel.swift @@ -21,11 +21,11 @@ open class TextViewModel: MoleculeModelProtocol { public var textColor: Color = Color(uiColor: .mvmBlack) public var fontSize: CGFloat? public var fontName: String? - public var fontStyle: LabelModel.FontStyle? + public var fontStyle: Styler.Font = Styler.Font.RegularBodySmall public var textAlignment: NSTextAlignment = .left public var height: CGFloat? public var placeholder: String = "" - public var placeholderFont: LabelModel.FontStyle = LabelModel.FontStyle.RegularMicro + public var placeholderFont: Styler.Font = Styler.Font.RegularMicro public var isEditable: Bool = true public var borderColor: Color? public var borderWidth: CGFloat = 0 @@ -77,7 +77,7 @@ open class TextViewModel: MoleculeModelProtocol { self.placeholder = placeholder } - if let placeholderFont = try typeContainer.decodeIfPresent(LabelModel.FontStyle.self, forKey: .placeholderFont) { + if let placeholderFont = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .placeholderFont) { self.placeholderFont = placeholderFont } @@ -97,12 +97,15 @@ open class TextViewModel: MoleculeModelProtocol { self.borderWidth = borderWidth } + if let fontStyle = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .fontStyle) { + self.fontStyle = fontStyle + } + borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize) fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName) - fontStyle = try typeContainer.decodeIfPresent(LabelModel.FontStyle.self, forKey: .fontStyle) height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) } diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index a1e49927..6accea28 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -294,7 +294,6 @@ B3 -> Legal /// Will style the label based on the string. Accepted values, including mva3.0 fonts and 2.0 fonts H1, H2, H3, H32, B1, B2, B3, B20 + (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style; + (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling; -+ (void)styleTextView:(nonnull UITextView *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling; + (void)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling; + (void)styleLabelH1:(nonnull UILabel *)label; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index 2805d4ee..213c205e 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -853,28 +853,6 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } } -+ (void)styleTextView:(nonnull UITextView *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling { - if ([self styleMVA3Label:label withStyle:style genericScaling:genericScaling]) { - //try mva 3.0 font first - } else if ([style isEqualToString:@"H1"]) { - [self styleLabelH1:label genericScaling:genericScaling]; - } else if ([style isEqualToString:@"H2"]) { - [self styleLabelH2:label genericScaling:genericScaling]; - } else if ([style isEqualToString:@"H3"]) { - [self styleLabelH3:label genericScaling:genericScaling]; - } else if ([style isEqualToString:@"H32"]) { - [self styleLabelH32:label genericScaling:genericScaling]; - } else if ([style isEqualToString:@"B1"]) { - [self styleLabelB1:label genericScaling:genericScaling]; - } else if ([style isEqualToString:@"B3"]) { - [self styleLabelB3:label genericScaling:genericScaling]; - } else if ([style isEqualToString:@"B20"]) { - [self styleLabelB20:label genericScaling:genericScaling]; - } else { - [self styleLabelB2:label genericScaling:genericScaling]; - } -} - + (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style { [self styleLabel:label withStyle:style genericScaling:YES]; } diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index b5d6627c..849395b1 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -144,7 +144,7 @@ open class Styler { } /// Returns the font based on the declared enum case. - public func getFont(_ genericScaling: Bool = true) -> UIFont? { + public func getFont(_ genericScaling: Bool = true) -> UIFont { let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize()