including 2.0 legacy as it's being used in some molecular at the moment.

This commit is contained in:
Kevin G Christiano 2020-04-02 17:16:04 -04:00
parent 8788d98323
commit c9bb3ce1f3
3 changed files with 90 additions and 47 deletions

View File

@ -18,7 +18,7 @@ import UIKit
return "font" return "font"
} }
var style: LabelModel.FontStyle? var style: Styler.Font?
var name: String? var name: String?
var size: CGFloat? var size: CGFloat?
@ -38,7 +38,7 @@ import UIKit
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
style = try typeContainer.decodeIfPresent(LabelModel.FontStyle.self, forKey: .style) style = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .style)
name = try typeContainer.decodeIfPresent(String.self, forKey: .name) name = try typeContainer.decodeIfPresent(String.self, forKey: .name)
size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size) size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size)
try super.init(from: decoder) try super.init(from: decoder)

View File

@ -10,31 +10,6 @@
import Foundation import Foundation
@objcMembers public class LabelModel: MoleculeModelProtocol { @objcMembers public class LabelModel: MoleculeModelProtocol {
public enum FontStyle: String, Codable {
case Title2XLarge
case TitleXLarge
case BoldTitleLarge
case RegularTitleLarge
case BoldTitleMedium
case RegularTitleMedium
case BoldBodyLarge
case RegularBodyLarge
case BoldBodySmall
case RegularBodySmall
case BoldMicro
case RegularMicro
// Legacy
case H1
case H2
case H3
case H32
case B1
case B2
case B3
case B20
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
@ -44,7 +19,7 @@ import Foundation
public var text: String public var text: String
public var accessibilityText: String? public var accessibilityText: String?
public var textColor: Color? public var textColor: Color?
public var fontStyle: FontStyle? public var fontStyle: Styler.Font?
public var fontName: String? public var fontName: String?
public var fontSize: CGFloat? public var fontSize: CGFloat?
public var textAlignment: NSTextAlignment? public var textAlignment: NSTextAlignment?
@ -95,7 +70,7 @@ import Foundation
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
fontStyle = try typeContainer.decodeIfPresent(FontStyle.self, forKey: .fontStyle) fontStyle = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .fontStyle)
fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName) fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName)
fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize) fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize)
textAlignment = try typeContainer.decodeIfPresent(NSTextAlignment.self, forKey: .textAlignment) textAlignment = try typeContainer.decodeIfPresent(NSTextAlignment.self, forKey: .textAlignment)

View File

@ -14,7 +14,7 @@ open class Styler {
// MARK: - Enums // MARK: - Enums
//-------------------------------------------------- //--------------------------------------------------
public enum Font: String { public enum Font: String, Codable {
case Title2XLarge case Title2XLarge
case TitleXLarge case TitleXLarge
case BoldTitleLarge case BoldTitleLarge
@ -28,31 +28,56 @@ open class Styler {
case BoldMicro case BoldMicro
case RegularMicro case RegularMicro
// Legacy Fonts
case H1
case H2
case H3
case H32
case B1
case B2
case B3
case B20
public func pointSize() -> CGFloat { public func pointSize() -> CGFloat {
switch self { switch self {
case .H1:
return 40
case .Title2XLarge: case .Title2XLarge:
return 36 return 36
case .TitleXLarge: case .TitleXLarge,
.H32:
return 32 return 32
case .H2:
return 25
case .BoldTitleLarge, case .BoldTitleLarge,
.RegularTitleLarge: .RegularTitleLarge:
return 24 return 24
case .BoldTitleMedium, case .BoldTitleMedium,
.RegularTitleMedium: .RegularTitleMedium,
.B20:
return 20 return 20
case .H3:
return 18
case .BoldBodyLarge, case .BoldBodyLarge,
.RegularBodyLarge: .RegularBodyLarge:
return 16 return 16
case .BoldBodySmall, case .BoldBodySmall,
.RegularBodySmall: .RegularBodySmall,
.B1,
.B2:
return 13 return 13
case .BoldMicro, .RegularMicro: case .BoldMicro,
.RegularMicro,
.B3:
return 11 return 11
} }
} }
@ -66,14 +91,51 @@ open class Styler {
.RegularTitleMedium, .RegularTitleMedium,
.RegularBodyLarge, .RegularBodyLarge,
.RegularBodySmall, .RegularBodySmall,
.RegularMicro: .RegularMicro,
.B2,
.B3,
.B20:
return false return false
case .BoldTitleLarge, case .BoldTitleLarge,
.BoldTitleMedium,
.BoldBodyLarge,
.BoldBodySmall,
.BoldMicro,
.H1,
.H2,
.H3,
.H32,
.B1:
return true
}
}
public func isLegacyFont() -> Bool {
switch self {
case .Title2XLarge,
.TitleXLarge,
.RegularTitleLarge,
.RegularTitleMedium,
.RegularBodyLarge,
.RegularBodySmall,
.RegularMicro,
.BoldTitleLarge,
.BoldTitleMedium, .BoldTitleMedium,
.BoldBodyLarge, .BoldBodyLarge,
.BoldBodySmall, .BoldBodySmall,
.BoldMicro: .BoldMicro:
return false
case .H1,
.H2,
.H3,
.H32,
.B1,
.B2,
.B3,
.B20:
return true return true
} }
} }
@ -81,7 +143,23 @@ open class Styler {
public func getFont(_ genericScaling: Bool = true) -> UIFont? { public func getFont(_ genericScaling: Bool = true) -> UIFont? {
let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize() let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize()
return getMVA3FontSize(size, isBold: isBold())
if isLegacyFont() {
switch self {
case .B2, .B3, .B20:
return MFFonts.mfFont55Rg(size)
default:
return MFFonts.mfFont75Bd(size)
}
} else {
if isBold() {
return size >= 15 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size)
} else {
return size >= 15 ? MFFonts.mfFontDSRegular(size) : MFFonts.mfFontTXRegular(size)
}
}
} }
public func styleLabel(_ label: UILabel, genericScaling: Bool = true) { public func styleLabel(_ label: UILabel, genericScaling: Bool = true) {
@ -90,7 +168,7 @@ open class Styler {
label.textColor = .black label.textColor = .black
} }
} }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Functions // MARK: - Functions
//-------------------------------------------------- //--------------------------------------------------
@ -129,14 +207,4 @@ open class Styler {
MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: top, trailing: horizontalPadding, bottom: bottom) MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: top, trailing: horizontalPadding, bottom: bottom)
} }
} }
open class func getMVA3FontSize(_ size: CGFloat, isBold: Bool) -> UIFont {
if isBold {
return size >= 15 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size)
} else {
return size >= 15 ? MFFonts.mfFontDSRegular(size) : MFFonts.mfFontTXRegular(size)
}
}
} }