refactored in numberPublisher
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
b8ab69adbd
commit
10e6c4dd21
@ -30,41 +30,88 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
//------------------------------------
|
//------------------------------------
|
||||||
//testing only remove later
|
//testing only remove later
|
||||||
//------------------------------------
|
//------------------------------------
|
||||||
var pointSizeRange = Slider()
|
var pointSizeRange = Slider().with {
|
||||||
|
$0.maximumValue = 500
|
||||||
|
$0.minimumValue = 0
|
||||||
|
$0.value = 0
|
||||||
|
}
|
||||||
var lineheightRange = Slider()
|
var lineheightRange = Slider()
|
||||||
var lineSpacingRange = Slider()
|
var lineSpacingRange = Slider()
|
||||||
var topInsetRange = Slider()
|
var topInsetRange = Slider().with {
|
||||||
var bottomInsetRange = Slider()
|
$0.maximumValue = 100
|
||||||
|
$0.minimumValue = -100
|
||||||
|
$0.value = 0
|
||||||
|
}
|
||||||
|
var bottomInsetRange = Slider().with {
|
||||||
|
$0.maximumValue = 100
|
||||||
|
$0.minimumValue = -100
|
||||||
|
$0.value = 0
|
||||||
|
}
|
||||||
//------------------------------------
|
//------------------------------------
|
||||||
|
var baseStyle: TextStyle!
|
||||||
|
var currentStyle: TextStyle! {
|
||||||
|
didSet {
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
#warning("testing only remove later")
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
let lineheight = component.useScaledFont ? currentStyle.scaledLineHeight : currentStyle.lineHeight
|
||||||
|
let lineheightText = component.useScaledFont ? "\(baseStyle.lineHeight.rounded())\nscaled: \(currentStyle.scaledLineHeight)" : "\(baseStyle.lineHeight.rounded())"
|
||||||
|
|
||||||
var currentStyle: TextStyle!
|
pointSizeRange.value = Float(currentStyle.pointSize)
|
||||||
|
lineheightRange.value = Float(lineheight)
|
||||||
|
lineheightRange.maximumValue = Float(lineheightRange.value * 1.50)
|
||||||
|
lineheightRange.minimumValue = 1
|
||||||
|
|
||||||
|
topInsetRange.value = Float(currentStyle.edgeInsets.top)
|
||||||
|
bottomInsetRange.value = Float(currentStyle.edgeInsets.bottom)
|
||||||
|
defaultLineHeightLabel?.text = "Line Height - iOS:\(Int(currentFont.lineHeight.rounded())) VDS:\(lineheightText)"
|
||||||
|
let text = component.useScaledFont ? "iOS: \(Int(currentFont.pointSize.rounded()))" : ""
|
||||||
|
defaultPointLabel?.text = "Font Size - \(text) VDS:\(currentStyle.pointSize.rounded())"
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var useScaledFont = Toggle()
|
||||||
var boldSwitch = Toggle()
|
var boldSwitch = Toggle()
|
||||||
var disabledSwitch = Toggle()
|
var disabledSwitch = Toggle()
|
||||||
var textField = TextField()
|
var textField = TextField()
|
||||||
private var isBold: Bool = false
|
private var isBold: Bool = false
|
||||||
var lineHeightLabel = UILabel().with { $0.translatesAutoresizingMaskIntoConstraints = false; $0.lineBreakMode = .byWordWrapping; $0.numberOfLines = 0}
|
|
||||||
|
override func setup() {
|
||||||
|
super.setup()
|
||||||
|
|
||||||
|
NotificationCenter
|
||||||
|
.Publisher(center: .default, name: UIContentSizeCategory.didChangeNotification)
|
||||||
|
.sink { [weak self] notification in
|
||||||
|
self?.checkForScaledFonts()
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
let stack = UIStackView()
|
|
||||||
stack.axis = .vertical
|
|
||||||
stack.spacing = 10
|
|
||||||
stack.addArrangedSubview(component)
|
|
||||||
stack.addArrangedSubview(lineHeightLabel)
|
|
||||||
|
|
||||||
addContentTopView(view: component)
|
addContentTopView(view: component)
|
||||||
|
|
||||||
setupPicker()
|
setupPicker()
|
||||||
setupModel()
|
setupModel()
|
||||||
}
|
}
|
||||||
var defaultLineHeightLabel: UILabel?
|
var defaultLineHeightLabel: Label?
|
||||||
var defaultPointLabel: UILabel?
|
var defaultPointLabel: Label?
|
||||||
var calculatedLabel = UILabel()
|
var calculatedLabel = UILabel()
|
||||||
|
var scaledFontRow: UIView?
|
||||||
|
|
||||||
|
func checkForScaledFonts() {
|
||||||
|
scaledFontRow?.isHidden = !TextStyle.canScaleFonts
|
||||||
|
updateLabelStyle()
|
||||||
|
}
|
||||||
|
|
||||||
override func setupForm(){
|
override func setupForm(){
|
||||||
super.setupForm()
|
super.setupForm()
|
||||||
addFormRow(label: "Disabled", view: disabledSwitch)
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||||
addFormRow(label: "Bold", view: boldSwitch)
|
addFormRow(label: "Bold", view: boldSwitch)
|
||||||
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
|
|
||||||
|
//Scaled Fonts implementation
|
||||||
|
scaledFontRow = addFormRow(label: "Use Scaled Font", view: useScaledFont)
|
||||||
|
checkForScaledFonts()
|
||||||
|
|
||||||
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
|
addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
|
||||||
addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView)
|
addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView)
|
||||||
addFormRow(label: "Text Size", view: textSizePickerSelectorView)
|
addFormRow(label: "Text Size", view: textSizePickerSelectorView)
|
||||||
@ -80,12 +127,18 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
self?.isBold = sender.isOn
|
self?.isBold = sender.isOn
|
||||||
self?.updateLabelStyle()
|
self?.updateLabelStyle()
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
useScaledFont
|
||||||
|
.publisher(for: .valueChanged)
|
||||||
|
.sink { [weak self] sender in
|
||||||
|
self?.component.useScaledFont = sender.isOn
|
||||||
|
self?.updateLabelStyle()
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
textField
|
textField
|
||||||
.textPublisher
|
.textPublisher
|
||||||
.sink { [weak self] text in
|
.sink { [weak self] text in
|
||||||
self?.component.text = text
|
self?.component.text = text
|
||||||
self?.lineHeightLabel.text = text
|
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
@ -98,41 +151,34 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
let view = testingSection.addFormRow(label: "Line Height", view: lineheightRange)
|
let view = testingSection.addFormRow(label: "Line Height", view: lineheightRange)
|
||||||
testingSection.addFormRow(label: "Top Inset", view: topInsetRange)
|
testingSection.addFormRow(label: "Top Inset", view: topInsetRange)
|
||||||
testingSection.addFormRow(label: "Bottom Inset", view: bottomInsetRange)
|
testingSection.addFormRow(label: "Bottom Inset", view: bottomInsetRange)
|
||||||
defaultLineHeightLabel = view.viewWithTag(1) as? UILabel
|
defaultLineHeightLabel = view.viewWithTag(1) as? Label
|
||||||
defaultPointLabel = pointView.viewWithTag(1) as? UILabel
|
defaultPointLabel = pointView.viewWithTag(1) as? Label
|
||||||
append(section: testingSection)
|
append(section: testingSection)
|
||||||
|
|
||||||
pointSizeRange.maximumValue = 20.0
|
|
||||||
pointSizeRange.minimumValue = 0.0
|
|
||||||
pointSizeRange.value = 0.0
|
|
||||||
pointSizeRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
pointSizeRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
let textStyle = self.component.textStyle
|
let textStyle = self.component.textStyle
|
||||||
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
||||||
fontFace: textStyle.fontFace,
|
fontFace: textStyle.fontFace,
|
||||||
pointSize: CGFloat(slider.value),
|
pointSize: slider.rounded,
|
||||||
lineHeight: textStyle.lineHeight,
|
lineHeight: textStyle.lineHeight,
|
||||||
letterSpacing: textStyle.letterSpacing,
|
letterSpacing: textStyle.letterSpacing,
|
||||||
edgeInsets: textStyle.edgeInsets)
|
edgeInsets: textStyle.edgeInsets)
|
||||||
|
self.currentStyle = self.component.textStyle
|
||||||
}).store(in: &subscribers)
|
}).store(in: &subscribers)
|
||||||
|
|
||||||
lineheightRange.maximumValue = 20.0
|
|
||||||
lineheightRange.minimumValue = 0.0
|
|
||||||
lineheightRange.value = 2.0
|
|
||||||
lineheightRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
lineheightRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
let textStyle = self.component.textStyle
|
let textStyle = self.component.textStyle
|
||||||
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
self.component.textStyle = TextStyle(rawValue: textStyle.rawValue,
|
||||||
fontFace: textStyle.fontFace,
|
fontFace: textStyle.fontFace,
|
||||||
pointSize: textStyle.pointSize,
|
pointSize: textStyle.pointSize,
|
||||||
lineHeight: CGFloat(slider.value),
|
lineHeight: slider.rounded,
|
||||||
letterSpacing: textStyle.letterSpacing,
|
letterSpacing: textStyle.letterSpacing,
|
||||||
edgeInsets: textStyle.edgeInsets)
|
edgeInsets: textStyle.edgeInsets)
|
||||||
|
self.currentStyle = self.component.textStyle
|
||||||
}).store(in: &subscribers)
|
}).store(in: &subscribers)
|
||||||
|
|
||||||
topInsetRange.maximumValue = 20.0
|
|
||||||
topInsetRange.minimumValue = -20
|
|
||||||
topInsetRange.value = 0
|
|
||||||
topInsetRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
topInsetRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
let textStyle = self.component.textStyle
|
let textStyle = self.component.textStyle
|
||||||
@ -141,12 +187,10 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
pointSize: textStyle.pointSize,
|
pointSize: textStyle.pointSize,
|
||||||
lineHeight: textStyle.lineHeight,
|
lineHeight: textStyle.lineHeight,
|
||||||
letterSpacing: textStyle.letterSpacing,
|
letterSpacing: textStyle.letterSpacing,
|
||||||
edgeInsets: .init(top: CGFloat(slider.value), left: 0, bottom: CGFloat(bottomInsetRange.value), right: 0))
|
edgeInsets: .init(top: slider.rounded, left: 0, bottom: CGFloat(bottomInsetRange.value), right: 0))
|
||||||
|
self.currentStyle = self.component.textStyle
|
||||||
}).store(in: &subscribers)
|
}).store(in: &subscribers)
|
||||||
|
|
||||||
bottomInsetRange.maximumValue = 20.0
|
|
||||||
bottomInsetRange.minimumValue = -20
|
|
||||||
bottomInsetRange.value = 0
|
|
||||||
bottomInsetRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
bottomInsetRange.publisher(for: .valueChanged).sink(receiveValue: { [weak self] slider in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
let textStyle = self.component.textStyle
|
let textStyle = self.component.textStyle
|
||||||
@ -155,7 +199,8 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
pointSize: textStyle.pointSize,
|
pointSize: textStyle.pointSize,
|
||||||
lineHeight: textStyle.lineHeight,
|
lineHeight: textStyle.lineHeight,
|
||||||
letterSpacing: textStyle.letterSpacing,
|
letterSpacing: textStyle.letterSpacing,
|
||||||
edgeInsets: .init(top: CGFloat(topInsetRange.value), left: 0, bottom: CGFloat(slider.value), right: 0))
|
edgeInsets: .init(top: CGFloat(topInsetRange.value), left: 0, bottom: slider.rounded, right: 0))
|
||||||
|
self.currentStyle = self.component.textStyle
|
||||||
}).store(in: &subscribers)
|
}).store(in: &subscribers)
|
||||||
|
|
||||||
component.publisher(for: \.bounds)
|
component.publisher(for: \.bounds)
|
||||||
@ -169,8 +214,6 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
func setupModel() {
|
func setupModel() {
|
||||||
component.text = "Helg¹ worldg Hell¹ worldg"
|
component.text = "Helg¹ worldg Hell¹ worldg"
|
||||||
component.textStyle = .featureXLarge
|
component.textStyle = .featureXLarge
|
||||||
lineHeightLabel.text = component.text
|
|
||||||
lineHeightLabel.font = component.textStyle.font
|
|
||||||
|
|
||||||
//setup UI
|
//setup UI
|
||||||
surfacePickerSelectorView.text = component.surface.rawValue
|
surfacePickerSelectorView.text = component.surface.rawValue
|
||||||
@ -190,9 +233,6 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
override func showDebug(show: Bool) {
|
override func showDebug(show: Bool) {
|
||||||
component.layer.borderColor = UIColor.blue.cgColor
|
component.layer.borderColor = UIColor.blue.cgColor
|
||||||
component.layer.borderWidth = show ? 1 : 0
|
component.layer.borderWidth = show ? 1 : 0
|
||||||
|
|
||||||
lineHeightLabel.layer.borderColor = UIColor.blue.cgColor
|
|
||||||
lineHeightLabel.layer.borderWidth = show ? 1 : 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Picker
|
//Picker
|
||||||
@ -216,27 +256,15 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentFont: UIFont {
|
||||||
|
component.useScaledFont ? currentStyle.font.scaledFont : currentStyle.font
|
||||||
|
}
|
||||||
|
|
||||||
func updateLabelStyle(){
|
func updateLabelStyle(){
|
||||||
if let style = fontCategory.style(for: textSize, isBold: isBold) {
|
if let style = fontCategory.style(for: textSize, isBold: isBold) {
|
||||||
component.textStyle = style
|
component.textStyle = style
|
||||||
|
baseStyle = style
|
||||||
currentStyle = style
|
currentStyle = style
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
#warning("testing only remove later")
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
let defaultLineHeight = style.font.lineHeight
|
|
||||||
lineHeightLabel.font = style.font
|
|
||||||
lineheightRange.maximumValue = Float(defaultLineHeight) * 1.50
|
|
||||||
lineheightRange.minimumValue = Float(defaultLineHeight) * 0.50
|
|
||||||
lineheightRange.value = Float(style.lineHeight)
|
|
||||||
pointSizeRange.value = Float(style.pointSize)
|
|
||||||
pointSizeRange.maximumValue = Float(style.pointSize) * 1.50
|
|
||||||
pointSizeRange.minimumValue = Float(style.pointSize) * 0.50
|
|
||||||
topInsetRange.value = Float(style.edgeInsets.top)
|
|
||||||
bottomInsetRange.value = Float(style.edgeInsets.bottom)
|
|
||||||
defaultLineHeightLabel?.text = "Line Height - d:\(defaultLineHeight) s:\(style.lineHeight)"
|
|
||||||
defaultPointLabel?.text = "Font Size - s:\(style.pointSize)"
|
|
||||||
//--------------------------------------------------------------
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,4 +289,9 @@ class LabelViewController: BaseViewController<Label> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Slider {
|
||||||
|
var rounded: CGFloat {
|
||||||
|
CGFloat((value * 100).rounded() / 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user