Merge branch 'feature/modern_styler' into 'develop'

Modern styler

See merge request BPHV_MIPS/mvm_core_ui!349
This commit is contained in:
Pfeil, Scott Robert 2020-04-09 10:46:19 -04:00
commit 2357d9c475
5 changed files with 288 additions and 29 deletions

View File

@ -87,6 +87,8 @@
0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */; };
0A6682A22434DB4F00AD3CA1 /* ListLeftVariableRadioButtonBodyText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A12434DB4F00AD3CA1 /* ListLeftVariableRadioButtonBodyText.swift */; };
0A6682A42434DB8D00AD3CA1 /* ListLeftVariableRadioButtonBodyTextModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A32434DB8D00AD3CA1 /* ListLeftVariableRadioButtonBodyTextModel.swift */; };
0A6682AA2435125F00AD3CA1 /* Styler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A92435125F00AD3CA1 /* Styler.swift */; };
0A6682AC243531C300AD3CA1 /* Padding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682AB243531C300AD3CA1 /* Padding.swift */; };
0A69F611241BDEA700F7231B /* RuleAnyRequiredModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */; };
0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */; };
0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; };
@ -491,6 +493,8 @@
0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGuidelinesProtocol.swift; sourceTree = "<group>"; };
0A6682A12434DB4F00AD3CA1 /* ListLeftVariableRadioButtonBodyText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableRadioButtonBodyText.swift; sourceTree = "<group>"; };
0A6682A32434DB8D00AD3CA1 /* ListLeftVariableRadioButtonBodyTextModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableRadioButtonBodyTextModel.swift; sourceTree = "<group>"; };
0A6682A92435125F00AD3CA1 /* Styler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Styler.swift; sourceTree = "<group>"; };
0A6682AB243531C300AD3CA1 /* Padding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Padding.swift; sourceTree = "<group>"; };
0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyRequiredModel.swift; sourceTree = "<group>"; };
0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDropdownEntryField.swift; sourceTree = "<group>"; };
0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = "<group>"; };
@ -1537,6 +1541,8 @@
children = (
D29DF13821E68636003B2FB9 /* MFStyler.h */,
D29DF13921E68637003B2FB9 /* MFStyler.m */,
0A6682A92435125F00AD3CA1 /* Styler.swift */,
0A6682AB243531C300AD3CA1 /* Padding.swift */,
);
path = Styles;
sourceTree = "<group>";
@ -2131,6 +2137,7 @@
8DD1E370243B3D0500D8F2DF /* ListThreeColumnInternationalData.swift in Sources */,
D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */,
01EB368F23609801006832FA /* LabelModel.swift in Sources */,
0A6682AC243531C300AD3CA1 /* Padding.swift in Sources */,
AA1EC59924373994003D6F50 /* ListThreeColumnSpeedTestDivider.swift in Sources */,
942C378E2412F5B60066E45E /* ModalMoleculeStackTemplate.swift in Sources */,
8D4687E4242E2DF300802879 /* ListFourColumnDataUsageListItem.swift in Sources */,
@ -2302,6 +2309,7 @@
011D95AD2406BB57000E3791 /* FormHolderProtocol.swift in Sources */,
01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */,
D260106523D0CEA700764D80 /* StackModel.swift in Sources */,
0A6682AA2435125F00AD3CA1 /* Styler.swift in Sources */,
D29770F521F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,48 @@
//
// Padding.swift
// MVMCoreUI
//
// Created by Kevin Christiano on 4/1/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
/// Padding is a multiple based on the number 4.
public struct Padding {
public static let OneHalf: CGFloat = 2
public static let One: CGFloat = 4
public static let Two: CGFloat = 8
public static let Three: CGFloat = 12
public static let Four: CGFloat = 16
public static let Five: CGFloat = 24
public static let Eight: CGFloat = 32
public static let Ten: CGFloat = 40
public static let Twelve: CGFloat = 48
public static let Eighteen: CGFloat = 72
public struct Component {
public static let Standard: CGFloat = 24
public static let HorizontalMarginSpacing: CGFloat = 32
public static let LargeVerticalMarginSpacing: CGFloat = 32
public static let VerticalMarginSpacing: CGFloat = 24
public static var horizontalPaddingForApplicationWidth: CGFloat {
return MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalMarginSpacing
}
public static var verticalPaddingForApplicationWidth: CGFloat {
return MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? VerticalMarginSpacing
}
public static func horizontalPaddingForSize(_ size: CGFloat) -> CGFloat {
return MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBased(onSize: size) ?? HorizontalMarginSpacing
}
public static func verticalPaddingForSize(_ size: CGFloat) -> CGFloat {
return MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBased(onSize: size) ?? VerticalMarginSpacing
}
}
}

View File

@ -0,0 +1,228 @@
//
// Styler.swift
// MVMCoreUI
//
// Created by Kevin Christiano on 4/1/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
import Foundation
open class Styler {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
public enum Font: 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 Fonts
case H1
case H2
case H3
case H32
case B1
case B2
case B3
case B20
/// Returns the font size of the current enum case.
public func pointSize() -> CGFloat {
switch self {
case .H1:
return 40
case .Title2XLarge:
return 36
case .TitleXLarge,
.H32:
return 32
case .H2:
return 25
case .BoldTitleLarge,
.RegularTitleLarge:
return 24
case .BoldTitleMedium,
.RegularTitleMedium,
.B20:
return 20
case .H3:
return 18
case .BoldBodyLarge,
.RegularBodyLarge:
return 16
case .BoldBodySmall,
.RegularBodySmall,
.B1,
.B2:
return 13
case .BoldMicro,
.RegularMicro,
.B3:
return 11
}
}
/// Determines if the selected font case is bold or regular.
public func isBold() -> Bool {
switch self {
case .Title2XLarge,
.TitleXLarge,
.RegularTitleLarge,
.RegularTitleMedium,
.RegularBodyLarge,
.RegularBodySmall,
.RegularMicro,
.B2,
.B3,
.B20:
return false
case .BoldTitleLarge,
.BoldTitleMedium,
.BoldBodyLarge,
.BoldBodySmall,
.BoldMicro,
.H1,
.H2,
.H3,
.H32,
.B1:
return true
}
}
/// Determines if the current enum is a legacy or modern font.
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
}
}
/// Returns the font based on the declared enum case.
public func getFont(_ genericScaling: Bool = true) -> UIFont? {
let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize()
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)
}
}
}
/// Styles the provided label to the declared enum Font case.
public func styleLabel(_ label: UILabel, textColor: UIColor = .mvmBlack, genericScaling: Bool = true) {
label.font = getFont(genericScaling)
label.textColor = textColor
}
}
//--------------------------------------------------
// MARK: - Functions
//--------------------------------------------------
open class func sizeObjectGeneric(forCurrentDevice size: CGFloat) -> MFSizeObject? {
let sizeObject = MFSizeObject(standardSize: size, standardiPadPortraitSize: size * 1.3)
sizeObject?.addLargerThanCustomSize(size * 1.4, forThreshold: MFSizeStandardiPadLandscapeThreshold)
sizeObject?.addLargerThanCustomSize(size * 1.5, forThreshold: MFSizeiPadProLandscapeThreshold)
return sizeObject
}
open class func sizeFontGeneric(forCurrentDevice size: CGFloat) -> CGFloat {
return sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? size
}
//--------------------------------------------------
// MARK: - Spacing
//--------------------------------------------------
open class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat?, horizontal: Bool = true, vertical: Bool = false) {
var horizontalPadding: CGFloat = Padding.Component.HorizontalMarginSpacing
let verticalPadding: CGFloat = vertical ? Padding.Component.VerticalMarginSpacing : 0
if let size = size {
horizontalPadding = horizontal ? Padding.Component.horizontalPaddingForSize(size) : 0
}
DispatchQueue.main.async {
MVMCoreUIUtility.setMarginsFor(view,
leading: horizontalPadding,
top: verticalPadding,
trailing: horizontalPadding,
bottom: verticalPadding)
}
}
open class func setMarginsFor(_ view: UIView?, size: CGFloat, horizontal: CGFloat?, top: CGFloat, bottom: CGFloat) {
let horizontalPadding: CGFloat = horizontal ?? Padding.Component.horizontalPaddingForSize(size)
DispatchQueue.main.async {
MVMCoreUIUtility.setMarginsFor(view,
leading: horizontalPadding,
top: top,
trailing: horizontalPadding,
bottom: bottom)
}
}
}