45 lines
1.5 KiB
Swift
45 lines
1.5 KiB
Swift
//
|
|
// Typography+Spacing.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 7/21/23.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
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 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
|
|
}
|
|
}
|
|
}
|