refactored out Typography and converted to TextStyle
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
443636b723
commit
9526a7ec40
@ -57,7 +57,7 @@
|
||||
EA985BEC2968A91200F2FF2E /* TitleLockupTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */; };
|
||||
EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */; };
|
||||
EA985BF02968A93600F2FF2E /* TitleLockupEyebrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */; };
|
||||
EA985BF22968B5BB00F2FF2E /* TitleLockupTypography.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */; };
|
||||
EA985BF22968B5BB00F2FF2E /* TitleLockupTextStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF12968B5BB00F2FF2E /* TitleLockupTextStyle.swift */; };
|
||||
EA985BF5296C60C000F2FF2E /* Icon.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF4296C60C000F2FF2E /* Icon.swift */; };
|
||||
EA985BF7296C665E00F2FF2E /* IconName.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF6296C665E00F2FF2E /* IconName.swift */; };
|
||||
EA985BF9296C710100F2FF2E /* IconColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA985BF8296C710100F2FF2E /* IconColor.swift */; };
|
||||
@ -98,7 +98,7 @@
|
||||
EAF7F0A2289AFB3900B287F5 /* Errorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A1289AFB3900B287F5 /* Errorable.swift */; };
|
||||
EAF7F0A4289B017C00B287F5 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */; };
|
||||
EAF7F0A6289B0CE000B287F5 /* Resetable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0A5289B0CE000B287F5 /* Resetable.swift */; };
|
||||
EAF7F0AB289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AA289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift */; };
|
||||
EAF7F0AB289B13FD00B287F5 /* TextStyleLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AA289B13FD00B287F5 /* TextStyleLabelAttribute.swift */; };
|
||||
EAF7F0AD289B142900B287F5 /* StrikeThroughLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */; };
|
||||
EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0AE289B144C00B287F5 /* UnderlineLabelAttribute.swift */; };
|
||||
EAF7F0B1289B177F00B287F5 /* ColorLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */; };
|
||||
@ -172,7 +172,7 @@
|
||||
EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTitleModel.swift; sourceTree = "<group>"; };
|
||||
EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupSubTitleModel.swift; sourceTree = "<group>"; };
|
||||
EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupEyebrowModel.swift; sourceTree = "<group>"; };
|
||||
EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTypography.swift; sourceTree = "<group>"; };
|
||||
EA985BF12968B5BB00F2FF2E /* TitleLockupTextStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupTextStyle.swift; sourceTree = "<group>"; };
|
||||
EA985BF4296C60C000F2FF2E /* Icon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Icon.swift; sourceTree = "<group>"; };
|
||||
EA985BF6296C665E00F2FF2E /* IconName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconName.swift; sourceTree = "<group>"; };
|
||||
EA985BF8296C710100F2FF2E /* IconColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconColor.swift; sourceTree = "<group>"; };
|
||||
@ -213,7 +213,7 @@
|
||||
EAF7F0A1289AFB3900B287F5 /* Errorable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errorable.swift; sourceTree = "<group>"; };
|
||||
EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = "<group>"; };
|
||||
EAF7F0A5289B0CE000B287F5 /* Resetable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Resetable.swift; sourceTree = "<group>"; };
|
||||
EAF7F0AA289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypographicalStyleLabelAttribute.swift; sourceTree = "<group>"; };
|
||||
EAF7F0AA289B13FD00B287F5 /* TextStyleLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyleLabelAttribute.swift; sourceTree = "<group>"; };
|
||||
EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StrikeThroughLabelAttribute.swift; sourceTree = "<group>"; };
|
||||
EAF7F0AE289B144C00B287F5 /* UnderlineLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnderlineLabelAttribute.swift; sourceTree = "<group>"; };
|
||||
EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorLabelAttribute.swift; sourceTree = "<group>"; };
|
||||
@ -493,7 +493,7 @@
|
||||
EA985BEF2968A93600F2FF2E /* TitleLockupEyebrowModel.swift */,
|
||||
EA985BED2968A92400F2FF2E /* TitleLockupSubTitleModel.swift */,
|
||||
EA985BEB2968A91200F2FF2E /* TitleLockupTitleModel.swift */,
|
||||
EA985BF12968B5BB00F2FF2E /* TitleLockupTypography.swift */,
|
||||
EA985BF12968B5BB00F2FF2E /* TitleLockupTextStyle.swift */,
|
||||
);
|
||||
path = TitleLockup;
|
||||
sourceTree = "<group>";
|
||||
@ -617,7 +617,7 @@
|
||||
EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */,
|
||||
EAF7F13228A2A16500B287F5 /* AttachmentLabelAttributeModel.swift */,
|
||||
EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */,
|
||||
EAF7F0AA289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift */,
|
||||
EAF7F0AA289B13FD00B287F5 /* TextStyleLabelAttribute.swift */,
|
||||
EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */,
|
||||
EAF7F0AC289B142900B287F5 /* StrikeThroughLabelAttribute.swift */,
|
||||
EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */,
|
||||
@ -776,7 +776,7 @@
|
||||
EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */,
|
||||
EAF7F11728A1475A00B287F5 /* RadioButton.swift in Sources */,
|
||||
EA985BEE2968A92400F2FF2E /* TitleLockupSubTitleModel.swift in Sources */,
|
||||
EA985BF22968B5BB00F2FF2E /* TitleLockupTypography.swift in Sources */,
|
||||
EA985BF22968B5BB00F2FF2E /* TitleLockupTextStyle.swift in Sources */,
|
||||
EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */,
|
||||
EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */,
|
||||
EAF7F0952899861000B287F5 /* Checkbox.swift in Sources */,
|
||||
@ -809,7 +809,7 @@
|
||||
EA1F266528B945070033E859 /* RadioSwatch.swift in Sources */,
|
||||
EA4DB18528CA967F00103EE3 /* SelectorGroupHandlerBase.swift in Sources */,
|
||||
EA89200228AECF2A006B9984 /* UIButton+Publisher.swift in Sources */,
|
||||
EAF7F0AB289B13FD00B287F5 /* TypographicalStyleLabelAttribute.swift in Sources */,
|
||||
EAF7F0AB289B13FD00B287F5 /* TextStyleLabelAttribute.swift in Sources */,
|
||||
EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */,
|
||||
EA985BE629688F6A00F2FF2E /* TiletBadgeModel.swift in Sources */,
|
||||
EA336171288B19200071C351 /* VDS.docc in Sources */,
|
||||
|
||||
@ -42,8 +42,8 @@ open class Button: ButtonBase, Useable {
|
||||
textColorConfiguration.getColor(self)
|
||||
}
|
||||
|
||||
open override var textStyle: TypographicalStyle {
|
||||
size == .large ? TypographicalStyle.BoldBodyLarge : TypographicalStyle.BoldBodySmall
|
||||
open override var textStyle: TextStyle {
|
||||
size == .large ? TextStyle.BoldBodyLarge : TextStyle.BoldBodySmall
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -66,7 +66,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
|
||||
}
|
||||
}
|
||||
|
||||
open var textStyle: TypographicalStyle { .defaultStyle }
|
||||
open var textStyle: TextStyle { .defaultStyle }
|
||||
|
||||
open var textColor: UIColor { .black }
|
||||
|
||||
|
||||
@ -26,8 +26,8 @@ open class TextLink: ButtonBase {
|
||||
|
||||
open override var availableSizes: [ButtonSize] { [.large, .small] }
|
||||
|
||||
open override var textStyle: TypographicalStyle {
|
||||
size == .large ? TypographicalStyle.BodyLarge : TypographicalStyle.BodySmall
|
||||
open override var textStyle: TextStyle {
|
||||
size == .large ? TextStyle.BodyLarge : TextStyle.BodySmall
|
||||
}
|
||||
|
||||
open override var textColor: UIColor {
|
||||
|
||||
@ -24,8 +24,8 @@ open class TextLinkCaret: ButtonBase {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
open override var textStyle: TypographicalStyle {
|
||||
TypographicalStyle.BoldBodyLarge
|
||||
open override var textStyle: TextStyle {
|
||||
TextStyle.BoldBodyLarge
|
||||
}
|
||||
|
||||
private var caretView = CaretView().with {
|
||||
|
||||
@ -40,10 +40,10 @@ public extension NSAttributedString {
|
||||
static func createAttributeModelFor(key: NSAttributedString.Key, range: NSRange, value: Any) -> (any LabelAttributeModel)? {
|
||||
guard let value = value as? AnyHashable else { return nil }
|
||||
|
||||
guard let font = value as? UIFont, let style = TypographicalStyle.style(for: font.fontName, size: font.pointSize), key == .font
|
||||
guard let font = value as? UIFont, let style = TextStyle.style(for: font.fontName, size: font.pointSize), key == .font
|
||||
else {
|
||||
return AnyAttribute(location: range.location, length: range.length, key: key, value: value)
|
||||
}
|
||||
return TypographicalStyleLabelAttribute(location: range.location, length: range.length, style: style)
|
||||
return TextStyleLabelAttribute(location: range.location, length: range.length, textStyle: style)
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,16 +8,16 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public struct TypographicalStyleLabelAttribute: LabelAttributeModel {
|
||||
public struct TextStyleLabelAttribute: LabelAttributeModel {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Equatable
|
||||
//--------------------------------------------------
|
||||
public func isEqual(_ equatable: TypographicalStyleLabelAttribute) -> Bool {
|
||||
public func isEqual(_ equatable: TextStyleLabelAttribute) -> Bool {
|
||||
return id == equatable.id
|
||||
&& range == equatable.range
|
||||
&& color == equatable.color
|
||||
&& style == equatable.style
|
||||
&& textColor == equatable.textColor
|
||||
&& textStyle == equatable.textStyle
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -26,19 +26,19 @@ public struct TypographicalStyleLabelAttribute: LabelAttributeModel {
|
||||
public var id = UUID()
|
||||
public var location: Int
|
||||
public var length: Int
|
||||
public var style: TypographicalStyle
|
||||
public var color: UIColor
|
||||
public var textStyle: TextStyle
|
||||
public var textColor: UIColor
|
||||
public var textPosition: TextPosition
|
||||
public var lineBreakMode: NSLineBreakMode
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
public init(location: Int, length: Int, style: TypographicalStyle, color: UIColor = .black, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) {
|
||||
public init(location: Int, length: Int, textStyle: TextStyle, textColor: UIColor = .black, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) {
|
||||
self.location = location
|
||||
self.length = length
|
||||
self.style = style
|
||||
self.color = color
|
||||
self.textStyle = textStyle
|
||||
self.textColor = textColor
|
||||
self.textPosition = textPosition
|
||||
self.lineBreakMode = lineBreakMode
|
||||
}
|
||||
@ -46,23 +46,23 @@ public struct TypographicalStyleLabelAttribute: LabelAttributeModel {
|
||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||
attributedString.removeAttribute(.font, range: range)
|
||||
attributedString.removeAttribute(.foregroundColor, range: range)
|
||||
attributedString.addAttribute(.font, value: style.font, range: range)
|
||||
attributedString.addAttribute(.foregroundColor, value: color, range: range)
|
||||
attributedString.addAttribute(.font, value: textStyle.font, range: range)
|
||||
attributedString.addAttribute(.foregroundColor, value: textColor, range: range)
|
||||
setStyleAttributes(attributedString)
|
||||
}
|
||||
|
||||
private func setStyleAttributes(_ attributedString: NSMutableAttributedString) {
|
||||
//set letterSpacing
|
||||
if style.letterSpacing > 0.0 {
|
||||
if textStyle.letterSpacing > 0.0 {
|
||||
attributedString.removeAttribute(.kern, range: range)
|
||||
attributedString.addAttribute(.kern, value: style.letterSpacing, range: range)
|
||||
attributedString.addAttribute(.kern, value: textStyle.letterSpacing, range: range)
|
||||
}
|
||||
|
||||
//set lineHeight
|
||||
if style.lineHeight > 0.0 {
|
||||
let lineHeight = style.lineHeight
|
||||
let adjustment = lineHeight > style.font.lineHeight ? 2.0 : 1.0
|
||||
let baselineOffset = (lineHeight - style.font.lineHeight) / 2.0 / adjustment
|
||||
if textStyle.lineHeight > 0.0 {
|
||||
let lineHeight = textStyle.lineHeight
|
||||
let adjustment = lineHeight > textStyle.font.lineHeight ? 2.0 : 1.0
|
||||
let baselineOffset = (lineHeight - textStyle.font.lineHeight) / 2.0 / adjustment
|
||||
let paragraph = NSMutableParagraphStyle().with {
|
||||
$0.maximumLineHeight = lineHeight
|
||||
$0.minimumLineHeight = lineHeight
|
||||
@ -33,7 +33,7 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable {
|
||||
|
||||
open var attributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
||||
|
||||
open var textStyle: TypographicalStyle = .defaultStyle { didSet { didChange() }}
|
||||
open var textStyle: TextStyle = .defaultStyle { didSet { didChange() }}
|
||||
|
||||
open var textPosition: TextPosition = .left { didSet { didChange() }}
|
||||
|
||||
|
||||
@ -100,7 +100,7 @@ public class InputField: EntryField, UITextFieldDelegate {
|
||||
|
||||
private var textField = UITextField().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.font = TypographicalStyle.BodyLarge.font
|
||||
$0.font = TextStyle.BodyLarge.font
|
||||
}
|
||||
|
||||
public var textFieldTextColorConfiguration: AnyColorable = ViewColorConfiguration().with {
|
||||
|
||||
@ -48,7 +48,7 @@ public class TextArea: EntryField {
|
||||
|
||||
private var textView = UITextView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
$0.font = TypographicalStyle.BodyLarge.font
|
||||
$0.font = TextStyle.BodyLarge.font
|
||||
$0.sizeToFit()
|
||||
$0.isScrollEnabled = false
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ open class Tilet: TileContainer {
|
||||
|
||||
private var titleLockup = TitleLockup().with {
|
||||
let configs = [
|
||||
TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall],
|
||||
TextStyle.DeviceSpacingConfig([.TitleSmall, .BoldTitleSmall],
|
||||
neighboring: [
|
||||
.BodySmall, .BoldBodySmall,
|
||||
.BodyMedium, .BoldBodyMedium
|
||||
@ -61,7 +61,7 @@ open class Tilet: TileContainer {
|
||||
spacing: 8.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.TitleMedium, .BoldTitleMedium,
|
||||
TextStyle.DeviceSpacingConfig([.TitleMedium, .BoldTitleMedium,
|
||||
.TitleLarge, .BoldTitleLarge],
|
||||
neighboring: [
|
||||
.BodySmall, .BoldBodySmall,
|
||||
@ -70,7 +70,7 @@ open class Tilet: TileContainer {
|
||||
spacing: 8.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge],
|
||||
TextStyle.DeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge],
|
||||
neighboring: [
|
||||
.BodySmall, .BoldBodySmall,
|
||||
.BodyMedium, .BoldBodyMedium,
|
||||
@ -80,7 +80,7 @@ open class Tilet: TileContainer {
|
||||
spacing: 12.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.TitleSmall, .BoldTitleSmall,
|
||||
TextStyle.DeviceSpacingConfig([.TitleSmall, .BoldTitleSmall,
|
||||
.TitleMedium, .BoldTitleMedium],
|
||||
neighboring: [
|
||||
.BodySmall, .BoldBodySmall,
|
||||
@ -90,7 +90,7 @@ open class Tilet: TileContainer {
|
||||
spacing: 8.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.TitleLarge, .BoldTitleLarge],
|
||||
TextStyle.DeviceSpacingConfig([.TitleLarge, .BoldTitleLarge],
|
||||
neighboring: [
|
||||
.BodySmall, .BoldBodySmall,
|
||||
.BodyMedium, .BoldBodyMedium,
|
||||
@ -100,7 +100,7 @@ open class Tilet: TileContainer {
|
||||
spacing: 12.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge],
|
||||
TextStyle.DeviceSpacingConfig([.TitleXLarge, .BoldTitleXLarge],
|
||||
neighboring: [
|
||||
.BodyLarge, .BoldBodyLarge,
|
||||
.TitleMedium, .BoldTitleMedium
|
||||
@ -110,7 +110,7 @@ open class Tilet: TileContainer {
|
||||
|
||||
]
|
||||
|
||||
$0.bottomTypographicalStyleSpacingConfig = TypographicalStyleSpacingConfig(configs: configs)
|
||||
$0.bottomTextStyleSpacingConfig = TextStyle.SpacingConfig(configs: configs)
|
||||
}
|
||||
|
||||
private var badgeContainerView = UIView().with {
|
||||
@ -300,7 +300,7 @@ open class Tilet: TileContainer {
|
||||
|
||||
if showTitleLockup {
|
||||
//flip the surface for the titleLockup
|
||||
titleLockup.surface = color == .black ? .dark : .light
|
||||
titleLockup.surface = color == .black ? Surface.dark : Surface.light
|
||||
|
||||
//titleLockup
|
||||
if let textWidth {
|
||||
|
||||
@ -50,124 +50,124 @@ open class TitleLockup: View {
|
||||
// MARK: - Configuration Properties
|
||||
//--------------------------------------------------
|
||||
// Sizes are from InVision design specs.
|
||||
open var topTypographicalStyleSpacingConfig: TypographicalStyleSpacingConfig = {
|
||||
open var topTextStyleSpacingConfig: TextStyle.SpacingConfig = {
|
||||
let configs = [
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitleLarge, .TitleLarge],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitleLarge, .TitleLarge],
|
||||
neighboring: [.BodySmall, .BodyMedium, .BodyLarge],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
|
||||
neighboring: [.TitleMedium, .BodyLarge],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
neighboring: [.TitleMedium, .TitleLarge],
|
||||
spacing: 16.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
neighboring: [.BodyLarge],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
|
||||
neighboring: [.TitleMedium, .TitleLarge],
|
||||
spacing: 16.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
|
||||
neighboring: [.BodyLarge],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
|
||||
neighboring: [.BodyLarge, .BodyMedium, .BodySmall, .TitleMedium],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
neighboring: [.BodyLarge, .BodyMedium, .TitleMedium],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall],
|
||||
neighboring: [.TitleLarge, .BodyLarge],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
|
||||
neighboring: [.TitleLarge, .TitleXLarge],
|
||||
spacing: 16.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
|
||||
neighboring: [.BodyLarge],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPhone)
|
||||
]
|
||||
return TypographicalStyleSpacingConfig(configs: configs)
|
||||
return TextStyle.SpacingConfig(configs: configs)
|
||||
}()
|
||||
|
||||
open var bottomTypographicalStyleSpacingConfig: TypographicalStyleSpacingConfig = {
|
||||
open var bottomTextStyleSpacingConfig: TextStyle.SpacingConfig = {
|
||||
let configs = [
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitleLarge, .TitleLarge],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitleLarge, .TitleLarge],
|
||||
neighboring: [.BodySmall, .BodyMedium, .BodyLarge],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
|
||||
neighboring: [.TitleMedium, .BodyLarge],
|
||||
spacing: 16.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
neighboring: [.TitleMedium, .TitleLarge],
|
||||
spacing: 24.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
neighboring: [.BodyLarge],
|
||||
spacing: 24.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
|
||||
neighboring: [.TitleMedium, .TitleLarge],
|
||||
spacing: 24.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall, .BoldFeatureMedium, .FeatureMedium],
|
||||
neighboring: [.BodyLarge],
|
||||
spacing: 24.0,
|
||||
deviceType: .iPad),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitleXLarge, .TitleXLarge],
|
||||
neighboring: [.BodyLarge, .BodyMedium, .BodySmall, .TitleMedium],
|
||||
spacing: 12.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
TextStyle.DeviceSpacingConfig([.BoldTitle2XLarge, .Title2XLarge, .BoldFeatureXSmall, .FeatureXSmall],
|
||||
neighboring: [.BodyLarge, .BodyMedium, .TitleMedium],
|
||||
spacing: 16,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureSmall, .FeatureSmall],
|
||||
neighboring: [.TitleLarge, .BodyLarge],
|
||||
spacing: 16.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
|
||||
neighboring: [.TitleLarge, .TitleXLarge],
|
||||
spacing: 24.0,
|
||||
deviceType: .iPhone),
|
||||
|
||||
TypographicalStyleDeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
|
||||
TextStyle.DeviceSpacingConfig([.BoldFeatureMedium, .FeatureMedium],
|
||||
neighboring: [.BodyLarge],
|
||||
spacing: 24.0,
|
||||
deviceType: .iPhone)
|
||||
]
|
||||
return TypographicalStyleSpacingConfig(configs: configs)
|
||||
return TextStyle.SpacingConfig(configs: configs)
|
||||
}()
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -281,14 +281,14 @@ open class TitleLockup: View {
|
||||
|
||||
//if both first 2 rows not empty set spacing
|
||||
if let eyebrowModel, let titleModel, !eyebrowModel.text.isEmpty, !titleModel.text.isEmpty {
|
||||
stackView.spacing = topTypographicalStyleSpacingConfig.spacing(for: titleModel.textStyle.value, neighboring: otherTextStyle.value)
|
||||
stackView.spacing = topTextStyleSpacingConfig.spacing(for: titleModel.textStyle.value, neighboring: otherTextStyle.value)
|
||||
} else {
|
||||
stackView.spacing = 0.0
|
||||
}
|
||||
|
||||
//if either first 2 rows not empty and subtile not empty, create space else collapse
|
||||
if let titleModel, (!eyebrowTextIsEmpty || !titleTextIsEmpty) && !subTitleTextIsEmpty {
|
||||
let bottomSpace = bottomTypographicalStyleSpacingConfig.spacing(for: titleModel.textStyle.value, neighboring: otherTextStyle.value)
|
||||
let bottomSpace = bottomTextStyleSpacingConfig.spacing(for: titleModel.textStyle.value, neighboring: otherTextStyle.value)
|
||||
stackView.setCustomSpacing(bottomSpace, after: titleLabel)
|
||||
} else if (!eyebrowTextIsEmpty || !titleTextIsEmpty) && subTitleTextIsEmpty {
|
||||
stackView.setCustomSpacing(0.0, after: titleLabel)
|
||||
@ -300,10 +300,3 @@ open class TitleLockup: View {
|
||||
subTitleLabel.isHidden = subTitleTextIsEmpty
|
||||
}
|
||||
}
|
||||
|
||||
extension TypographicalStyle {
|
||||
func isWithin(_ collection: [TypographicalStyle]) -> Bool {
|
||||
(collection.first(where: {$0 == self}) != nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// TitleLockupTypography.swift
|
||||
// TitleLockupTextStyle.swift
|
||||
// VDS
|
||||
//
|
||||
// Created by Matt Bruce on 1/6/23.
|
||||
@ -31,7 +31,7 @@ extension TitleLockup {
|
||||
case TitleSmall
|
||||
case BoldTitleSmall
|
||||
|
||||
public var defaultValue: TypographicalStyle {.BoldFeatureXSmall }
|
||||
public var defaultValue: TextStyle {.BoldFeatureXSmall }
|
||||
}
|
||||
|
||||
public enum OtherTextStyle: String, Codable, EnumSubset {
|
||||
@ -42,7 +42,7 @@ extension TitleLockup {
|
||||
case BodySmall
|
||||
case BoldBodySmall
|
||||
|
||||
public var defaultValue: TypographicalStyle {.BodyLarge }
|
||||
public var defaultValue: TextStyle {.BodyLarge }
|
||||
}
|
||||
|
||||
}
|
||||
@ -102,7 +102,7 @@ open class ToggleBase: Control, Accessable, DataTrackable {
|
||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .selected)
|
||||
}
|
||||
|
||||
private var textStyle: TypographicalStyle {
|
||||
private var textStyle: TextStyle {
|
||||
if textSize == .small {
|
||||
if textWeight == .bold {
|
||||
return .BoldBodySmall
|
||||
|
||||
@ -23,7 +23,7 @@ public enum TextPosition: String, Codable, CaseIterable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum TypographicalStyle: String, Codable, CaseIterable {
|
||||
public enum TextStyle: String, Codable, CaseIterable {
|
||||
|
||||
case FeatureXLarge
|
||||
case BoldFeatureXLarge
|
||||
@ -57,13 +57,13 @@ public enum TypographicalStyle: String, Codable, CaseIterable {
|
||||
case Micro
|
||||
case BoldMicro
|
||||
|
||||
public static var defaultStyle: TypographicalStyle {
|
||||
public static var defaultStyle: TextStyle {
|
||||
return .BodyLarge
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: FontCategory
|
||||
extension TypographicalStyle {
|
||||
extension TextStyle {
|
||||
public enum FontCategory: String, Codable, CaseIterable {
|
||||
case feature = "Feature"
|
||||
case title = "Title"
|
||||
@ -83,9 +83,9 @@ extension TypographicalStyle {
|
||||
}
|
||||
}
|
||||
|
||||
public func style(for fontSize: FontSize?, isBold: Bool = false) -> TypographicalStyle? {
|
||||
public func style(for fontSize: FontSize?, isBold: Bool = false) -> TextStyle? {
|
||||
let styleName = "\(isBold ? "Bold" : "")\(self.rawValue)\(fontSize?.rawValue ?? "")"
|
||||
guard let style = TypographicalStyle(rawValue: styleName) else {
|
||||
guard let style = TextStyle(rawValue: styleName) else {
|
||||
return nil
|
||||
}
|
||||
return style
|
||||
@ -94,7 +94,7 @@ extension TypographicalStyle {
|
||||
}
|
||||
|
||||
//MARK: FontSize
|
||||
extension TypographicalStyle {
|
||||
extension TextStyle {
|
||||
public enum FontSize: String, Codable, CaseIterable {
|
||||
case xxlarge = "2XLarge"
|
||||
case xlarge = "XLarge"
|
||||
@ -106,7 +106,7 @@ extension TypographicalStyle {
|
||||
}
|
||||
|
||||
//MARK: PointSize
|
||||
extension TypographicalStyle {
|
||||
extension TextStyle {
|
||||
public var pointSize: CGFloat {
|
||||
switch self {
|
||||
case .FeatureXLarge, .BoldFeatureXLarge:
|
||||
@ -142,7 +142,7 @@ extension TypographicalStyle {
|
||||
}
|
||||
|
||||
//MARK: LineHeight
|
||||
extension TypographicalStyle {
|
||||
extension TextStyle {
|
||||
public var lineHeight: CGFloat {
|
||||
switch self {
|
||||
case .FeatureXLarge, .BoldFeatureXLarge:
|
||||
@ -178,7 +178,7 @@ extension TypographicalStyle {
|
||||
}
|
||||
|
||||
//MARK: LetterSpacing
|
||||
extension TypographicalStyle {
|
||||
extension TextStyle {
|
||||
public var letterSpacing: CGFloat {
|
||||
switch self {
|
||||
case .FeatureXLarge,
|
||||
@ -202,14 +202,14 @@ extension TypographicalStyle {
|
||||
}
|
||||
|
||||
//MARK: Alignments
|
||||
extension TypographicalStyle {
|
||||
extension TextStyle {
|
||||
public var aligments: [TextPosition] {
|
||||
return [.left, .center]
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: Fonts
|
||||
extension TypographicalStyle {
|
||||
extension TextStyle {
|
||||
public var fontFace: Fonts {
|
||||
switch self {
|
||||
case .BoldFeatureXLarge,
|
||||
@ -261,8 +261,8 @@ extension TypographicalStyle {
|
||||
}
|
||||
}
|
||||
|
||||
extension TypographicalStyle {
|
||||
public static func style(for fontName: String, size: CGFloat) -> TypographicalStyle? {
|
||||
extension TextStyle {
|
||||
public static func style(for fontName: String, size: CGFloat) -> TextStyle? {
|
||||
//filter all styles by fontName
|
||||
let styles = allCases.filter{$0.fontFace.fontName == fontName }.sorted { lhs, rhs in lhs.pointSize < rhs.pointSize }
|
||||
|
||||
@ -282,35 +282,44 @@ extension TypographicalStyle {
|
||||
}
|
||||
}
|
||||
|
||||
public struct TypographicalStyleSpacingConfig {
|
||||
public var defaultSpacing: CGFloat = 8.0
|
||||
public var configs: [TypographicalStyleDeviceSpacingConfig]
|
||||
|
||||
public func spacing(for style: TypographicalStyle, neighboring: TypographicalStyle) -> CGFloat {
|
||||
let deviceType: TypographicalStyleDeviceSpacingConfig.DeviceType = UIDevice.isIPad ? .iPad : .iPhone
|
||||
if let config = configs.first(where:
|
||||
{ style.isWithin($0.primaryStyles) && neighboring.isWithin($0.neighboringStyles) &&
|
||||
($0.deviceType == deviceType || $0.deviceType == .all )})
|
||||
{
|
||||
return config.spacing
|
||||
}
|
||||
return defaultSpacing
|
||||
extension TextStyle {
|
||||
public func isWithin(_ collection: [TextStyle]) -> Bool {
|
||||
(collection.first(where: {$0 == self}) != nil)
|
||||
}
|
||||
}
|
||||
|
||||
public struct TypographicalStyleDeviceSpacingConfig {
|
||||
public enum DeviceType {
|
||||
case iPhone, iPad, all
|
||||
extension TextStyle {
|
||||
public struct SpacingConfig {
|
||||
public var defaultSpacing: CGFloat = 8.0
|
||||
public var configs: [TextStyle.DeviceSpacingConfig]
|
||||
|
||||
public func spacing(for style: TextStyle, neighboring: TextStyle) -> CGFloat {
|
||||
let deviceType: TextStyle.DeviceSpacingConfig.DeviceType = UIDevice.isIPad ? .iPad : .iPhone
|
||||
if let config = configs.first(where:
|
||||
{ style.isWithin($0.primaryStyles) && neighboring.isWithin($0.neighboringStyles) &&
|
||||
($0.deviceType == deviceType || $0.deviceType == .all )})
|
||||
{
|
||||
return config.spacing
|
||||
}
|
||||
return defaultSpacing
|
||||
}
|
||||
}
|
||||
public var spacing: CGFloat
|
||||
public var deviceType: DeviceType = .iPhone
|
||||
public var primaryStyles: [TypographicalStyle]
|
||||
public var neighboringStyles: [TypographicalStyle]
|
||||
|
||||
public init(_ primaryStyles: [TypographicalStyle], neighboring: [TypographicalStyle], spacing: CGFloat, deviceType: DeviceType = .iPhone) {
|
||||
self.spacing = spacing
|
||||
self.primaryStyles = primaryStyles
|
||||
self.neighboringStyles = neighboring
|
||||
self.deviceType = deviceType
|
||||
public struct DeviceSpacingConfig {
|
||||
public enum DeviceType {
|
||||
case iPhone, iPad, all
|
||||
}
|
||||
public var spacing: CGFloat
|
||||
public var deviceType: DeviceType = .iPhone
|
||||
public var primaryStyles: [TextStyle]
|
||||
public var neighboringStyles: [TextStyle]
|
||||
|
||||
public init(_ primaryStyles: [TextStyle], neighboring: [TextStyle], spacing: CGFloat, deviceType: DeviceType = .iPhone) {
|
||||
self.spacing = spacing
|
||||
self.primaryStyles = primaryStyles
|
||||
self.neighboringStyles = neighboring
|
||||
self.deviceType = deviceType
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user