Setting label alignment changes per title lock up alignment

This commit is contained in:
Sumanth Nadigadda 2022-04-26 02:24:41 +05:30
parent 4980874914
commit 8ca99f5802
2 changed files with 21 additions and 20 deletions

View File

@ -11,10 +11,15 @@
// MARK: - Outlets
//--------------------------------------------------
public let stack = Stack<StackModel>(frame: .zero)
public let eyebrow = Label(fontStyle: .RegularBodySmall)
public let headline = Label(fontStyle: .RegularBodySmall)
public let body = Label(fontStyle: .RegularBodySmall)
public lazy var stack: Stack<StackModel> = {
return Stack<StackModel>.createStack(with: [(view: eyebrow, model: StackItemModel(horizontalAlignment: .fill)),
(view: headline, model: StackItemModel(horizontalAlignment: .fill)),
(view: body, model: StackItemModel(horizontalAlignment: .fill))],
axis: .vertical)
}()
var castModel: EyebrowHeadlineBodyModel? {
get { return model as? EyebrowHeadlineBodyModel }
@ -24,9 +29,8 @@
// MARK: - Initialization
//--------------------------------------------------
public convenience init(spacing: CGFloat) {
public convenience init() {
self.init(frame: .zero)
stack.stackModel?.spacing = spacing
stack.restack()
}
@ -36,8 +40,6 @@
open override func setupView() {
super.setupView()
stack.setAndCreateModel(with: [eyebrow, headline, body])
stack.stackModel?.spacing = 0
addSubview(stack)
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
stack.restack()
@ -56,9 +58,6 @@
open override func reset() {
super.reset()
stack.reset()
eyebrow.setFontStyle(.RegularBodySmall)
headline.setFontStyle(.RegularBodySmall)
body.setFontStyle(.RegularBodySmall)
}
//--------------------------------------------------
@ -67,22 +66,24 @@
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData)
setStyle(style: castModel?.style)
guard let model = model as? EyebrowHeadlineBodyModel else { return }
setStyle(style: model.style)
///Updating the text color
castModel?.eyebrow?.textColor = castModel?.headlineColor
castModel?.headline.textColor = castModel?.headlineColor
castModel?.body?.textColor = castModel?.bodyColor
model.eyebrow?.textColor = model.headlineColor
model.headline.textColor = model.headlineColor
model.body?.textColor = model.bodyColor
if let alignment = castModel?.alignment, let textAlignment = NSTextAlignment(rawValue: alignment.rawValue) {
castModel?.eyebrow?.textAlignment = textAlignment
castModel?.headline.textAlignment = textAlignment
castModel?.body?.textAlignment = textAlignment
if let textAlignment = NSTextAlignment(rawValue: model.alignment.rawValue) {
model.eyebrow?.textAlignment = textAlignment
model.headline.textAlignment = textAlignment
model.body?.textAlignment = textAlignment
}
stack.updateContainedMolecules(with: [castModel?.eyebrow,
castModel?.headline,
castModel?.body],
stack.updateContainedMolecules(with: [model.eyebrow,
model.headline,
model.body],
delegateObject, additionalData)
}

View File

@ -100,7 +100,7 @@ public class EyebrowHeadlineBodyModel: MoleculeModelProtocol, ParentMoleculeMode
switch self {
case .small,.medium,.large:
return Padding.One
return Padding.Two
case .xlarge:
return Padding.Three
case .xxlarge: