Digital ACT-191 ONEAPP-9311 story: aligning text to center
This commit is contained in:
parent
4e88ee936a
commit
90eb01cb24
@ -44,7 +44,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
/// auto(default) - The control's width is determined by the combined width of the value, trailing text and padding
|
/// auto(default) - The control's width is determined by the combined width of the value, trailing text and padding
|
||||||
/// Value - The control's width can be set to a fixed pixel.
|
/// Value - The control's width can be set to a fixed pixel.
|
||||||
open var controlWidth: String? = "auto" { didSet { setNeedsUpdate() } }
|
open var controlWidth: String? = "auto" { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// Accepts percentage value to controlWidth of input stepper.
|
/// Accepts percentage value to controlWidth of input stepper.
|
||||||
open var controlWidthPercentage: CGFloat? {
|
open var controlWidthPercentage: CGFloat? {
|
||||||
didSet {
|
didSet {
|
||||||
@ -72,7 +72,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
|
|
||||||
/// Allows an id to be passed to input stepper.
|
/// Allows an id to be passed to input stepper.
|
||||||
open var id: Int? { didSet { setNeedsUpdate() } }
|
open var id: Int? { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// Maximum value of the input stepper, defaults to '99'.
|
/// Maximum value of the input stepper, defaults to '99'.
|
||||||
open var maxValue: Int? = 99 {
|
open var maxValue: Int? = 99 {
|
||||||
didSet {
|
didSet {
|
||||||
@ -82,7 +82,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Minimum value of the input stepper, defaults to '0'.
|
/// Minimum value of the input stepper, defaults to '0'.
|
||||||
open var minValue: Int? = 0 {
|
open var minValue: Int? = 0 {
|
||||||
didSet {
|
didSet {
|
||||||
@ -94,7 +94,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The size of the input stepper. Defaults to 'large'.
|
/// The size of the input stepper. Defaults to 'large'.
|
||||||
open var size: Size = .large {
|
open var size: Size = .large {
|
||||||
didSet {
|
didSet {
|
||||||
updateStepperContainerViewSize()
|
updateStepperContainerViewSize()
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
@ -143,24 +143,25 @@ open class InputStepper: EntryFieldBase {
|
|||||||
$0.textStyle = .boldBodyLarge
|
$0.textStyle = .boldBodyLarge
|
||||||
$0.numberOfLines = 1
|
$0.numberOfLines = 1
|
||||||
$0.lineBreakMode = .byTruncatingTail
|
$0.lineBreakMode = .byTruncatingTail
|
||||||
|
$0.textAlignment = .center
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal var stepperWidthConstraint: NSLayoutConstraint?
|
internal var stepperWidthConstraint: NSLayoutConstraint?
|
||||||
internal var stepperHeightConstraint: NSLayoutConstraint?
|
internal var stepperHeightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration Properties
|
// MARK: - Configuration Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal override var containerSize: CGSize { CGSize(width: size == .large ? largeMinWidth : smallMinWidth, height: size == .large ? largeMinHeight : smallMinHeight) }
|
internal override var containerSize: CGSize { CGSize(width: size == .large ? largeMinWidth : smallMinWidth, height: size == .large ? largeMinHeight : smallMinHeight) }
|
||||||
|
|
||||||
internal var largeMinWidth = 121
|
internal var largeMinWidth = 121
|
||||||
internal var smallMinWidth = 90
|
internal var smallMinWidth = 90
|
||||||
internal var largeMinHeight = 44
|
internal var largeMinHeight = 44
|
||||||
internal var smallMinHeight = 32
|
internal var smallMinHeight = 32
|
||||||
|
|
||||||
internal let labelColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
|
internal let labelColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
|
||||||
internal let labelDisabledColorConfiguration = SurfaceColorConfiguration(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark)
|
internal let labelDisabledColorConfiguration = SurfaceColorConfiguration(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark)
|
||||||
|
|
||||||
@ -182,11 +183,11 @@ open class InputStepper: EntryFieldBase {
|
|||||||
// Set initial states
|
// Set initial states
|
||||||
containerView.isEnabled = false
|
containerView.isEnabled = false
|
||||||
statusIcon.isHidden = true
|
statusIcon.isHidden = true
|
||||||
|
|
||||||
// Add listeners
|
// Add listeners
|
||||||
decrementButton.onClick = { _ in self.decrementButtonClick() }
|
decrementButton.onClick = { _ in self.decrementButtonClick() }
|
||||||
incrementButton.onClick = { _ in self.incrementButtonClick() }
|
incrementButton.onClick = { _ in self.incrementButtonClick() }
|
||||||
|
|
||||||
// setting color config
|
// setting color config
|
||||||
textLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable()
|
textLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable()
|
||||||
}
|
}
|
||||||
@ -195,12 +196,12 @@ open class InputStepper: EntryFieldBase {
|
|||||||
stepperStackView.addArrangedSubview(decrementButton)
|
stepperStackView.addArrangedSubview(decrementButton)
|
||||||
stepperStackView.addArrangedSubview(textLabel)
|
stepperStackView.addArrangedSubview(textLabel)
|
||||||
stepperStackView.addArrangedSubview(incrementButton)
|
stepperStackView.addArrangedSubview(incrementButton)
|
||||||
|
|
||||||
// Set space between decrement button, label, and increment button relative to input Stepper size.
|
// Set space between decrement button, label, and increment button relative to input Stepper size.
|
||||||
let space = size == .large ? VDSLayout.space3X : VDSLayout.space2X
|
let space = size == .large ? VDSLayout.space3X : VDSLayout.space2X
|
||||||
stepperStackView.setCustomSpacing(space, after: decrementButton)
|
stepperStackView.setCustomSpacing(space, after: decrementButton)
|
||||||
stepperStackView.setCustomSpacing(space, after: textLabel)
|
stepperStackView.setCustomSpacing(space, after: textLabel)
|
||||||
|
|
||||||
// Update Edge insets relative to input Stepper size.
|
// Update Edge insets relative to input Stepper size.
|
||||||
stepperStackView.pinToSuperView(.uniform(size == .large ? 6.0 : VDSLayout.space1X))
|
stepperStackView.pinToSuperView(.uniform(size == .large ? 6.0 : VDSLayout.space1X))
|
||||||
|
|
||||||
@ -221,20 +222,19 @@ open class InputStepper: EntryFieldBase {
|
|||||||
statusIcon.isHidden = true
|
statusIcon.isHidden = true
|
||||||
updateConstraintsToFieldStackView(flag: false)
|
updateConstraintsToFieldStackView(flag: false)
|
||||||
updateContainerView(flag: false)
|
updateContainerView(flag: false)
|
||||||
|
|
||||||
// Update label text, style, color, ande surface.
|
// Update label text, style, color, ande surface.
|
||||||
textLabel.text = String(defaultValue) + " " + (trailingText ?? "")
|
textLabel.text = String(defaultValue) + " " + (trailingText ?? "")
|
||||||
textLabel.textStyle = size == .large ? .boldBodyLarge : .boldBodySmall
|
textLabel.textStyle = size == .large ? .boldBodyLarge : .boldBodySmall
|
||||||
textLabel.textColorConfiguration = !isEnabled ? labelDisabledColorConfiguration.eraseToAnyColorable() : labelColorConfiguration.eraseToAnyColorable()
|
textLabel.textColorConfiguration = !isEnabled ? labelDisabledColorConfiguration.eraseToAnyColorable() : labelColorConfiguration.eraseToAnyColorable()
|
||||||
textLabel.surface = surface
|
textLabel.surface = surface
|
||||||
|
|
||||||
// Update increment and decrement button.
|
// Update increment and decrement button.
|
||||||
updateButtonStates()
|
updateButtonStates()
|
||||||
|
|
||||||
// Update stepper container border and corner radius.
|
// Update stepper container border and corner radius.
|
||||||
setControlWidth(controlWidth)
|
setControlWidth(controlWidth)
|
||||||
updateControlWidthPercentage()
|
updateControlWidthPercentage()
|
||||||
|
|
||||||
setNeedsLayout()
|
setNeedsLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
widthConstraint?.deactivate()
|
widthConstraint?.deactivate()
|
||||||
trailingLessThanEqualsConstraint?.deactivate()
|
trailingLessThanEqualsConstraint?.deactivate()
|
||||||
trailingEqualsConstraint?.deactivate()
|
trailingEqualsConstraint?.deactivate()
|
||||||
|
|
||||||
if let width, width >= minWidth, width <= maxWidth {
|
if let width, width >= minWidth, width <= maxWidth {
|
||||||
widthConstraint?.constant = width
|
widthConstraint?.constant = width
|
||||||
widthConstraint?.activate()
|
widthConstraint?.activate()
|
||||||
@ -286,7 +286,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
internal func checkDefaultValue() {
|
internal func checkDefaultValue() {
|
||||||
if let _minValue = minValue, let _maxValue = maxValue {
|
if let _minValue = minValue, let _maxValue = maxValue {
|
||||||
defaultValue = defaultValue > _maxValue ? _maxValue : defaultValue < _minValue ? _minValue : defaultValue
|
defaultValue = defaultValue > _maxValue ? _maxValue : defaultValue < _minValue ? _minValue : defaultValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,7 +308,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
incrementButton.customContainerSize = size == .large ? 32 : 24
|
incrementButton.customContainerSize = size == .large ? 32 : 24
|
||||||
decrementButton.surface = surface
|
decrementButton.surface = surface
|
||||||
incrementButton.surface = surface
|
incrementButton.surface = surface
|
||||||
|
|
||||||
if isReadOnly || !isEnabled {
|
if isReadOnly || !isEnabled {
|
||||||
decrementButton.isEnabled = false
|
decrementButton.isEnabled = false
|
||||||
incrementButton.isEnabled = false
|
incrementButton.isEnabled = false
|
||||||
@ -341,7 +341,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
// Set controlWidth provided which is either pixel or percentage
|
// Set controlWidth provided which is either pixel or percentage
|
||||||
let width = width ?? CGFloat(containerView.frame.size.width)
|
let width = width ?? CGFloat(containerView.frame.size.width)
|
||||||
updateStepperContainerWidth(controlWidth: CGFloat(controlWidth), width: width)
|
updateStepperContainerWidth(controlWidth: CGFloat(controlWidth), width: width)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handling the controlwidth without going beyond the width of the parent container.
|
// Handling the controlwidth without going beyond the width of the parent container.
|
||||||
@ -359,7 +359,7 @@ open class InputStepper: EntryFieldBase {
|
|||||||
|
|
||||||
private func updateControlWidthPercentage() {
|
private func updateControlWidthPercentage() {
|
||||||
let superWidth = width ?? CGFloat(containerView.frame.size.width)
|
let superWidth = width ?? CGFloat(containerView.frame.size.width)
|
||||||
|
|
||||||
// Set the inputStepper's controlWidth based on the controlWidth percentage received relative to its parentView's frame.
|
// Set the inputStepper's controlWidth based on the controlWidth percentage received relative to its parentView's frame.
|
||||||
if let controlWidthPercentage {
|
if let controlWidthPercentage {
|
||||||
controlWidth = String( Int( max(superWidth * ((controlWidthPercentage) / 100), minWidth)))
|
controlWidth = String( Int( max(superWidth * ((controlWidthPercentage) / 100), minWidth)))
|
||||||
@ -379,6 +379,5 @@ open class InputStepper: EntryFieldBase {
|
|||||||
updateControlWidthPercentage()
|
updateControlWidthPercentage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user