including 2.0 legacy as it's being used in some molecular at the moment.
This commit is contained in:
parent
8788d98323
commit
c9bb3ce1f3
@ -18,7 +18,7 @@ import UIKit
|
||||
return "font"
|
||||
}
|
||||
|
||||
var style: LabelModel.FontStyle?
|
||||
var style: Styler.Font?
|
||||
var name: String?
|
||||
var size: CGFloat?
|
||||
|
||||
@ -38,7 +38,7 @@ import UIKit
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
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)
|
||||
size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size)
|
||||
try super.init(from: decoder)
|
||||
|
||||
@ -10,31 +10,6 @@
|
||||
import Foundation
|
||||
|
||||
@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
|
||||
//--------------------------------------------------
|
||||
@ -44,7 +19,7 @@ import Foundation
|
||||
public var text: String
|
||||
public var accessibilityText: String?
|
||||
public var textColor: Color?
|
||||
public var fontStyle: FontStyle?
|
||||
public var fontStyle: Styler.Font?
|
||||
public var fontName: String?
|
||||
public var fontSize: CGFloat?
|
||||
public var textAlignment: NSTextAlignment?
|
||||
@ -95,7 +70,7 @@ import Foundation
|
||||
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
|
||||
textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor)
|
||||
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)
|
||||
fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize)
|
||||
textAlignment = try typeContainer.decodeIfPresent(NSTextAlignment.self, forKey: .textAlignment)
|
||||
|
||||
@ -14,7 +14,7 @@ open class Styler {
|
||||
// MARK: - Enums
|
||||
//--------------------------------------------------
|
||||
|
||||
public enum Font: String {
|
||||
public enum Font: String, Codable {
|
||||
case Title2XLarge
|
||||
case TitleXLarge
|
||||
case BoldTitleLarge
|
||||
@ -28,31 +28,56 @@ open class Styler {
|
||||
case BoldMicro
|
||||
case RegularMicro
|
||||
|
||||
// Legacy Fonts
|
||||
case H1
|
||||
case H2
|
||||
case H3
|
||||
case H32
|
||||
case B1
|
||||
case B2
|
||||
case B3
|
||||
case B20
|
||||
|
||||
public func pointSize() -> CGFloat {
|
||||
switch self {
|
||||
case .H1:
|
||||
return 40
|
||||
|
||||
case .Title2XLarge:
|
||||
return 36
|
||||
|
||||
case .TitleXLarge:
|
||||
case .TitleXLarge,
|
||||
.H32:
|
||||
return 32
|
||||
|
||||
case .H2:
|
||||
return 25
|
||||
|
||||
case .BoldTitleLarge,
|
||||
.RegularTitleLarge:
|
||||
return 24
|
||||
|
||||
case .BoldTitleMedium,
|
||||
.RegularTitleMedium:
|
||||
.RegularTitleMedium,
|
||||
.B20:
|
||||
return 20
|
||||
|
||||
case .H3:
|
||||
return 18
|
||||
|
||||
case .BoldBodyLarge,
|
||||
.RegularBodyLarge:
|
||||
return 16
|
||||
|
||||
case .BoldBodySmall,
|
||||
.RegularBodySmall:
|
||||
.RegularBodySmall,
|
||||
.B1,
|
||||
.B2:
|
||||
return 13
|
||||
|
||||
case .BoldMicro, .RegularMicro:
|
||||
case .BoldMicro,
|
||||
.RegularMicro,
|
||||
.B3:
|
||||
return 11
|
||||
}
|
||||
}
|
||||
@ -66,14 +91,51 @@ open class Styler {
|
||||
.RegularTitleMedium,
|
||||
.RegularBodyLarge,
|
||||
.RegularBodySmall,
|
||||
.RegularMicro:
|
||||
.RegularMicro,
|
||||
.B2,
|
||||
.B3,
|
||||
.B20:
|
||||
return false
|
||||
|
||||
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,
|
||||
.BoldBodyLarge,
|
||||
.BoldBodySmall,
|
||||
.BoldMicro:
|
||||
return false
|
||||
|
||||
case .H1,
|
||||
.H2,
|
||||
.H3,
|
||||
.H32,
|
||||
.B1,
|
||||
.B2,
|
||||
.B3,
|
||||
.B20:
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -81,7 +143,23 @@ open class Styler {
|
||||
public func getFont(_ genericScaling: Bool = true) -> UIFont? {
|
||||
|
||||
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) {
|
||||
@ -90,7 +168,7 @@ open class Styler {
|
||||
label.textColor = .black
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Functions
|
||||
//--------------------------------------------------
|
||||
@ -129,14 +207,4 @@ open class Styler {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user